-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTeamCityListener.php
More file actions
130 lines (122 loc) · 3.42 KB
/
TeamCityListener.php
File metadata and controls
130 lines (122 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* This class helps to integrate PHPUnit to TeamCity.
* For each important function it prints special message which could be
* parsed and handled by TeamCity
*
* @author sery0ga
*
* Realweb 2012
*/
class TeamCityListener implements PHPUnit_Framework_TestListener {
/**
* Print message on error
*
* @attention TeamCity doesn't support errors so we handle them as failures
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param integer $time
*/
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
echo $e->getMessage();
printf(
"##teamcity[testFailed name='%s' details='See full log for details']\n",
$test->getName()
);
}
/**
* Print message on failure
*
* @param PHPUnit_Framework_Test $test
* @param PHPUnit_Framework_AssertionFailedError $e
* @param integer $time
*/
public function addFailure(
PHPUnit_Framework_Test $test,
PHPUnit_Framework_AssertionFailedError $e,
$time
) {
echo $e->getMessage();
printf(
"##teamcity[testFailed name='%s' details='See full log for details']\n",
$test->getName()
);
}
/**
* Print message on incomplete test
*
* @attention TeamCity doesn't support incomplete tests so we handle them as skipped
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param integer $time
*/
public function addIncompleteTest(
PHPUnit_Framework_Test $test,
Exception $e,
$time
) {
printf(
"##teamcity[testIgnored name='%s' message='%s']\n",
$test->getName(),
str_replace("\n", "|n|r ", $e->getMessage())
);
}
/**
* Print message on skipped test
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param integer $time
*/
public function addSkippedTest(
PHPUnit_Framework_Test $test,
Exception $e,
$time
) {
printf(
"##teamcity[testIgnored name='%s' message='%s']\n",
$test->getName(),
str_replace("\n", "|n|r ", $e->getMessage())
);
}
/**
* Print message when test starts
*
* @param PHPUnit_Framework_Test $test
*/
public function startTest(PHPUnit_Framework_Test $test) {
printf(
"##teamcity[testStarted name='%s' captureStandardOutput='true']\n",
$test->getName()
);
}
/**
* Print message when test ends
*
* @param PHPUnit_Framework_Test $test
* @param integer $time
*/
public function endTest(PHPUnit_Framework_Test $test, $time) {
printf(
"##teamcity[testFinished name='%s' duration='%s']\n",
$test->getName(),
$time*1000
);
}
/**
* Print message when test suite starts
*
* @param PHPUnit_Framework_TestSuite $suite
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
printf("##teamcity[testSuiteStarted name='%s']\n", $suite->getName());
}
/**
* Print message when test suite ends
*
* @param PHPUnit_Framework_TestSuite $suite
*/
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
printf("##teamcity[testSuiteFinished name='%s']\n", $suite->getName());
}
}