silverstripe-framework/Dev/TestListener.php

72 lines
2.0 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\Dev;
use PHPUnit_Framework_TestListener;
use PHPUnit_Framework_Test;
use PHPUnit_Framework_AssertionFailedError;
use PHPUnit_Framework_TestSuite;
2016-09-09 08:43:05 +02:00
use Exception;
/**
* Necessary to call setUpOnce() and tearDownOnce() on {@link SapphireTest}
* classes. This feature doesn't exist in PHPUnit in the same way
* (setUpBeforeClass() and tearDownAfterClass() are just called statically).
2014-08-15 08:53:05 +02:00
*
* @see http://www.phpunit.de/manual/3.5/en/extending-phpunit.html#extending-phpunit.PHPUnit_Framework_TestListener
*/
2016-09-09 08:43:05 +02:00
class TestListener implements PHPUnit_Framework_TestListener {
2014-08-15 08:53:05 +02:00
/**
* @var SapphireTest
*/
protected $class;
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 endTest(PHPUnit_Framework_Test $test, $time) {}
2014-08-15 08:53:05 +02:00
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
$name = $suite->getName();
if(!$this->isValidClass($name)) return;
2014-08-15 08:53:05 +02:00
$this->class = new $name();
$this->class->setUpOnce();
}
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
$name = $suite->getName();
if(!$this->isValidClass($name)) return;
2014-08-15 08:53:05 +02:00
$this->class->tearDownOnce();
}
2014-08-15 08:53:05 +02:00
2014-03-30 08:37:54 +02:00
/**
* Risky test.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
* @since Method available since Release 3.8.0
*/
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
// Stub out to support PHPUnit 3.8
}
/**
* @param string $name Class Name
* @return boolean
*/
protected function isValidClass($name) {
return (class_exists($name) && is_subclass_of($name, 'SilverStripe\\Dev\\SapphireTest'));
}
}