Created
August 13, 2010 16:28
-
-
Save zacharydanger/523152 to your computer and use it in GitHub Desktop.
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
<?xml version="1.0" ?> | |
<phpunit> | |
<listeners> | |
<listener class="TimeLoggerListener" file="./TimeLoggerListener.php"> | |
<arguments> | |
<string>/tmp/test-time.csv</string> | |
</arguments> | |
</listener> | |
</listeners> | |
</phpunit> |
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 | |
require_once 'PHPUnit/Framework.php'; | |
class TimeLoggerListener implements PHPUnit_Framework_TestListener { | |
private $_filename; | |
private $_handle; | |
public function __construct($filename) { | |
$this->_filename = $filename; | |
} | |
public function endTest(PHPUnit_Framework_Test $test, $time) { | |
$this->_writeLog(get_class($test) . '::' . $test->getName() . "\t" . $time); | |
} | |
private function _writeLog($message) { | |
$file = $this->_getHandle(); | |
fwrite($file, $message . "\n"); | |
} | |
private function _getHandle() { | |
if(false == isset($this->_handle)) { | |
$handle = fopen($this->_filename, 'a'); | |
} else { | |
$handle = $this->_handle; | |
} | |
return $handle; | |
} | |
/***************************************************************************************** | |
* These functions are required by the interface, but aren't actually used for anything. * | |
*****************************************************************************************/ | |
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) { } | |
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { } | |
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) { } | |
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) { } | |
public function startTest(PHPUnit_Framework_Test $test) { } | |
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { } | |
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) { } | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment