Skip to content

Commit

Permalink
bug #1458 [make:entity] fix require mercure before asking to broadcas…
Browse files Browse the repository at this point in the history
…t entity updates
  • Loading branch information
jrushlow authored Feb 21, 2024
1 parent d344744 commit 3525c65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Maker/MakeEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3525c65

Please sign in to comment.