1<?php declare(strict_types=1); 2 3namespace PhpParser; 4 5require __DIR__ . '/bootstrap.php'; 6require __DIR__ . '/PhpParser/CodeTestParser.php'; 7require __DIR__ . '/PhpParser/CodeParsingTest.php'; 8 9$dir = __DIR__ . '/code/parser'; 10 11$testParser = new CodeTestParser(); 12$codeParsingTest = new CodeParsingTest(); 13foreach (filesInDir($dir, 'test') as $fileName => $code) { 14 if (false !== strpos($code, '@@{')) { 15 // Skip tests with evaluate segments 16 continue; 17 } 18 19 list($name, $tests) = $testParser->parseTest($code, 2); 20 $newTests = []; 21 foreach ($tests as list($modeLine, list($input, $expected))) { 22 $modes = $codeParsingTest->parseModeLine($modeLine); 23 $parser = $codeParsingTest->createParser($modes['version'] ?? null); 24 list(, $output) = $codeParsingTest->getParseOutput($parser, $input, $modes); 25 $newTests[] = [$modeLine, [$input, $output]]; 26 } 27 28 $newCode = $testParser->reconstructTest($name, $newTests); 29 file_put_contents($fileName, $newCode); 30} 31