Created
January 21, 2013 18:32
-
-
Save gcatlin/4588170 to your computer and use it in GitHub Desktop.
Print slowest PHPUnit tests
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<phpunit | |
printerClass="ProfilerPrinter" | |
printerFile="profiler.php" | |
> | |
</phpunit> |
This file contains 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 | |
class ProfilerPrinter extends PHPUnit_TextUI_ResultPrinter | |
{ | |
private $current_suite; | |
private $test_times = array(); | |
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) | |
{ | |
parent::startTestSuite($suite); | |
$this->current_suite = $suite->getName(); | |
} | |
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) | |
{ | |
parent::endTestSuite($suite); | |
$this->current_suite = null; | |
} | |
public function endTest(PHPUnit_Framework_Test $test, $time) | |
{ | |
parent::endTest($test, $time); | |
$this->test_times[$this->current_suite . '::' . $test->getName()] = $time; | |
} | |
protected function printFooter(PHPUnit_Framework_TestResult $result) | |
{ | |
parent::printFooter($result); | |
arsort($this->test_times); | |
$top_five = array_slice($this->test_times, 0, 5); | |
echo "\n"; | |
echo "5 Slowest Tests:\n"; | |
foreach ($top_five as $test => $time) { | |
printf("%0.3f\t%s\n", $time, $test); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd rather write a script that parses that information from the XML logfile.