2017-11-02 18:56:01 +01:00
|
|
|
<?php declare(strict_types=1);
|
2011-11-26 16:09:39 +01:00
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser;
|
|
|
|
|
2017-04-27 18:14:07 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
2017-01-19 22:23:19 +01:00
|
|
|
require_once __DIR__ . '/CodeTestParser.php';
|
|
|
|
|
2017-04-27 18:14:07 +02:00
|
|
|
abstract class CodeTestAbstract extends TestCase
|
2011-11-26 16:09:39 +01:00
|
|
|
{
|
2016-12-23 14:11:31 +01:00
|
|
|
protected function getTests($directory, $fileExtension, $chunksPerTest = 2) {
|
2017-01-19 22:23:19 +01:00
|
|
|
$parser = new CodeTestParser;
|
2017-08-13 14:35:03 +02:00
|
|
|
$allTests = [];
|
2017-01-19 22:23:19 +01:00
|
|
|
foreach (filesInDir($directory, $fileExtension) as $fileName => $fileContents) {
|
|
|
|
list($name, $tests) = $parser->parseTest($fileContents, $chunksPerTest);
|
2011-11-27 21:43:27 +01:00
|
|
|
|
|
|
|
// first part is the name
|
2017-01-19 22:23:19 +01:00
|
|
|
$name .= ' (' . $fileName . ')';
|
2016-04-20 15:03:18 +02:00
|
|
|
$shortName = ltrim(str_replace($directory, '', $fileName), '/\\');
|
2011-11-27 21:43:27 +01:00
|
|
|
|
|
|
|
// multiple sections possible with always two forming a pair
|
2017-01-19 22:23:19 +01:00
|
|
|
foreach ($tests as $i => list($mode, $parts)) {
|
|
|
|
$dataSetName = $shortName . (count($parts) > 1 ? '#' . $i : '');
|
|
|
|
$allTests[$dataSetName] = array_merge([$name], $parts, [$mode]);
|
2011-11-27 21:43:27 +01:00
|
|
|
}
|
2011-11-26 16:09:39 +01:00
|
|
|
}
|
|
|
|
|
2017-01-19 22:23:19 +01:00
|
|
|
return $allTests;
|
2015-06-13 15:10:46 +02:00
|
|
|
}
|
2015-03-12 13:17:31 +01:00
|
|
|
}
|