Skip to content

Commit 97000d8

Browse files
author
Douglas Greenshields
committed
[PhpBridge] use progressive enhancement to keep compatibility with PHP 5 in SymfonyTestsListener
1 parent c2f62ef commit 97000d8

File tree

3 files changed

+74
-74
lines changed

3 files changed

+74
-74
lines changed

src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerPhpunit6.php

-57
This file was deleted.

src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php

+14-17
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111

1212
namespace Symfony\Bridge\PhpUnit;
1313

14+
use PHPUnit\Framework\BaseTestListener;
1415
use PHPUnit\Framework\Test;
15-
use PHPUnit\Framework\TestListener;
16-
use PHPUnit\Framework\TestListenerDefaultImplementation;
1716
use PHPUnit\Framework\TestSuite;
1817
use PHPUnit\Framework\Warning;
1918

2019
// Using an early return instead of a else does not work when using the PHPUnit phar due to some weird PHP behavior (the class
2120
// gets defined without executing the code before it and so the definition is not properly conditional)
2221
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
2322
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');
23+
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '>=')) {
24+
class_alias('Symfony\Bridge\PhpUnit\SymfonyTestsListenerWithReturnTypes', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
2625
} else {
2726
/**
2827
* Collects and replays skipped tests.
@@ -31,10 +30,8 @@ class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerPhpunit6', 'Symfo
3130
*
3231
* @final
3332
*/
34-
class SymfonyTestsListener implements TestListener
33+
class SymfonyTestsListener extends BaseTestListener
3534
{
36-
use TestListenerDefaultImplementation;
37-
3835
private $trait;
3936

4037
public function __construct(array $mockedNamespaces = array())
@@ -47,29 +44,29 @@ public function globalListenerDisabled()
4744
$this->trait->globalListenerDisabled();
4845
}
4946

50-
public function startTestSuite(TestSuite $suite): void
47+
public function startTestSuite(TestSuite $suite)
5148
{
52-
$this->trait->startTestSuite($suite);
49+
return $this->trait->startTestSuite($suite);
5350
}
5451

55-
public function addSkippedTest(Test $test, \Throwable $t, float $time): void
52+
public function addSkippedTest(Test $test, \Exception $e, $time)
5653
{
57-
$this->trait->addSkippedTest($test, $t, $time);
54+
return $this->trait->addSkippedTest($test, $e, $time);
5855
}
5956

60-
public function startTest(Test $test): void
57+
public function startTest(Test $test)
6158
{
62-
$this->trait->startTest($test);
59+
return $this->trait->startTest($test);
6360
}
6461

65-
public function addWarning(Test $test, Warning $e, float $time): void
62+
public function addWarning(Test $test, Warning $e, $time)
6663
{
67-
$this->trait->addWarning($test, $e, $time);
64+
return $this->trait->addWarning($test, $e, $time);
6865
}
6966

70-
public function endTest(Test $test, float $time): void
67+
public function endTest(Test $test, $time)
7168
{
72-
$this->trait->endTest($test, $time);
69+
return $this->trait->endTest($test, $time);
7370
}
7471
}
7572
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\PhpUnit;
4+
5+
use PHPUnit\Framework\Test;
6+
use PHPUnit\Framework\TestListener;
7+
use PHPUnit\Framework\TestListenerDefaultImplementation;
8+
use PHPUnit\Framework\TestSuite;
9+
use PHPUnit\Framework\Warning;
10+
11+
/**
12+
* Collects and replays skipped tests.
13+
*
14+
* (Version of SymfonyTestsListener for PHPUnit 7+, and PHP 7.1+.)
15+
*
16+
* @author Nicolas Grekas <p@tchwork.com>
17+
*
18+
* @final
19+
*/
20+
class SymfonyTestsListenerWithReturnTypes
21+
{
22+
use TestListenerDefaultImplementation;
23+
24+
private $trait;
25+
26+
public function __construct(array $mockedNamespaces = array())
27+
{
28+
$this->trait = new Legacy\SymfonyTestsListenerTrait($mockedNamespaces);
29+
}
30+
31+
public function globalListenerDisabled()
32+
{
33+
$this->trait->globalListenerDisabled();
34+
}
35+
36+
public function startTestSuite(TestSuite $suite): void
37+
{
38+
$this->trait->startTestSuite($suite);
39+
}
40+
41+
public function addSkippedTest(Test $test, \Throwable $t, float $time): void
42+
{
43+
$this->trait->addSkippedTest($test, $t, $time);
44+
}
45+
46+
public function startTest(Test $test): void
47+
{
48+
$this->trait->startTest($test);
49+
}
50+
51+
public function addWarning(Test $test, Warning $e, float $time): void
52+
{
53+
$this->trait->addWarning($test, $e, $time);
54+
}
55+
56+
public function endTest(Test $test, float $time): void
57+
{
58+
$this->trait->endTest($test, $time);
59+
}
60+
}

0 commit comments

Comments
 (0)