|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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 | +} |
0 commit comments