updateTests.php 1.1 KB

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