diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/ExecutionTimeTestListener.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/ExecutionTimeTestListener.php | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/ExecutionTimeTestListener.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/ExecutionTimeTestListener.php new file mode 100644 index 00000000..6d541b28 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/ExecutionTimeTestListener.php @@ -0,0 +1,92 @@ +<?php + +namespace SMW\Tests; + +use Exception; +use PHPUnit_Framework_AssertionFailedError; +use PHPUnit_Framework_Test; +use PHPUnit_Framework_TestListener; +use PHPUnit_Framework_TestSuite; +use PHPUnit_Framework_Warning; + +class ExecutionTimeTestListener implements PHPUnit_Framework_TestListener { + + protected $testCollector = []; + protected $executionTimeThresholdInSeconds = 10; + protected $isEnabledToListen = true; + + public function __construct( $isEnabledToListen, $executionTimeThresholdInSeconds ) { + $this->isEnabledToListen = $isEnabledToListen; + $this->executionTimeThresholdInSeconds = $executionTimeThresholdInSeconds; + } + + /** + * @see PHPUnit_Framework_TestListener::startTest + */ + public function startTest( PHPUnit_Framework_Test $test ) { + } + + /** + * @see PHPUnit_Framework_TestListener::endTest + */ + public function endTest( PHPUnit_Framework_Test $test, $length ) { + if ( $this->isEnabledToListen && ( $length > $this->executionTimeThresholdInSeconds ) ) { + $this->testCollector[$test->getName()] = round( $length, 3 ); + } + } + + /** + * @see PHPUnit_Framework_TestListener::addError + */ + public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) { + } + + /** + * @see PHPUnit_Framework_TestListener::addError + */ + public function addWarning( PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time) { + + } + + /** + * @see PHPUnit_Framework_TestListener::addFailure + */ + public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time ) { + } + + /** + * @see PHPUnit_Framework_TestListener::addError + */ + public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) { + } + + /** + * @see PHPUnit_Framework_TestListener::addRiskyTest + * @since 4.0.0 + */ + public function addRiskyTest( PHPUnit_Framework_Test $test, Exception $e, $time ) { + } + + /** + * @see PHPUnit_Framework_TestListener::addSkippedTest + */ + public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) { + } + + /** + * @see PHPUnit_Framework_TestListener::startTestSuite + */ + public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) { + } + + /** + * @see PHPUnit_Framework_TestListener::endTestSuite + */ + public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) { + foreach ( $this->testCollector as $name => $length ) { + print ( "\n" . $suite->getName() . " {$name} ran for {$length} seconds" . "\n" ); + unset( $this->testCollector[$name] ); + } + } + +} |