Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 771c642

Browse filesBrowse files
author
Benjamin
committed
[PhpUnitBridge] Add compatibility to PHPUnit 9 #35662
1 parent 12f1c7c commit 771c642
Copy full SHA for 771c642

File tree

2 files changed

+66
-1
lines changed
Filter options

2 files changed

+66
-1
lines changed
+63Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/PhpUnit/TextUI/Command.php
+3-1Lines 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(), '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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.