1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-27 12:24:39 +01:00
PHP-Parser/test/testAgainstDirectory.php

118 lines
2.8 KiB
PHP
Raw Normal View History

<?php
2011-05-30 22:11:11 +02:00
$DIR = '../../Symfony';
function __autoload($class) {
is_file($file = '../lib/' . strtr($class, '_', '/') . '.php') && require_once $file;
}
2011-05-30 19:21:25 +02:00
$parser = new Parser;
$prettyPrinter = new PrettyPrinter_Zend;
2011-05-30 19:21:25 +02:00
$nodeDumper = new NodeDumper;
include './testFormatting.html';
2011-05-29 20:38:36 +02:00
echo '<table>
<tr>
<td>File</td>
<td>Parse</td>
<td>Time</td>
<td>PrettyPrint</td>
2011-05-29 20:38:36 +02:00
<td>Compare</td>
</tr>';
2011-05-29 20:38:36 +02:00
$totalStartTime = microtime(true);
$parseFail = $parseCount = $ppFail = $ppCount = $compareFail = $compareCount = 0;
foreach (new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($DIR),
RecursiveIteratorIterator::LEAVES_ONLY)
as $file) {
if ('.php' !== substr($file, -4)) {
continue;
}
echo '
<tr>
<td>' . $file . '</td>';
set_time_limit(10);
$errMsg = '';
$startTime = microtime(true);
$stmts = $parser->parse(
new Lexer(file_get_contents($file)),
function($msg) use (&$errMsg) {
$errMsg = $msg;
}
);
$time = microtime(true) - $startTime;
2011-05-29 20:38:36 +02:00
++$parseCount;
if (false !== $stmts) {
$code = '<?php' . "\n" . $prettyPrinter->pStmts($stmts);
$ppStmts = $parser->parse(
new Lexer($code),
function($msg) use (&$errMsg) {
$errMsg = $msg;
}
);
2011-05-29 20:38:36 +02:00
++$ppCount;
if (false !== $ppStmts) {
2011-05-29 20:38:36 +02:00
++$compareCount;
2011-05-30 19:21:25 +02:00
if ($nodeDumper->dump($stmts) == $nodeDumper->dump($ppStmts)) {
echo '
<td class="pass">PASS</td>
<td>' . $time . 's</td>
<td class="pass">PASS</td>
<td class="pass">PASS</td>
</tr>'; } else {
echo '
<td class="pass">PASS</td>
<td>' . $time . 's</td>
<td class="pass">PASS</td>
<td class="fail">FAIL</td>
</tr>';
2011-05-29 20:38:36 +02:00
++$compareFail;
}
} else {
echo '
<td class="pass">PASS</td>
<td>' . $time . 's</td>
<td class="fail">FAIL</td>
<td></td>
</tr>';
2011-05-29 20:38:36 +02:00
++$ppFail;
}
} else {
echo '
<td class="fail">FAIL</td>
<td>' . $time . 's</td>
<td></td>
<td></td>
</tr>
<tr class="failReason"><td colspan="5">' . $errMsg . '</td></tr>';
2011-05-29 20:38:36 +02:00
++$parseFail;
}
flush();
}
echo '
2011-05-29 20:38:36 +02:00
<tr>
<td>Fail / Total:</td>
<td><span class="failCount">' . $parseFail . '</span> / ' . $parseCount . '</td>
<td></td>
<td><span class="failCount">' . $ppFail . '</span> / ' . $ppCount . '</td>
<td><span class="failCount">' . $compareFail . '</span> / ' . $compareCount . '</td>
</tr>
</table>';
2011-05-29 20:38:36 +02:00
echo 'Total time: ', microtime(true) - $totalStartTime;