From 5a5218fe2d57dbfc54eeb6e9d2d50e92f6a12ae1 Mon Sep 17 00:00:00 2001 From: "SUMIDA, Ippei" Date: Mon, 1 Jul 2024 20:09:22 +0900 Subject: [PATCH] [make:entity] create id as a UUID type when class name is specified as an argument --- src/Maker/MakeEntity.php | 3 +-- tests/Maker/MakeEntityTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index 1774ffc35..0b58038f2 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -123,8 +123,6 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma return; } - $this->checkIsUsingUid($input); - $argument = $command->getDefinition()->getArgument('name'); $question = $this->createEntityClassQuestion($argument->getDescription()); $entityClassName ??= $io->askQuestion($question); @@ -171,6 +169,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void { + $this->checkIsUsingUid($input); $overwrite = $input->getOption('overwrite'); // the regenerate option has entirely custom behavior diff --git a/tests/Maker/MakeEntityTest.php b/tests/Maker/MakeEntityTest.php index c8826274f..2c10b2f4e 100644 --- a/tests/Maker/MakeEntityTest.php +++ b/tests/Maker/MakeEntityTest.php @@ -161,6 +161,24 @@ public function getTestDetails(): \Generator }), ]; + yield 'it_creates_a_new_class_with_uuid_and_class_name' => [$this->createMakeEntityTest() + ->addExtraDependencies('symfony/uid') + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + // add not additional fields + '', + ], 'User --with-uuid'); + + $this->assertFileExists($runner->getPath('src/Entity/User.php')); + + $content = file_get_contents($runner->getPath('src/Entity/User.php')); + $this->assertStringContainsString('use Symfony\Component\Uid\Uuid;', $content); + $this->assertStringContainsString('[ORM\CustomIdGenerator(class: \'doctrine.uuid_generator\')]', $content); + + $this->runEntityTest($runner); + }), + ]; + yield 'it_creates_a_new_class_with_ulid' => [$this->createMakeEntityTest() ->addExtraDependencies('symfony/uid') ->run(function (MakerTestRunner $runner) {