33namespace Yandex \Allure \Adapter ;
44
55use 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 ;
1114use Yandex \Allure \Adapter \Annotation ;
1215use Yandex \Allure \Adapter \Event \TestCaseBrokenEvent ;
1316use Yandex \Allure \Adapter \Event \TestCaseCanceledEvent ;
1922use Yandex \Allure \Adapter \Event \TestSuiteStartedEvent ;
2023use Yandex \Allure \Adapter \Model ;
2124
22- class AllureAdapter implements PHPUnit_Framework_TestListener
25+ class AllureAdapter implements TestListener
2326{
2427
2528 //NOTE: here we implicitly assume that PHPUnit runs in single-threaded mode
@@ -28,7 +31,7 @@ class AllureAdapter implements PHPUnit_Framework_TestListener
2831 private $ methodName ;
2932
3033 /**
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)
3235 * @var array
3336 */
3437 private $ ignoredAnnotations = [
@@ -43,7 +46,7 @@ class AllureAdapter implements PHPUnit_Framework_TestListener
4346 /**
4447 * @param string $outputDirectory XML files output directory
4548 * @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
4750 */
4851 public function __construct (
4952 $ outputDirectory ,
@@ -83,32 +86,44 @@ public function prepareOutputDirectory($outputDirectory, $deletePreviousResults)
8386 /**
8487 * An error occurred.
8588 *
86- * @param PHPUnit_Framework_Test $test
89+ * @param Test $test
8790 * @param Exception $e
8891 * @param float $time
8992 */
90- public function addError (PHPUnit_Framework_Test $ test , Exception $ e , $ time )
93+ public function addError (Test $ test , Exception $ e , $ time )
9194 {
9295 $ event = new TestCaseBrokenEvent ();
9396 Allure::lifecycle ()->fire ($ event ->withException ($ e )->withMessage ($ e ->getMessage ()));
9497 }
9598
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+
96111 /**
97112 * A failure occurred.
98113 *
99- * @param PHPUnit_Framework_Test $test
100- * @param PHPUnit_Framework_AssertionFailedError $e
114+ * @param Test $test
115+ * @param AssertionFailedError $e
101116 * @param float $time
102117 */
103- public function addFailure (PHPUnit_Framework_Test $ test , PHPUnit_Framework_AssertionFailedError $ e , $ time )
118+ public function addFailure (Test $ test , AssertionFailedError $ e , $ time )
104119 {
105120 $ event = new TestCaseFailedEvent ();
106121
107122 $ message = $ e ->getMessage ();
108123
109124 // 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 ' ))
112127 && $ e ->getComparisonFailure ()
113128 ) {
114129 $ message .= $ e ->getComparisonFailure ()->getDiff ();
@@ -120,11 +135,11 @@ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_Asser
120135 /**
121136 * Incomplete test.
122137 *
123- * @param PHPUnit_Framework_Test $test
138+ * @param Test $test
124139 * @param Exception $e
125140 * @param float $time
126141 */
127- public function addIncompleteTest (PHPUnit_Framework_Test $ test , Exception $ e , $ time )
142+ public function addIncompleteTest (Test $ test , Exception $ e , $ time )
128143 {
129144 $ event = new TestCasePendingEvent ();
130145 Allure::lifecycle ()->fire ($ event ->withException ($ e ));
@@ -133,28 +148,28 @@ public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $t
133148 /**
134149 * Risky test.
135150 *
136- * @param PHPUnit_Framework_Test $test
151+ * @param Test $test
137152 * @param Exception $e
138153 * @param float $time
139154 * @since Method available since Release 4.0.0
140155 */
141- public function addRiskyTest (PHPUnit_Framework_Test $ test , Exception $ e , $ time )
156+ public function addRiskyTest (Test $ test , Exception $ e , $ time )
142157 {
143158 $ this ->addIncompleteTest ($ test , $ e , $ time );
144159 }
145160
146161 /**
147162 * Skipped test.
148163 *
149- * @param PHPUnit_Framework_Test $test
164+ * @param Test $test
150165 * @param Exception $e
151166 * @param float $time
152167 * @since Method available since Release 3.0.0
153168 */
154- public function addSkippedTest (PHPUnit_Framework_Test $ test , Exception $ e , $ time )
169+ public function addSkippedTest (Test $ test , Exception $ e , $ time )
155170 {
156171 $ shouldCreateStartStopEvents = false ;
157- if ($ test instanceof \PHPUnit_Framework_TestCase ){
172+ if ($ test instanceof TestCase ){
158173 $ methodName = $ test ->getName ();
159174 if ($ methodName !== $ this ->methodName ){
160175 $ shouldCreateStartStopEvents = true ;
@@ -165,20 +180,20 @@ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time
165180 $ event = new TestCaseCanceledEvent ();
166181 Allure::lifecycle ()->fire ($ event ->withException ($ e )->withMessage ($ e ->getMessage ()));
167182
168- if ($ shouldCreateStartStopEvents && $ test instanceof \PHPUnit_Framework_TestCase ){
183+ if ($ shouldCreateStartStopEvents && $ test instanceof TestCase ){
169184 $ this ->endTest ($ test , 0 );
170185 }
171186 }
172187
173188 /**
174189 * A test suite started.
175190 *
176- * @param PHPUnit_Framework_TestSuite $suite
191+ * @param TestSuite $suite
177192 * @since Method available since Release 2.2.0
178193 */
179- public function startTestSuite (PHPUnit_Framework_TestSuite $ suite )
194+ public function startTestSuite (TestSuite $ suite )
180195 {
181- if ($ suite instanceof \PHPUnit_Framework_TestSuite_DataProvider ) {
196+ if ($ suite instanceof DataProviderTestSuite ) {
182197 return ;
183198 }
184199
@@ -200,12 +215,12 @@ public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
200215 /**
201216 * A test suite ended.
202217 *
203- * @param PHPUnit_Framework_TestSuite $suite
218+ * @param TestSuite $suite
204219 * @since Method available since Release 2.2.0
205220 */
206- public function endTestSuite (PHPUnit_Framework_TestSuite $ suite )
221+ public function endTestSuite (TestSuite $ suite )
207222 {
208- if ($ suite instanceof \PHPUnit_Framework_TestSuite_DataProvider ) {
223+ if ($ suite instanceof DataProviderTestSuite ) {
209224 return ;
210225 }
211226
@@ -215,11 +230,11 @@ public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
215230 /**
216231 * A test started.
217232 *
218- * @param PHPUnit_Framework_Test $test
233+ * @param Test $test
219234 */
220- public function startTest (PHPUnit_Framework_Test $ test )
235+ public function startTest (Test $ test )
221236 {
222- if ($ test instanceof \PHPUnit_Framework_TestCase ) {
237+ if ($ test instanceof TestCase ) {
223238 $ testName = $ test ->getName ();
224239 $ methodName = $ this ->methodName = $ test ->getName (false );
225240
@@ -237,13 +252,13 @@ public function startTest(PHPUnit_Framework_Test $test)
237252 /**
238253 * A test ended.
239254 *
240- * @param PHPUnit_Framework_Test $test
255+ * @param Test $test
241256 * @param float $time
242257 * @throws \Exception
243258 */
244- public function endTest (PHPUnit_Framework_Test $ test , $ time )
259+ public function endTest (Test $ test , $ time )
245260 {
246- if ($ test instanceof \PHPUnit_Framework_TestCase ) {
261+ if ($ test instanceof TestCase ) {
247262 Allure::lifecycle ()->fire (new TestCaseFinishedEvent ());
248263 }
249264 }
0 commit comments