mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR: Added test listeners to support TeamCity/PHPUnit executions.
This commit is contained in:
parent
07c4860031
commit
f3467a3337
45
dev/SilverStripeListener.php
Normal file
45
dev/SilverStripeListener.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
// 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
|
||||
|
||||
class SilverStripeListener implements PHPUnit_Framework_TestListener {
|
||||
|
||||
protected function isValidClass($name) {
|
||||
return (class_exists($name) && is_subclass_of($name, 'SapphireTest'));
|
||||
}
|
||||
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||
$name = $suite->getName();
|
||||
if(!$this->isValidClass($name)) return;
|
||||
|
||||
$class = new $name();
|
||||
$class->setUpOnce();
|
||||
}
|
||||
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||
$name = $suite->getName();
|
||||
if(!$this->isValidClass($name)) return;
|
||||
|
||||
$class = new $name();
|
||||
$class->tearDownOnce();
|
||||
}
|
||||
|
||||
public function startTest(PHPUnit_Framework_Test $test) {
|
||||
}
|
||||
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time) {
|
||||
}
|
||||
|
||||
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) {
|
||||
}
|
||||
}
|
59
dev/TeamCityListener.php
Normal file
59
dev/TeamCityListener.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
// Bind TeamCity test listener. Echos messages to stdout that TeamCity interprets into the test results
|
||||
|
||||
class TeamCityListener implements PHPUnit_Framework_TestListener {
|
||||
|
||||
private function escape($str) {
|
||||
return strtr($str, array(
|
||||
"\n" => '|n',
|
||||
"\r" => '|r',
|
||||
"[" => '|[',
|
||||
"]" => '|]',
|
||||
"'" => "|'",
|
||||
"|" => '||'
|
||||
));
|
||||
}
|
||||
|
||||
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||
echo "##teamcity[testSuiteStarted name='{$suite->getName()}']\n";
|
||||
}
|
||||
|
||||
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||
echo "##teamcity[testSuiteFinished name='{$suite->getName()}']\n";
|
||||
}
|
||||
|
||||
public function startTest(PHPUnit_Framework_Test $test) {
|
||||
$class = get_class($test);
|
||||
echo "##teamcity[testStarted name='{$class}.{$test->getName()}']\n";
|
||||
}
|
||||
|
||||
public function endTest(PHPUnit_Framework_Test $test, $time) {
|
||||
$class = get_class($test);
|
||||
echo "##teamcity[testFinished name='{$class}.{$test->getName()}' duration='$time']\n";
|
||||
}
|
||||
|
||||
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||
$class = get_class($test);
|
||||
$message = $this->escape("Exception: {$e->getMessage()}");
|
||||
$trace = $this->escape($e->getTraceAsString());
|
||||
echo "##teamcity[testFailed type='exception' name='{$class}.{$test->getName()}' message='$message' details='$trace']\n";
|
||||
}
|
||||
|
||||
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
|
||||
$class = get_class($test);
|
||||
$message = $this->escape($e->getMessage());
|
||||
$trace = $this->escape($e->getTraceAsString());
|
||||
echo "##teamcity[testFailed type='failure' name='{$class}.{$test->getName()}' message='$message' details='$trace']\n";
|
||||
}
|
||||
|
||||
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||
$class = get_class($test);
|
||||
$message = $this->escape($e->getMessage());
|
||||
echo "##teamcity[testIgnored name='{$class}.{$test->getName()}' message='$message']\n";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user