3
3
namespace Yandex \Allure \Adapter ;
4
4
5
5
use Exception ;
6
- use PHPUnit_Framework_AssertionFailedError ;
7
- use PHPUnit_Framework_ExpectationFailedException ;
8
- use PHPUnit_Framework_Test ;
9
- use PHPUnit_Framework_TestListener ;
10
- use PHPUnit_Framework_TestSuite ;
6
+ use PHPUnit \Framework \AssertionFailedError ;
7
+ use PHPUnit \Framework \ExpectationFailedException ;
8
+ use PHPUnit \Framework \Test ;
9
+ use PHPUnit \Framework \TestCase ;
10
+ use PHPUnit \Framework \TestListener ;
11
+ use PHPUnit \Framework \TestSuite ;
12
+ use PHPUnit \Framework \DataProviderTestSuite ;
13
+ use PHPUnit \Framework \Warning ;
11
14
use Yandex \Allure \Adapter \Annotation ;
12
15
use Yandex \Allure \Adapter \Event \TestCaseBrokenEvent ;
13
16
use Yandex \Allure \Adapter \Event \TestCaseCanceledEvent ;
19
22
use Yandex \Allure \Adapter \Event \TestSuiteStartedEvent ;
20
23
use Yandex \Allure \Adapter \Model ;
21
24
22
- class AllureAdapter implements PHPUnit_Framework_TestListener
25
+ class AllureAdapter implements TestListener
23
26
{
24
27
25
28
//NOTE: here we implicitly assume that PHPUnit runs in single-threaded mode
@@ -28,7 +31,7 @@ class AllureAdapter implements PHPUnit_Framework_TestListener
28
31
private $ methodName ;
29
32
30
33
/**
31
- * Annotations that should be ignored by the annotaions parser (especially PHPUnit annotations)
34
+ * Annotations that should be ignored by the annotations parser (especially PHPUnit annotations)
32
35
* @var array
33
36
*/
34
37
private $ ignoredAnnotations = [
@@ -43,7 +46,7 @@ class AllureAdapter implements PHPUnit_Framework_TestListener
43
46
/**
44
47
* @param string $outputDirectory XML files output directory
45
48
* @param bool $deletePreviousResults Whether to delete previous results on return
46
- * @param array $ignoredAnnotations Extra annotaions to ignore in addition to standard PHPUnit annotations
49
+ * @param array $ignoredAnnotations Extra annotations to ignore in addition to standard PHPUnit annotations
47
50
*/
48
51
public function __construct (
49
52
$ outputDirectory ,
@@ -83,32 +86,44 @@ public function prepareOutputDirectory($outputDirectory, $deletePreviousResults)
83
86
/**
84
87
* An error occurred.
85
88
*
86
- * @param PHPUnit_Framework_Test $test
89
+ * @param Test $test
87
90
* @param Exception $e
88
91
* @param float $time
89
92
*/
90
- public function addError (PHPUnit_Framework_Test $ test , Exception $ e , $ time )
93
+ public function addError (Test $ test , Exception $ e , $ time )
91
94
{
92
95
$ event = new TestCaseBrokenEvent ();
93
96
Allure::lifecycle ()->fire ($ event ->withException ($ e )->withMessage ($ e ->getMessage ()));
94
97
}
95
98
99
+ /**
100
+ * A warning occurred.
101
+ *
102
+ * @param \PHPUnit\Framework\Test $test
103
+ * @param \PHPUnit\Framework\Warning $e
104
+ * @param float $time
105
+ */
106
+ public function addWarning (Test $ test , Warning $ e , $ time )
107
+ {
108
+ // TODO: Implement addWarning() method.
109
+ }
110
+
96
111
/**
97
112
* A failure occurred.
98
113
*
99
- * @param PHPUnit_Framework_Test $test
100
- * @param PHPUnit_Framework_AssertionFailedError $e
114
+ * @param Test $test
115
+ * @param AssertionFailedError $e
101
116
* @param float $time
102
117
*/
103
- public function addFailure (PHPUnit_Framework_Test $ test , PHPUnit_Framework_AssertionFailedError $ e , $ time )
118
+ public function addFailure (Test $ test , AssertionFailedError $ e , $ time )
104
119
{
105
120
$ event = new TestCaseFailedEvent ();
106
121
107
122
$ message = $ e ->getMessage ();
108
123
109
124
// Append comparison diff for errors of type ExpectationFailedException (and is subclasses)
110
- if (($ e instanceof PHPUnit_Framework_ExpectationFailedException
111
- || is_subclass_of ($ e , '\PHPUnit_Framework_ExpectationFailedException ' ))
125
+ if (($ e instanceof ExpectationFailedException
126
+ || is_subclass_of ($ e , 'PHPUnit\Framework\ExpectationFailedException ' ))
112
127
&& $ e ->getComparisonFailure ()
113
128
) {
114
129
$ message .= $ e ->getComparisonFailure ()->getDiff ();
@@ -120,11 +135,11 @@ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_Asser
120
135
/**
121
136
* Incomplete test.
122
137
*
123
- * @param PHPUnit_Framework_Test $test
138
+ * @param Test $test
124
139
* @param Exception $e
125
140
* @param float $time
126
141
*/
127
- public function addIncompleteTest (PHPUnit_Framework_Test $ test , Exception $ e , $ time )
142
+ public function addIncompleteTest (Test $ test , Exception $ e , $ time )
128
143
{
129
144
$ event = new TestCasePendingEvent ();
130
145
Allure::lifecycle ()->fire ($ event ->withException ($ e ));
@@ -133,28 +148,28 @@ public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $t
133
148
/**
134
149
* Risky test.
135
150
*
136
- * @param PHPUnit_Framework_Test $test
151
+ * @param Test $test
137
152
* @param Exception $e
138
153
* @param float $time
139
154
* @since Method available since Release 4.0.0
140
155
*/
141
- public function addRiskyTest (PHPUnit_Framework_Test $ test , Exception $ e , $ time )
156
+ public function addRiskyTest (Test $ test , Exception $ e , $ time )
142
157
{
143
158
$ this ->addIncompleteTest ($ test , $ e , $ time );
144
159
}
145
160
146
161
/**
147
162
* Skipped test.
148
163
*
149
- * @param PHPUnit_Framework_Test $test
164
+ * @param Test $test
150
165
* @param Exception $e
151
166
* @param float $time
152
167
* @since Method available since Release 3.0.0
153
168
*/
154
- public function addSkippedTest (PHPUnit_Framework_Test $ test , Exception $ e , $ time )
169
+ public function addSkippedTest (Test $ test , Exception $ e , $ time )
155
170
{
156
171
$ shouldCreateStartStopEvents = false ;
157
- if ($ test instanceof \PHPUnit_Framework_TestCase ){
172
+ if ($ test instanceof TestCase ){
158
173
$ methodName = $ test ->getName ();
159
174
if ($ methodName !== $ this ->methodName ){
160
175
$ shouldCreateStartStopEvents = true ;
@@ -165,20 +180,20 @@ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time
165
180
$ event = new TestCaseCanceledEvent ();
166
181
Allure::lifecycle ()->fire ($ event ->withException ($ e )->withMessage ($ e ->getMessage ()));
167
182
168
- if ($ shouldCreateStartStopEvents && $ test instanceof \PHPUnit_Framework_TestCase ){
183
+ if ($ shouldCreateStartStopEvents && $ test instanceof TestCase ){
169
184
$ this ->endTest ($ test , 0 );
170
185
}
171
186
}
172
187
173
188
/**
174
189
* A test suite started.
175
190
*
176
- * @param PHPUnit_Framework_TestSuite $suite
191
+ * @param TestSuite $suite
177
192
* @since Method available since Release 2.2.0
178
193
*/
179
- public function startTestSuite (PHPUnit_Framework_TestSuite $ suite )
194
+ public function startTestSuite (TestSuite $ suite )
180
195
{
181
- if ($ suite instanceof \PHPUnit_Framework_TestSuite_DataProvider ) {
196
+ if ($ suite instanceof DataProviderTestSuite ) {
182
197
return ;
183
198
}
184
199
@@ -200,12 +215,12 @@ public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
200
215
/**
201
216
* A test suite ended.
202
217
*
203
- * @param PHPUnit_Framework_TestSuite $suite
218
+ * @param TestSuite $suite
204
219
* @since Method available since Release 2.2.0
205
220
*/
206
- public function endTestSuite (PHPUnit_Framework_TestSuite $ suite )
221
+ public function endTestSuite (TestSuite $ suite )
207
222
{
208
- if ($ suite instanceof \PHPUnit_Framework_TestSuite_DataProvider ) {
223
+ if ($ suite instanceof DataProviderTestSuite ) {
209
224
return ;
210
225
}
211
226
@@ -215,11 +230,11 @@ public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
215
230
/**
216
231
* A test started.
217
232
*
218
- * @param PHPUnit_Framework_Test $test
233
+ * @param Test $test
219
234
*/
220
- public function startTest (PHPUnit_Framework_Test $ test )
235
+ public function startTest (Test $ test )
221
236
{
222
- if ($ test instanceof \PHPUnit_Framework_TestCase ) {
237
+ if ($ test instanceof TestCase ) {
223
238
$ testName = $ test ->getName ();
224
239
$ methodName = $ this ->methodName = $ test ->getName (false );
225
240
@@ -237,13 +252,13 @@ public function startTest(PHPUnit_Framework_Test $test)
237
252
/**
238
253
* A test ended.
239
254
*
240
- * @param PHPUnit_Framework_Test $test
255
+ * @param Test $test
241
256
* @param float $time
242
257
* @throws \Exception
243
258
*/
244
- public function endTest (PHPUnit_Framework_Test $ test , $ time )
259
+ public function endTest (Test $ test , $ time )
245
260
{
246
- if ($ test instanceof \PHPUnit_Framework_TestCase ) {
261
+ if ($ test instanceof TestCase ) {
247
262
Allure::lifecycle ()->fire (new TestCaseFinishedEvent ());
248
263
}
249
264
}
0 commit comments