mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT Added custom test listener for PHPUnit in order to call setUpOnce() and tearDownOnce() on SapphireTest (from r111050)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112888 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
abe50eb26a
commit
ea2b86cd1d
48
dev/TestListener.php
Normal file
48
dev/TestListener.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 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).
|
||||||
|
*
|
||||||
|
* @see http://www.phpunit.de/manual/3.5/en/extending-phpunit.html#extending-phpunit.PHPUnit_Framework_TestListener
|
||||||
|
*
|
||||||
|
* @package sapphire
|
||||||
|
* @subpackage testing
|
||||||
|
*/
|
||||||
|
class SS_TestListener implements PHPUnit_Framework_TestListener {
|
||||||
|
|
||||||
|
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) {}
|
||||||
|
|
||||||
|
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||||
|
$name = $suite->getName();
|
||||||
|
if(!$this->isValidClass($name)) return;
|
||||||
|
|
||||||
|
$this->class = new $name();
|
||||||
|
$this->class->setUpOnce();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||||
|
$name = $suite->getName();
|
||||||
|
if(!$this->isValidClass($name)) return;
|
||||||
|
|
||||||
|
$this->class->tearDownOnce();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param String Classname
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected function isValidClass($name) {
|
||||||
|
return (class_exists($name) && is_subclass_of($name, 'SapphireTest'));
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,10 @@
|
|||||||
/**
|
/**
|
||||||
* Controller that executes PHPUnit tests.
|
* Controller that executes PHPUnit tests.
|
||||||
*
|
*
|
||||||
|
* Alternatively, you can also use the "phpunit" binary directly by
|
||||||
|
* pointing it to a file or folder containing unit tests.
|
||||||
|
* See phpunit.dist.xml in the webroot for configuration details.
|
||||||
|
*
|
||||||
* <h2>URL Options</h2>
|
* <h2>URL Options</h2>
|
||||||
* - SkipTests: A comma-separated list of test classes to skip (useful when running dev/tests/all)
|
* - SkipTests: A comma-separated list of test classes to skip (useful when running dev/tests/all)
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user