bug #32903 [PHPUnit Bridge] Avoid registering listener twice (alexpott)
This PR was merged into the 3.4 branch.
Discussion
----------
[PHPUnit Bridge] Avoid registering listener twice
The listener can be registered via configuration by the user. In that
case, we do not want to add it again to the list of listeners.
Closes #31649
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Commits
-------
b190536205
Check phpunit configuration for listeners
This commit is contained in:
commit
726999d015
@ -23,8 +23,6 @@ class CommandForV5 extends \PHPUnit_TextUI_Command
|
||||
*/
|
||||
protected function createRunner()
|
||||
{
|
||||
$listener = new SymfonyTestsListenerForV5();
|
||||
|
||||
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : array();
|
||||
|
||||
$registeredLocally = false;
|
||||
@ -37,8 +35,21 @@ class CommandForV5 extends \PHPUnit_TextUI_Command
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->arguments['configuration'])) {
|
||||
$configuration = $this->arguments['configuration'];
|
||||
if (!$configuration instanceof \PHPUnit_Util_Configuration) {
|
||||
$configuration = \PHPUnit_Util_Configuration::getInstance($this->arguments['configuration']);
|
||||
}
|
||||
foreach ($configuration->getListenerConfiguration() as $registeredListener) {
|
||||
if ('Symfony\Bridge\PhpUnit\SymfonyTestsListener' === ltrim($registeredListener['class'], '\\')) {
|
||||
$registeredLocally = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$registeredLocally) {
|
||||
$this->arguments['listeners'][] = $listener;
|
||||
$this->arguments['listeners'][] = new SymfonyTestsListenerForV5();
|
||||
}
|
||||
|
||||
return parent::createRunner();
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Bridge\PhpUnit\Legacy;
|
||||
|
||||
use PHPUnit\TextUI\Command as BaseCommand;
|
||||
use PHPUnit\TextUI\TestRunner as BaseRunner;
|
||||
use PHPUnit\Util\Configuration;
|
||||
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
|
||||
|
||||
/**
|
||||
@ -27,8 +28,6 @@ class CommandForV6 extends BaseCommand
|
||||
*/
|
||||
protected function createRunner(): BaseRunner
|
||||
{
|
||||
$listener = new SymfonyTestsListener();
|
||||
|
||||
$this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : [];
|
||||
|
||||
$registeredLocally = false;
|
||||
@ -41,8 +40,21 @@ class CommandForV6 extends BaseCommand
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->arguments['configuration'])) {
|
||||
$configuration = $this->arguments['configuration'];
|
||||
if (!$configuration instanceof Configuration) {
|
||||
$configuration = Configuration::getInstance($this->arguments['configuration']);
|
||||
}
|
||||
foreach ($configuration->getListenerConfiguration() as $registeredListener) {
|
||||
if ('Symfony\Bridge\PhpUnit\SymfonyTestsListener' === ltrim($registeredListener['class'], '\\')) {
|
||||
$registeredLocally = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$registeredLocally) {
|
||||
$this->arguments['listeners'][] = $listener;
|
||||
$this->arguments['listeners'][] = new SymfonyTestsListener();
|
||||
}
|
||||
|
||||
return parent::createRunner();
|
||||
|
Reference in New Issue
Block a user