Skip to content

Commit c2f62ef

Browse files
author
Douglas Greenshields
committed
[PhpBridge] add PHPUnit 7 support to SymfonyTestsListener
1 parent a48849e commit c2f62ef

File tree

2 files changed

+76
-14
lines changed

2 files changed

+76
-14
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Legacy;
13+
14+
use PHPUnit\Framework\BaseTestListener;
15+
use PHPUnit\Framework\Test;
16+
use PHPUnit\Framework\TestSuite;
17+
use PHPUnit\Framework\Warning;
18+
19+
class SymfonyTestsListenerPhpunit6 extends BaseTestListener
20+
{
21+
private $trait;
22+
23+
public function __construct(array $mockedNamespaces = array())
24+
{
25+
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
26+
}
27+
28+
public function globalListenerDisabled()
29+
{
30+
$this->trait->globalListenerDisabled();
31+
}
32+
33+
public function startTestSuite(TestSuite $suite)
34+
{
35+
$this->trait->startTestSuite($suite);
36+
}
37+
38+
public function addSkippedTest(Test $test, \Exception $e, $time)
39+
{
40+
$this->trait->addSkippedTest($test, $e, $time);
41+
}
42+
43+
public function startTest(Test $test)
44+
{
45+
$this->trait->startTest($test);
46+
}
47+
48+
public function addWarning(Test $test, Warning $e, $time)
49+
{
50+
$this->trait->addWarning($test, $e, $time);
51+
}
52+
53+
public function endTest(Test $test, $time)
54+
{
55+
$this->trait->endTest($test, $time);
56+
}
57+
}

src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111

1212
namespace Symfony\Bridge\PhpUnit;
1313

14-
use PHPUnit\Framework\BaseTestListener;
1514
use PHPUnit\Framework\Test;
15+
use PHPUnit\Framework\TestListener;
16+
use PHPUnit\Framework\TestListenerDefaultImplementation;
1617
use PHPUnit\Framework\TestSuite;
1718
use PHPUnit\Framework\Warning;
1819

19-
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
20-
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
2120
// Using an early return instead of a else does not work when using the PHPUnit phar due to some weird PHP behavior (the class
2221
// gets defined without executing the code before it and so the definition is not properly conditional)
22+
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
23+
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
24+
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) {
25+
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerPhpunit6', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
2326
} else {
2427
/**
2528
* Collects and replays skipped tests.
@@ -28,8 +31,10 @@ class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener', 'Symfony\Bridg
2831
*
2932
* @final
3033
*/
31-
class SymfonyTestsListener extends BaseTestListener
34+
class SymfonyTestsListener implements TestListener
3235
{
36+
use TestListenerDefaultImplementation;
37+
3338
private $trait;
3439

3540
public function __construct(array $mockedNamespaces = array())
@@ -42,29 +47,29 @@ public function globalListenerDisabled()
4247
$this->trait->globalListenerDisabled();
4348
}
4449

45-
public function startTestSuite(TestSuite $suite)
50+
public function startTestSuite(TestSuite $suite): void
4651
{
47-
return $this->trait->startTestSuite($suite);
52+
$this->trait->startTestSuite($suite);
4853
}
4954

50-
public function addSkippedTest(Test $test, \Exception $e, $time)
55+
public function addSkippedTest(Test $test, \Throwable $t, float $time): void
5156
{
52-
return $this->trait->addSkippedTest($test, $e, $time);
57+
$this->trait->addSkippedTest($test, $t, $time);
5358
}
5459

55-
public function startTest(Test $test)
60+
public function startTest(Test $test): void
5661
{
57-
return $this->trait->startTest($test);
62+
$this->trait->startTest($test);
5863
}
5964

60-
public function addWarning(Test $test, Warning $e, $time)
65+
public function addWarning(Test $test, Warning $e, float $time): void
6166
{
62-
return $this->trait->addWarning($test, $e, $time);
67+
$this->trait->addWarning($test, $e, $time);
6368
}
6469

65-
public function endTest(Test $test, $time)
70+
public function endTest(Test $test, float $time): void
6671
{
67-
return $this->trait->endTest($test, $time);
72+
$this->trait->endTest($test, $time);
6873
}
6974
}
7075
}

0 commit comments

Comments
 (0)