Add improvements to unit tests

This commit is contained in:
Romain Neutron
2013-12-19 12:08:59 +01:00
parent 49ea64b1c3
commit 6c45e8d40a
39 changed files with 583 additions and 689 deletions

View File

@@ -2,28 +2,27 @@
class PhraseanetPHPUnitListener implements PHPUnit_Framework_TestListener
{
private static $enableDurationCapture = false;
private static $skipped = [];
private static $duration = [];
private static $csv = [];
private static $durationByTest = [];
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
{
return;
}
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
{
return;
}
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
return;
}
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
static::$skipped[] = get_class($test) . ':' . $test->getName() . ' - ' . $e->getMessage();
return;
}
public static function getSkipped()
@@ -31,30 +30,89 @@ class PhraseanetPHPUnitListener implements PHPUnit_Framework_TestListener
return static::$skipped;
}
public static function getDuration()
{
return static::$duration;
}
public static function getCsv()
{
return static::$csv;
}
public static function getDurationByTest()
{
return static::$durationByTest;
}
public static function resetSkipped()
{
static::$skipped = [];
}
return;
public static function resetDuration()
{
static::$duration = [];
static::$durationByTest = [];
static::$csv = [];
}
public function startTest(PHPUnit_Framework_Test $test)
{
return;
if (!static::$enableDurationCapture) {
return;
}
if (!isset(static::$durationByTest[get_class($test)]['executions'])) {
static::$durationByTest[get_class($test)]['executions'] = 0;
}
static::$durationByTest[get_class($test)]['executions']++;
static::$duration[self::generateName($test)] = microtime(true);
static::$csv[self::generateName($test)] = [
'duration' => microtime(true),
'test' => get_class($test),
'name' => $test->getName(),
];
}
public function endTest(PHPUnit_Framework_Test $test, $time)
{
return;
if (!static::$enableDurationCapture) {
return;
}
$name = self::generateName($test);
static::$duration[$name] = microtime(true) - static::$duration[$name];
static::$csv[self::generateName($test)]['duration'] = microtime(true) - static::$csv[self::generateName($test)]['duration'];
}
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
{
return;
if (!static::$enableDurationCapture) {
return;
}
if (!class_exists($suite->getName())) {
return;
}
static::$durationByTest[$suite->getName()]['time'] = microtime(true);
}
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
{
return;
if (!static::$enableDurationCapture) {
return;
}
if (!class_exists($suite->getName())) {
return;
}
static::$durationByTest[$suite->getName()]['time'] = microtime(true) - static::$durationByTest[$suite->getName()]['time'];
}
private static function generateName(PHPUnit_Framework_Test $test)
{
return get_class($test) . '::' . $test->getName();
}
}