1<?php declare(strict_types=1); 2 3namespace PhpParser; 4 5abstract class CodeTestAbstract extends \PHPUnit\Framework\TestCase { 6 protected static function getTests($directory, $fileExtension, $chunksPerTest = 2) { 7 $parser = new CodeTestParser(); 8 $allTests = []; 9 foreach (filesInDir($directory, $fileExtension) as $fileName => $fileContents) { 10 list($name, $tests) = $parser->parseTest($fileContents, $chunksPerTest); 11 12 // first part is the name 13 $name .= ' (' . $fileName . ')'; 14 $shortName = ltrim(str_replace($directory, '', $fileName), '/\\'); 15 16 // multiple sections possible with always two forming a pair 17 foreach ($tests as $i => list($mode, $parts)) { 18 $dataSetName = $shortName . (count($parts) > 1 ? '#' . $i : ''); 19 $allTests[$dataSetName] = array_merge([$name], $parts, [$mode]); 20 } 21 } 22 23 return $allTests; 24 } 25 26 public function parseModeLine(?string $modeLine): array { 27 if ($modeLine === null) { 28 return []; 29 } 30 31 $modes = []; 32 foreach (explode(',', $modeLine) as $mode) { 33 $kv = explode('=', $mode, 2); 34 if (isset($kv[1])) { 35 $modes[$kv[0]] = $kv[1]; 36 } else { 37 $modes[$kv[0]] = true; 38 } 39 } 40 return $modes; 41 } 42} 43