From 3525c65f2f1c5c9a0b61751253fa0c7d75d847c4 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Wed, 21 Feb 2024 08:22:34 -0500 Subject: [PATCH] bug #1458 [make:entity] fix require mercure before asking to broadcast entity updates --- src/Maker/MakeEntity.php | 10 +++++----- tests/Maker/MakeEntityTest.php | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index a4a620d2c..01e228f40 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -141,15 +141,15 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma && class_exists(Broadcast::class) && !class_exists($this->generator->createClassNameDetails($entityClassName, 'Entity\\')->getFullName()) ) { - // Mercure is needed - if (!class_exists(MercureExtension::class)) { - throw new RuntimeCommandException('Please run "composer require symfony/mercure". It is needed to broadcast entities.'); - } - $description = $command->getDefinition()->getOption('broadcast')->getDescription(); $question = new ConfirmationQuestion($description, false); $isBroadcast = $io->askQuestion($question); + // Mercure is needed + if ($isBroadcast && !class_exists(MercureExtension::class)) { + throw new RuntimeCommandException('Please run "composer require symfony/mercure". It is needed to broadcast entities.'); + } + $input->setOption('broadcast', $isBroadcast); } } diff --git a/tests/Maker/MakeEntityTest.php b/tests/Maker/MakeEntityTest.php index f96b43398..7ee5c3e5a 100644 --- a/tests/Maker/MakeEntityTest.php +++ b/tests/Maker/MakeEntityTest.php @@ -600,6 +600,22 @@ public function getTestDetails(): \Generator $this->runEntityTest($runner); }), ]; + + yield 'it_generates_entity_with_turbo_without_mercure' => [$this->createMakeEntityTest() + ->preRun(function (MakerTestRunner $runner) { + $runner->runProcess('composer require symfony/ux-turbo'); + }) + ->addExtraDependencies('twig') + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + 'User', // entity class + 'n', // no broadcast + '', + ]); + + $this->assertFileExists($runner->getPath('src/Entity/User.php')); + }), + ]; } private function runEntityTest(MakerTestRunner $runner, array $data = []): void