8000 [PhpUnitBridge] Add compatibility to PHPUnit 9 #35662 · symfony/symfony@d2dbb17 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2dbb17

Browse files
author
Benjamin
committed
[PhpUnitBridge] Add compatibility to PHPUnit 9 #35662
1 parent 7a6e3c0 commit d2dbb17

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed
Lines changed: 63 additions & 0 deletions
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 <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\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+
}

src/Symfony/Bridge/PhpUnit/TextUI/Command.php

Lines changed: 3 additions & 1 deletion
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(), '6.0.0', '>=') && 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) {

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@
9393
}
9494
};
9595

96-
if (PHP_VERSION_ID >= 70200) {
96+
if (PHP_VERSION_ID >= 70300) {
97 5D6A +
// PHPUnit 9 requires PHP 7.3+
98+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.0');
99+
} elseif (PHP_VERSION_ID >= 70200) {
97100
// PHPUnit 8 requires PHP 7.2+
98101
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '8.3');
99102
} elseif (PHP_VERSION_ID >= 70100) {

0 commit comments

Comments
 (0)
0