Check phpunit configuration for listeners
The bridge 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
This commit is contained in:
parent
1f7250139f
commit
b190536205
@ -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