Skip to content

Commit 45504ae

Browse files
tvanrijnbaev
authored andcommitted
add support for latest phpunit versions (fixes allure-framework#36, via allure-framework#37)
1 parent 4ffd514 commit 45504ae

File tree

4 files changed

+74
-57
lines changed

4 files changed

+74
-57
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ In order to use this adapter you need to add a new dependency to your **composer
3131
```
3232
{
3333
"require": {
34-
"php": ">=5.4.0",
34+
"php": ">=7.0.0",
3535
"allure-framework/allure-phpunit": "~1.2.0"
3636
}
3737
}
@@ -62,13 +62,13 @@ In order to add such title to any test class or [test case](https://github.com/a
6262
```php
6363
namespace Example\Tests;
6464

65-
use PHPUnit_Framework_TestCase;
65+
use PHPUnit\Framework\TestCase;
6666
use Yandex\Allure\Adapter\Annotation\Title;
6767

6868
/**
6969
* @Title("Human-readable test class title")
7070
*/
71-
class SomeTest extends PHPUnit_Framework_TestCase
71+
class SomeTest extends TestCase
7272
{
7373
/**
7474
* @Title("Human-readable test method title")
@@ -85,14 +85,14 @@ Similarly you can add detailed description for each test class and [test method]
8585
```php
8686
namespace Example\Tests;
8787

88-
use PHPUnit_Framework_TestCase;
88+
use PHPUnit\Framework\TestCase;
8989
use Yandex\Allure\Adapter\Annotation\Description;
9090
use Yandex\Allure\Adapter\Model\DescriptionType;
9191

9292
/**
9393
* @Description("Detailed description for test class")
9494
*/
95-
class SomeTest extends PHPUnit_Framework_TestCase
95+
class SomeTest extends TestCase
9696
{
9797
/**
9898
* @Description(value = "Detailed description for <b>test class</b>.", type = DescriptionType::HTML)
@@ -110,11 +110,11 @@ Description can be added in plain text, HTML or Markdown format - simply assign
110110
```php
111111
namespace Example\Tests;
112112

113-
use PHPUnit_Framework_TestCase;
113+
use PHPUnit\Framework\TestCase;
114114
use Yandex\Allure\Adapter\Annotation\Severity;
115115
use Yandex\Allure\Adapter\Model\SeverityLevel;
116116

117-
class SomeTest extends PHPUnit_Framework_TestCase
117+
class SomeTest extends TestCase
118118
{
119119
/**
120120
* @Severity(level = SeverityLevel::MINOR)
@@ -131,11 +131,11 @@ In order to add information about test method [parameters](https://github.com/al
131131
```php
132132
namespace Example\Tests;
133133

134-
use PHPUnit_Framework_TestCase;
134+
use PHPUnit\Framework\TestCase;
135135
use Yandex\Allure\Adapter\Annotation\Parameter;
136136
use Yandex\Allure\Adapter\Model\ParameterKind;
137137

138-
class SomeTest extends PHPUnit_Framework_TestCase
138+
class SomeTest extends TestCase
139139
{
140140
/**
141141
* @Parameter(name = "param1", value = "value1")
@@ -153,15 +153,15 @@ In some development approaches tests are classified by [stories](https://github.
153153
```php
154154
namespace Example\Tests;
155155

156-
use PHPUnit_Framework_TestCase;
156+
use PHPUnit\Framework\TestCase;
157157
use Yandex\Allure\Adapter\Annotation\Features;
158158
use Yandex\Allure\Adapter\Annotation\Stories;
159159

160160
/**
161161
* @Stories({"story1", "story2"})
162162
* @Features({"feature1", "feature2", "feature3"})
163163
*/
164-
class SomeTest extends PHPUnit_Framework_TestCase
164+
class SomeTest extends TestCase
165165
{
166166
/**
167167
* @Features({"feature2"})
@@ -180,10 +180,10 @@ If you wish to [attach some files](https://github.com/allure-framework/allure-co
180180
```php
181181
namespace Example\Tests;
182182

183-
use PHPUnit_Framework_TestCase;
183+
use PHPUnit\Framework\TestCase;
184184
use Yandex\Allure\Adapter\Support\AttachmentSupport;
185185

186-
class SomeTest extends PHPUnit_Framework_TestCase
186+
class SomeTest extends TestCase
187187
{
188188

189189
use AttachmentSupport;
@@ -212,10 +212,10 @@ Allure framework also supports very useful feature called [steps](https://github
212212
```php
213213
namespace Example\Tests;
214214

215-
use PHPUnit_Framework_TestCase;
215+
use PHPUnit\Framework\TestCase;
216216
use Yandex\Allure\Adapter\Support\StepSupport;
217217

218-
class SomeTest extends PHPUnit_Framework_TestCase
218+
class SomeTest extends TestCase
219219
{
220220

221221
use StepSupport;

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"source": "https://github.com/allure-framework/allure-phpunit"
1717
},
1818
"require": {
19-
"php": ">=5.4.0",
20-
"phpunit/phpunit": ">=4.0.0",
19+
"php": ">=7.0.0",
20+
"phpunit/phpunit": ">=6.0.0",
2121
"mikey179/vfsStream": "1.*",
2222
"allure-framework/allure-php-api": "~1.1.0"
2323
},

src/Yandex/Allure/Adapter/AllureAdapter.php

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
namespace Yandex\Allure\Adapter;
44

55
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;
1114
use Yandex\Allure\Adapter\Annotation;
1215
use Yandex\Allure\Adapter\Event\TestCaseBrokenEvent;
1316
use Yandex\Allure\Adapter\Event\TestCaseCanceledEvent;
@@ -19,7 +22,7 @@
1922
use Yandex\Allure\Adapter\Event\TestSuiteStartedEvent;
2023
use 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
}

test/Yandex/Allure/Adapter/AllureAdapterTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Yandex\Allure\Adapter;
44

5-
5+
use PHPUnit\Framework\AssertionFailedError;
6+
use PHPUnit\Framework\TestCase;
7+
use PHPUnit\Framework\TestSuite;
68
use Exception;
79
use org\bovigo\vfs\vfsStream;
810
use Yandex\Allure\Adapter\Event\TestCaseBrokenEvent;
@@ -15,7 +17,7 @@
1517
const ROOT_DIRECTORY = 'test-root-directory';
1618
const TEST_DIRECTORY = 'test-directory';
1719

18-
class AllureAdapterTest extends \PHPUnit_Framework_TestCase
20+
class AllureAdapterTest extends TestCase
1921
{
2022

2123
/**
@@ -62,7 +64,7 @@ public function testAddError()
6264

6365
public function testAddFailure()
6466
{
65-
$exception = new \PHPUnit_Framework_AssertionFailedError(EXCEPTION_MESSAGE);
67+
$exception = new AssertionFailedError(EXCEPTION_MESSAGE);
6668
$time = $this->getTime();
6769
$this->getAllureAdapter()->addFailure($this, $exception, $time);
6870
$events = $this->getMockedLifecycle()->getEvents();
@@ -170,7 +172,7 @@ private function getTime()
170172

171173
private function getTestSuite()
172174
{
173-
return new \PHPUnit_Framework_TestSuite(__CLASS__);
175+
return new TestSuite(__CLASS__);
174176
}
175177

176-
}
178+
}

0 commit comments

Comments
 (0)