Skip to content

Commit a270dbf

Browse files
bug #35716 [PhpUnitBridge] Fix compatibility to PHPUnit 9 (Benjamin)
This PR was merged into the 4.4 branch. Discussion ---------- [PhpUnitBridge] Fix compatibility to PHPUnit 9 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #35662 | License | MIT | Doc PR | - Adding the possibility to use PHPUnit 9. Commits ------- 771c642a43 [PhpUnitBridge] Add compatibility to PHPUnit 9 #35662
2 parents 6631ffe + 4375f79 commit a270dbf

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

Legacy/CommandForV9.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\TextUI\Command as BaseCommand;
15+
use PHPUnit\TextUI\Configuration\Configuration;
16+
use PHPUnit\TextUI\Configuration\Registry;
17+
use PHPUnit\TextUI\TestRunner as BaseRunner;
18+
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
19+
20+
/**
21+
* {@inheritdoc}
22+
*
23+
* @internal
24+
*/
25+
class CommandForV9 extends BaseCommand
26+
{
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protected function createRunner(): BaseRunner
31+
{
32+
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : [];
33+
34+
$registeredLocally = false;
35+
36+
foreach ($this->arguments['listeners'] as $registeredListener) {
37+
if ($registeredListener instanceof SymfonyTestsListener) {
38+
$registeredListener->globalListenerDisabled();
39+
$registeredLocally = true;
40+
break;
41+
}
42+
}
43+
44+
if (isset($this->arguments['configuration'])) {
45+
$configuration = $this->arguments['configuration'];
46+
if (!$configuration instanceof Configuration) {
47+
$configuration = Registry::getInstance()->get($this->arguments['configuration']);
48+
}
49+
foreach ($configuration->listeners() as $registeredListener) {
50+
if ('Symfony\Bridge\PhpUnit\SymfonyTestsListener' === ltrim($registeredListener->className(), '\\')) {
51+
$registeredLocally = true;
52+
break;
53+
}
54+
}
55+
}
56+
57+
if (!$registeredLocally) {
58+
$this->arguments['listeners'][] = new SymfonyTestsListener();
59+
}
60+
61+
return parent::createRunner();
62+
}
63+
}

TextUI/Command.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
if (version_compare(\PHPUnit\Runner\Version::id(), '6.0.0', '<')) {
1515
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV5', 'Symfony\Bridge\PhpUnit\TextUI\Command');
16-
} else {
16+
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '9.0.0', '<')) {
1717
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV6', 'Symfony\Bridge\PhpUnit\TextUI\Command');
18+
} else {
19+
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV9', 'Symfony\Bridge\PhpUnit\TextUI\Command');
1820
}
1921

2022
if (false) {

0 commit comments

Comments
 (0)