CodeTestAbstract.php 960 B

1234567891011121314151617181920212223242526
  1. <?php declare(strict_types=1);
  2. namespace PhpParser;
  3. abstract class CodeTestAbstract extends \PHPUnit\Framework\TestCase
  4. {
  5. protected function getTests($directory, $fileExtension, $chunksPerTest = 2) {
  6. $parser = new CodeTestParser;
  7. $allTests = [];
  8. foreach (filesInDir($directory, $fileExtension) as $fileName => $fileContents) {
  9. list($name, $tests) = $parser->parseTest($fileContents, $chunksPerTest);
  10. // first part is the name
  11. $name .= ' (' . $fileName . ')';
  12. $shortName = ltrim(str_replace($directory, '', $fileName), '/\\');
  13. // multiple sections possible with always two forming a pair
  14. foreach ($tests as $i => list($mode, $parts)) {
  15. $dataSetName = $shortName . (count($parts) > 1 ? '#' . $i : '');
  16. $allTests[$dataSetName] = array_merge([$name], $parts, [$mode]);
  17. }
  18. }
  19. return $allTests;
  20. }
  21. }