mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Add improvements to unit tests
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user