diff --git a/composer.json b/composer.json index 2b12605ad..2033ee462 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,7 @@ "laminas/laminas-stdlib": "^3.13.0", "laminas/laminas-validator": "^2.25.0", "psr/container": "^1.1.2", - "symfony/console": "^5.4.16 || ^6.2.1" + "symfony/console": "^6.2.1 || ^7.0.0" }, "require-dev": { "doctrine/coding-standard": "^12.0.0", diff --git a/tests/Service/CliFactoryTest.php b/tests/Service/CliFactoryTest.php new file mode 100644 index 000000000..f2db80d62 --- /dev/null +++ b/tests/Service/CliFactoryTest.php @@ -0,0 +1,58 @@ +setService('config', []); + $serviceManager->setService('EventManager', new EventManager()); + + $factory = new CliFactory(); + $app = $factory->__invoke($serviceManager, 'doctrine.cli'); + + $this->assertInstanceOf(Application::class, $app); + } + + public function testRegistrationOfCustomCliCommand(): void + { + $serviceManager = new ServiceManager(); + $eventManager = new EventManager(); + + $eventManager->attach( + 'loadCli.post', + static function (EventInterface $event): void { + $target = $event->getTarget(); + if (! ($target instanceof Application)) { + return; + } + + $target->add(new DummyCliCommand()); + }, + ); + + $serviceManager->setService('config', []); + $serviceManager->setService('EventManager', $eventManager); + + $factory = new CliFactory(); + $app = $factory->__invoke($serviceManager, 'doctrine.cli'); + + $this->assertInstanceOf(Application::class, $app); + $this->assertTrue($app->has('app:dummy-command')); + } +} diff --git a/tests/Service/TestAsset/DummyCliCommand.php b/tests/Service/TestAsset/DummyCliCommand.php new file mode 100644 index 000000000..1c1ac2482 --- /dev/null +++ b/tests/Service/TestAsset/DummyCliCommand.php @@ -0,0 +1,30 @@ +setName('app:dummy-command') + ->setDescription('A dummy command for testing purposes.'); + } + + public function execute(InputInterface $input, OutputInterface $output): int + { + $output->writeln([ + 'Dummy Command', + '=============', + '', + ]); + + return Command::SUCCESS; + } +}