Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 5c20742

Browse files
committed
Fix test listeners for PHPUnit 7
1 parent 72ffbff commit 5c20742

File tree

3 files changed

+75
-52
lines changed

3 files changed

+75
-52
lines changed

dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Listener.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,26 @@
66
namespace Magento\TestFramework\ErrorLog;
77

88
use Magento\TestFramework\Helper;
9+
use PHPUnit\Framework\AssertionFailedError;
10+
use PHPUnit\Framework\Test;
11+
use PHPUnit\Framework\TestCase;
12+
use PHPUnit\Framework\TestListener;
13+
use PHPUnit\Framework\TestSuite;
14+
use PHPUnit\Framework\Warning;
915

10-
class Listener implements \PHPUnit\Framework\TestListener
16+
class Listener implements TestListener
1117
{
18+
/**
19+
* @var Logger|null
20+
*/
21+
private $logger;
22+
1223
/**
1324
* {@inheritdoc}
1425
* @SuppressWarnings(PHPMD.ShortVariable)
1526
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
1627
*/
17-
public function addError(\PHPUnit\Framework\Test $test, \Exception $e, $time)
28+
public function addError(Test $test, \Throwable $e, float $time): void
1829
{
1930
}
2031

@@ -23,7 +34,7 @@ public function addError(\PHPUnit\Framework\Test $test, \Exception $e, $time)
2334
* @SuppressWarnings(PHPMD.ShortVariable)
2435
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2536
*/
26-
public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, $time)
37+
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
2738
{
2839
}
2940

@@ -32,7 +43,7 @@ public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Ass
3243
* @SuppressWarnings(PHPMD.ShortVariable)
3344
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3445
*/
35-
public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
46+
public function addIncompleteTest(Test $test, \Throwable $e, float $time): void
3647
{
3748
}
3849

@@ -41,7 +52,7 @@ public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Exception $e,
4152
* @SuppressWarnings(PHPMD.ShortVariable)
4253
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4354
*/
44-
public function addRiskyTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
55+
public function addRiskyTest(Test $test, \Throwable $e, float $time): void
4556
{
4657
}
4758

