-
-
Save liuggio/2793706 to your computer and use it in GitHub Desktop.
PHPUnit --log-junit processor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This script is used to process the output of a PHPUnit test run | |
* that uses --log-junit for the purposes of timing each executed | |
* test method. It outputs test methods with their respective | |
* runtimes in order from largest to smallest. Times are in | |
* seconds. The script accepts paths to any number of files in the | |
* JUnit log format. | |
* | |
* Ex: php phpunit-log-junit.php /path/to/junit-log1.xml /path/to/junit-log2.xml ... | |
*/ | |
array_shift($argv); | |
$data = array(); | |
foreach ($argv as $file) { | |
$doc = new DOMDocument; | |
$doc->load($file); | |
$xpath = new DOMXPath($doc); | |
$results = $xpath->query('//testcase[@class]'); | |
foreach ($results as $result) { | |
$class = $result->getAttribute('class'); | |
$method = $result->getAttribute('name'); | |
$time = $result->getAttribute('time'); | |
$data[$class . '->' . $method] = $time; | |
} | |
$results = $xpath->query('//testsuite/testsuite/testcase'); | |
foreach ($results as $result) { | |
$class = $result->parentNode->parentNode->getAttribute('name'); | |
$method = $result->getAttribute('name'); | |
$time = $result->getAttribute('time'); | |
$data[$class . '->' . $method] = $time; | |
} | |
} | |
arsort($data); | |
$pad = strlen(max($data)); | |
foreach ($data as $test => $time) { | |
echo str_pad($time, $pad, STR_PAD_LEFT), ' ', $test, PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment