PHP-Parser/test/updateTests.php

31 lines
1017 B
PHP
Raw Permalink Normal View History

2022-06-04 12:48:12 +02:00
<?php declare(strict_types=1);
2017-01-19 22:23:19 +01:00
namespace PhpParser;
require __DIR__ . '/bootstrap.php';
require __DIR__ . '/PhpParser/CodeTestParser.php';
require __DIR__ . '/PhpParser/CodeParsingTest.php';
$dir = __DIR__ . '/code/parser';
$testParser = new CodeTestParser();
$codeParsingTest = new CodeParsingTest();
2017-01-19 22:23:19 +01:00
foreach (filesInDir($dir, 'test') as $fileName => $code) {
if (false !== strpos($code, '@@{')) {
// Skip tests with evaluate segments
continue;
}
list($name, $tests) = $testParser->parseTest($code, 2);
$newTests = [];
foreach ($tests as list($modeLine, list($input, $expected))) {
$modes = $codeParsingTest->parseModeLine($modeLine);
$parser = $codeParsingTest->createParser($modes['version'] ?? null);
list(, $output) = $codeParsingTest->getParseOutput($parser, $input, $modes);
2017-01-19 22:23:19 +01:00
$newTests[] = [$modeLine, [$input, $output]];
}
$newCode = $testParser->reconstructTest($name, $newTests);
file_put_contents($fileName, $newCode);
2018-01-10 15:04:06 -02:00
}