2012-05-28 08:31:48 +02:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\Dev;
|
|
|
|
|
|
|
|
use PHPUnit_Framework_TestListener;
|
|
|
|
use PHPUnit_Framework_TestSuite;
|
|
|
|
use PHPUnit_Framework_Test;
|
|
|
|
use Exception;
|
|
|
|
use PHPUnit_Framework_AssertionFailedError;
|
|
|
|
|
2013-11-29 05:12:47 +01:00
|
|
|
/**
|
|
|
|
* Inject SilverStripe 'setUpOnce' and 'tearDownOnce' unittest extension methods into PHPUnit.
|
|
|
|
*
|
|
|
|
* This is already in later SilverStripe 2.4 versions, but having it here extends compatibility to older versions.
|
|
|
|
*/
|
2012-05-28 08:31:48 +02:00
|
|
|
class SilverStripeListener implements PHPUnit_Framework_TestListener {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-28 08:31:48 +02:00
|
|
|
protected function isValidClass($name) {
|
2016-08-19 00:51:35 +02:00
|
|
|
return (class_exists($name) && is_subclass_of($name, 'SilverStripe\\Dev\\SapphireTest'));
|
2012-05-28 08:31:48 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-28 08:31:48 +02:00
|
|
|
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
|
|
|
$name = $suite->getName();
|
|
|
|
if(!$this->isValidClass($name)) return;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
/** @var SapphireTest $class */
|
2012-05-28 08:31:48 +02:00
|
|
|
$class = new $name();
|
|
|
|
$class->setUpOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
|
|
|
$name = $suite->getName();
|
|
|
|
if(!$this->isValidClass($name)) return;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
/** @var SapphireTest $class */
|
2012-05-28 08:31:48 +02:00
|
|
|
$class = new $name();
|
|
|
|
$class->tearDownOnce();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-28 08:31:48 +02:00
|
|
|
public function startTest(PHPUnit_Framework_Test $test) {
|
|
|
|
}
|
2012-12-08 12:20:20 +01:00
|
|
|
|
2012-05-28 08:31:48 +02:00
|
|
|
public function endTest(PHPUnit_Framework_Test $test, $time) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
|
|
|
}
|
2012-12-08 12:20:20 +01:00
|
|
|
|
2012-05-28 08:31:48 +02:00
|
|
|
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) {
|
|
|
|
}
|
2014-02-04 00:32:58 +01: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
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|