@@ -50,40 +61,40 @@ public function addRiskyTest(\PHPUnit\Framework\Test $test, \Exception $e, $time
5061
* @SuppressWarnings(PHPMD.ShortVariable)
5162
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5263
*/
53-
public function addSkippedTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
64+
public function addSkippedTest(Test $test, \Throwable $e, float $time): void
5465
{
5566
}
5667

5768
/**
5869
* {@inheritdoc}
5970
*/
60-
public function startTestSuite(\PHPUnit\Framework\TestSuite $suite)
71+
public function startTestSuite(TestSuite $suite): void
6172
{
6273
}
6374

6475
/**
6576
* {@inheritdoc}
6677
*/
67-
public function endTestSuite(\PHPUnit\Framework\TestSuite $suite)
78+
public function endTestSuite(TestSuite $suite): void
6879
{
6980
}
7081

7182
/**
7283
* {@inheritdoc}
7384
*/
74-
public function startTest(\PHPUnit\Framework\Test $test)
85+
public function startTest(Test $test): void
7586
{
76-
$this->logger = Helper\Bootstrap::getObjectManager()->get(\Magento\TestFramework\ErrorLog\Logger::class);
87+
$this->logger = Helper\Bootstrap::getObjectManager()->get(Logger::class);
7788
$this->logger->clearMessages();
7889
}
7990

8091
/**
8192
* {@inheritdoc}
8293
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
8394
*/
84-
public function endTest(\PHPUnit\Framework\Test $test, $time)
95+
public function endTest(Test $test, float $time): void
8596
{
86-
if ($test instanceof \PHPUnit\Framework\TestCase) {
97+
if ($test instanceof TestCase) {
8798
$messages = $this->logger->getMessages();
8899
try {
89100
if ($messages) {
@@ -102,7 +113,7 @@ public function endTest(\PHPUnit\Framework\Test $test, $time)
102113
/**
103114
* {@inheritdoc}
104115
*/
105-
public function addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, $time)
116+
public function addWarning(Test $test, Warning $e, float $time): void
106117
{
107118
}
108119
}

dev/tests/integration/framework/Magento/TestFramework/Listener/ExtededTestdox.php

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
*/
66
namespace Magento\TestFramework\Listener;
77

8-
class ExtededTestdox extends \PHPUnit_Util_Printer implements \PHPUnit\Framework\TestListener
8+
use PHPUnit\Framework\AssertionFailedError;
9+
use PHPUnit\Framework\Test;
10+
use PHPUnit\Framework\TestCase;
11+
use PHPUnit\Framework\TestListener;
12+
use PHPUnit\Framework\TestSuite;
13+
use PHPUnit\Runner\BaseTestRunner;
14+
use PHPUnit\Util\Printer;
15+
use PHPUnit\Util\TestDox\NamePrettifier;
16+
17+
class ExtededTestdox extends Printer implements TestListener
918
{
1019
/**
11-
* @var \PHPUnit_Util_TestDox_NamePrettifier
20+
* @var NamePrettifier
1221
*/
1322
protected $prettifier;
1423

@@ -55,7 +64,7 @@ class ExtededTestdox extends \PHPUnit_Util_Printer implements \PHPUnit\Framework
5564
/**
5665
* @var \stdClass
5766
*/
58-
protected $testTypeOfInterest = \PHPUnit\Framework\TestCase::class;
67+
protected $testTypeOfInterest = TestCase::class;
5968

6069
/**
6170
* @var string
@@ -76,7 +85,7 @@ public function __construct($out = null)
7685
{
7786
parent::__construct($out);
7887

79-
$this->prettifier = new \PHPUnit_Util_TestDox_NamePrettifier();
88+
$this->prettifier = new NamePrettifier();
8089
$this->startRun();
8190
}
8291

@@ -95,113 +104,113 @@ public function flush()
95104
/**
96105
* An error occurred.
97106
*
98-
* @param \PHPUnit\Framework\Test $test
107+
* @param Test $test
99108
* @param \Exception $e
100109
* @param float $time
101110
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
102111
*/
103-
public function addError(\PHPUnit\Framework\Test $test, \Exception $e, $time)
112+
public function addError(Test $test, \Throwable $e, float $time): void
104113
{
105114
if ($test instanceof $this->testTypeOfInterest) {
106-
$this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_ERROR;
115+
$this->testStatus = BaseTestRunner::STATUS_ERROR;
107116
$this->failed++;
108117
}
109118
}
110119

111120
/**
112121
* A failure occurred.
113122
*
114-
* @param \PHPUnit\Framework\Test $test
115-
* @param \PHPUnit\Framework\AssertionFailedError $e
123+
* @param Test $test
124+
* @param AssertionFailedError $e
116125
* @param float $time
117126
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
118127
*/
119-
public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, $time)
128+
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
120129
{
121130
if ($test instanceof $this->testTypeOfInterest) {
122-
$this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE;
131+
$this->testStatus = BaseTestRunner::STATUS_FAILURE;
123132
$this->failed++;
124133
}
125134
}
126135

127136
/**
128137
* Incomplete test.
129138
*
130-
* @param \PHPUnit\Framework\Test $test
139+
* @param Test $test
131140
* @param \Exception $e
132141
* @param float $time
133142
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
134143
*/
135-
public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
144+
public function addIncompleteTest(Test $test, \Throwable $e, float $time): void
136145
{
137146
if ($test instanceof $this->testTypeOfInterest) {
138-
$this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE;
147+
$this->testStatus = BaseTestRunner::STATUS_INCOMPLETE;
139148
$this->incomplete++;
140149
}
141150
}
142151

143152
/**
144153
* Skipped test.
145154
*
146-
* @param \PHPUnit\Framework\Test $test
155+
* @param Test $test
147156
* @param \Exception $e
148157
* @param float $time
149158
* @since Method available since Release 3.0.0
150159
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
151160
*/
152-
public function addSkippedTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
161+
public function addSkippedTest(Test $test, \Throwable $e, float $time): void
153162
{
154163
if ($test instanceof $this->testTypeOfInterest) {
155-
$this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED;
164+
$this->testStatus = BaseTestRunner::STATUS_SKIPPED;
156165
$this->skipped++;
157166
}
158167
}
159168

160169
/**
161170
* Risky test.
162171
*
163-
* @param \PHPUnit\Framework\Test $test
172+
* @param Test $test
164173
* @param \Exception $e
165174
* @param float $time
166175
* @since Method available since Release 4.0.0
167176
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
168177
*/
169-
public function addRiskyTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
178+
public function addRiskyTest(Test $test, \Throwable $e, float $time): void
170179
{
171180
if ($test instanceof $this->testTypeOfInterest) {
172-
$this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_RISKY;
181+
$this->testStatus = BaseTestRunner::STATUS_RISKY;
173182
$this->risky++;
174183
}
175184
}
176185

177186
/**
178187
* A testsuite started.
179188
*
180-
* @param \PHPUnit\Framework\TestSuite $suite
189+
* @param TestSuite $suite
181190
* @since Method available since Release 2.2.0
182191
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
183192
*/
184-
public function startTestSuite(\PHPUnit\Framework\TestSuite $suite)
193+
public function startTestSuite(TestSuite $suite): void
185194
{
186195
}
187196

188197
/**
189198
* A testsuite ended.
190199
*
191-
* @param \PHPUnit\Framework\TestSuite $suite
200+
* @param TestSuite $suite
192201
* @since Method available since Release 2.2.0
193202
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
194203
*/
195-
public function endTestSuite(\PHPUnit\Framework\TestSuite $suite)
204+
public function endTestSuite(TestSuite $suite): void
196205
{
197206
}
198207

199208
/**
200209
* A test started.
201210
*
202-
* @param \PHPUnit\Framework\Test $test
211+
* @param Test $test
203212
*/
204-
public function startTest(\PHPUnit\Framework\Test $test)
213+
public function startTest(Test $test): void
205214
{
206215
if ($test instanceof $this->testTypeOfInterest) {
207216
$class = get_class($test);
@@ -220,30 +229,30 @@ public function startTest(\PHPUnit\Framework\Test $test)
220229
$this->write('.');
221230
$this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(false));
222231

223-
$this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
232+
$this->testStatus = BaseTestRunner::STATUS_PASSED;
224233
}
225234
}
226235

227236
/**
228237
* A test ended.
229238
*
230-
* @param \PHPUnit\Framework\Test $test
239+
* @param Test $test
231240
* @param float $time
232241
*/
233-
public function endTest(\PHPUnit\Framework\Test $test, $time)
242+
public function endTest(Test $test, float $time): void
234243
{
235244
if ($test instanceof $this->testTypeOfInterest) {
236245
if (!isset($this->tests[$this->currentTestMethodPrettified])) {
237246
$this->tests[$this->currentTestMethodPrettified] = ['success' => 0, 'failure' => 0, 'time' => 0];
238247
}
239248

240-
if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
249+
if ($this->testStatus == BaseTestRunner::STATUS_PASSED) {
241250
$this->tests[$this->currentTestMethodPrettified]['success']++;
242251
}
243-
if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_ERROR) {
252+
if ($this->testStatus == BaseTestRunner::STATUS_ERROR) {
244253
$this->tests[$this->currentTestMethodPrettified]['failure']++;
245254
}
246-
if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
255+
if ($this->testStatus == BaseTestRunner::STATUS_FAILURE) {
247256
$this->tests[$this->currentTestMethodPrettified]['failure']++;
248257
}
249258
$this->tests[$this->currentTestMethodPrettified]['time'] += $time;
@@ -256,15 +265,15 @@ public function endTest(\PHPUnit\Framework\Test $test, $time)
256265
* Handler for 'start run' event.
257266
*
258267
*/
259-
protected function startRun()
268+
protected function startRun(): void
260269
{
261270
}
262271

263272
/**
264273
* Handler for 'end run' event.
265274
*
266275
*/
267-
protected function endRun()
276+
protected function endRun(): void
268277
{
269278
}
270279

@@ -274,7 +283,7 @@ protected function endRun()
274283
* @param string $name
275284
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
276285
*/
277-
protected function startClass($name)
286+
protected function startClass($name): void
278287
{
279288
$this->write($this->currentTestClassPrettified . ' ');
280289
}
@@ -285,15 +294,15 @@ protected function startClass($name)
285294
* @param string $name
286295
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
287296
*/
288-
protected function endClass($name)
297+
protected function endClass($name): void
289298
{
290299
$this->write("\n");
291300
}
292301

293302
/**
294303
* @since Method available since Release 2.3.0
295304
*/
296-
protected function doEndClass()
305+
protected function doEndClass(): void
297306
{
298307
foreach ($this->tests as $name => $data) {
299308
$check = $data['failure'] == 0 ? ' - [x] ' : ' - [ ] ';

lib/internal/Magento/Framework/TestFramework/Unit/Listener/ReplaceObjectManager.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77

88
use Magento\Framework\App\ObjectManager;
99
use Magento\Framework\ObjectManagerInterface;
10+
use PHPUnit\Framework\TestListener;
11+
use PHPUnit\Framework\TestListenerDefaultImplementation;
1012

1113
/**
1214
* The event listener which instantiates ObjectManager before test run
1315
*/
14-
class ReplaceObjectManager extends \PHPUnit\Framework\BaseTestListener
16+
class ReplaceObjectManager implements TestListener
1517
{
18+
use TestListenerDefaultImplementation;
1619
/**
1720
* Replaces ObjectManager before run for each test
1821
*
@@ -25,7 +28,7 @@ class ReplaceObjectManager extends \PHPUnit\Framework\BaseTestListener
2528
* @return void
2629
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2730
*/
28-
public function startTest(\PHPUnit\Framework\Test $test)
31+
public function startTest(\PHPUnit\Framework\Test $test): void
2932
{
3033
if ($test instanceof \PHPUnit\Framework\TestCase) {
3134
$objectManagerMock = $test->getMockBuilder(ObjectManagerInterface::class)

0 commit comments

Comments
 (0)