Skip to content

Commit 3525c65

Browse files
authored
bug #1458 [make:entity] fix require mercure before asking to broadcast entity updates
1 parent d344744 commit 3525c65

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/Maker/MakeEntity.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
141141
&& class_exists(Broadcast::class)
142142
&& !class_exists($this->generator->createClassNameDetails($entityClassName, 'Entity\\')->getFullName())
143143
) {
144-
// Mercure is needed
145-
if (!class_exists(MercureExtension::class)) {
146-
throw new RuntimeCommandException('Please run "composer require symfony/mercure". It is needed to broadcast entities.');
147-
}
148-
149144
$description = $command->getDefinition()->getOption('broadcast')->getDescription();
150145
$question = new ConfirmationQuestion($description, false);
151146
$isBroadcast = $io->askQuestion($question);
152147

148+
// Mercure is needed
149+
if ($isBroadcast && !class_exists(MercureExtension::class)) {
150+
throw new RuntimeCommandException('Please run "composer require symfony/mercure". It is needed to broadcast entities.');
151+
}
152+
153153
$input->setOption('broadcast', $isBroadcast);
154154
}
155155
}

tests/Maker/MakeEntityTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,22 @@ public function getTestDetails(): \Generator
600600
$this->runEntityTest($runner);
601601
}),
602602
];
603+
604+
yield 'it_generates_entity_with_turbo_without_mercure' => [$this->createMakeEntityTest()
605+
->preRun(function (MakerTestRunner $runner) {
606+
$runner->runProcess('composer require symfony/ux-turbo');
607+
})
608+
->addExtraDependencies('twig')
609+
->run(function (MakerTestRunner $runner) {
610+
$runner->runMaker([
611+
'User', // entity class
612+
'n', // no broadcast
613+
'',
614+
]);
615+
616+
$this->assertFileExists($runner->getPath('src/Entity/User.php'));
617+
}),
618+
];
603619
}
604620

605621
private function runEntityTest(MakerTestRunner $runner, array $data = []): void

0 commit comments

Comments
 (0)