Skip to content

Commit

Permalink
Check phpunit configuration for listeners
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexpott authored and greg0ire committed Sep 2, 2019
1 parent 028617b commit c8dd56c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
17 changes: 14 additions & 3 deletions Legacy/CommandForV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,8 +35,21 @@ protected function createRunner()
}
}

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();
Expand Down
18 changes: 15 additions & 3 deletions Legacy/CommandForV6.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\TextUI\Command as BaseCommand;
use PHPUnit\TextUI\TestRunner as BaseRunner;
use PHPUnit\Util\Configuration;
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;

/**
Expand All @@ -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;
Expand All @@ -41,8 +40,21 @@ protected function createRunner(): BaseRunner
}
}

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();
Expand Down

0 comments on commit c8dd56c

Please sign in to comment.