CommandForV6.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\PhpUnit\Legacy;
  11. use PHPUnit\TextUI\Command as BaseCommand;
  12. use PHPUnit\TextUI\TestRunner as BaseRunner;
  13. use PHPUnit\Util\Configuration;
  14. use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
  15. /**
  16. * {@inheritdoc}
  17. *
  18. * @internal
  19. */
  20. class CommandForV6 extends BaseCommand
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. protected function createRunner(): BaseRunner
  26. {
  27. $this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : [];
  28. $registeredLocally = false;
  29. foreach ($this->arguments['listeners'] as $registeredListener) {
  30. if ($registeredListener instanceof SymfonyTestsListener) {
  31. $registeredListener->globalListenerDisabled();
  32. $registeredLocally = true;
  33. break;
  34. }
  35. }
  36. if (isset($this->arguments['configuration'])) {
  37. $configuration = $this->arguments['configuration'];
  38. if (!$configuration instanceof Configuration) {
  39. $configuration = Configuration::getInstance($this->arguments['configuration']);
  40. }
  41. foreach ($configuration->getListenerConfiguration() as $registeredListener) {
  42. if ('Symfony\Bridge\PhpUnit\SymfonyTestsListener' === ltrim($registeredListener['class'], '\\')) {
  43. $registeredLocally = true;
  44. break;
  45. }
  46. }
  47. }
  48. if (!$registeredLocally) {
  49. $this->arguments['listeners'][] = new SymfonyTestsListener();
  50. }
  51. return parent::createRunner();
  52. }
  53. }