php-parser/test/updateTests.php

33 lines
1.1 KiB
PHP
Raw Normal View History

2017-01-19 22:23:19 +01:00
<?php
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;
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 = null !== $modeLine ? array_fill_keys(explode(',', $modeLine), true) : [];
list($parser5, $parser7) = $codeParsingTest->createParsers($modes);
2018-07-22 15:19:40 +02:00
list(, $output) = isset($modes['php5'])
2017-01-19 22:23:19 +01:00
? $codeParsingTest->getParseOutput($parser5, $input, $modes)
: $codeParsingTest->getParseOutput($parser7, $input, $modes);
$newTests[] = [$modeLine, [$input, $output]];
}
$newCode = $testParser->reconstructTest($name, $newTests);
file_put_contents($fileName, $newCode);
2018-01-10 18:04:06 +01:00
}