2012-05-28 08:31:48 +02:00
|
|
|
<?php
|
2013-11-29 05:12:47 +01:00
|
|
|
/**
|
|
|
|
* Bind TeamCity test listener. Echos messages to stdout that TeamCity interprets into the test results
|
|
|
|
*
|
|
|
|
* @package framework
|
|
|
|
* @subpackage testing
|
|
|
|
*/
|
2012-05-28 08:31:48 +02:00
|
|
|
class TeamCityListener implements PHPUnit_Framework_TestListener {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-28 08:31:48 +02:00
|
|
|
private function escape($str) {
|
|
|
|
return strtr($str, array(
|
|
|
|
"\n" => '|n',
|
|
|
|
"\r" => '|r',
|
|
|
|
"[" => '|[',
|
|
|
|
"]" => '|]',
|
|
|
|
"'" => "|'",
|
|
|
|
"|" => '||'
|
|
|
|
));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-28 08:31:48 +02:00
|
|
|
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";
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-28 08:31:48 +02:00
|
|
|
public function startTest(PHPUnit_Framework_Test $test) {
|
|
|
|
$class = get_class($test);
|
|
|
|
echo "##teamcity[testStarted name='{$class}.{$test->getName()}']\n";
|
|
|
|
}
|
2012-12-08 12:20:20 +01:00
|
|
|
|
2012-05-28 08:31:48 +02:00
|
|
|
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());
|
2012-09-26 23:34:00 +02:00
|
|
|
echo "##teamcity[testFailed type='exception' name='{$class}.{$test->getName()}' message='$message'"
|
|
|
|
. " details='$trace']\n";
|
2012-05-28 08:31:48 +02:00
|
|
|
}
|
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) {
|
|
|
|
$class = get_class($test);
|
2015-08-21 07:30:50 +02:00
|
|
|
$message = $this->escape(PHPUnit_Framework_TestFailure::exceptionToString($e));
|
2012-05-28 08:31:48 +02:00
|
|
|
$trace = $this->escape($e->getTraceAsString());
|
2012-09-26 23:34:00 +02:00
|
|
|
echo "##teamcity[testFailed type='failure' name='{$class}.{$test->getName()}' message='$message'"
|
|
|
|
. " details='$trace']\n";
|
2012-05-28 08:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
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
|
|
|
|
}
|
2012-05-28 08:31:48 +02:00
|
|
|
}
|