CommandForV9.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Configuration\Configuration as LegacyConfiguration;
  13. use PHPUnit\TextUI\Configuration\Registry;
  14. use PHPUnit\TextUI\TestRunner as BaseRunner;
  15. use PHPUnit\TextUI\XmlConfiguration\Configuration;
  16. use PHPUnit\TextUI\XmlConfiguration\Loader;
  17. use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
  18. /**
  19. * {@inheritdoc}
  20. *
  21. * @internal
  22. */
  23. class CommandForV9 extends BaseCommand
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function createRunner(): BaseRunner
  29. {
  30. $this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : [];
  31. $registeredLocally = false;
  32. foreach ($this->arguments['listeners'] as $registeredListener) {
  33. if ($registeredListener instanceof SymfonyTestsListener) {
  34. $registeredListener->globalListenerDisabled();
  35. $registeredLocally = true;
  36. break;
  37. }
  38. }
  39. if (isset($this->arguments['configuration'])) {
  40. $configuration = $this->arguments['configuration'];
  41. if (!class_exists(Configuration::class) && !$configuration instanceof LegacyConfiguration) {
  42. $configuration = Registry::getInstance()->get($this->arguments['configuration']);
  43. } elseif (class_exists(Configuration::class) && !$configuration instanceof Configuration) {
  44. $configuration = (new Loader())->load($this->arguments['configuration']);
  45. }
  46. foreach ($configuration->listeners() as $registeredListener) {
  47. if ('Symfony\Bridge\PhpUnit\SymfonyTestsListener' === ltrim($registeredListener->className(), '\\')) {
  48. $registeredLocally = true;
  49. break;
  50. }
  51. }
  52. }
  53. if (!$registeredLocally) {
  54. $this->arguments['listeners'][] = new SymfonyTestsListener();
  55. }
  56. return parent::createRunner();
  57. }
  58. }