diff --git a/src/Maker/Common/CanGenerateTestsTrait.php b/src/Maker/Common/CanGenerateTestsTrait.php index aae231704..05b752036 100644 --- a/src/Maker/Common/CanGenerateTestsTrait.php +++ b/src/Maker/Common/CanGenerateTestsTrait.php @@ -32,7 +32,7 @@ public function configureCommandWithTestsOption(Command $command): Command $help = $command->getHelp()."\n".$testsHelp; $command - ->addOption(name: 'with-tests', mode: InputOption::VALUE_NONE, description: 'Generate PHPUnit Tests') + ->addOption(name: 'with-tests', mode: InputOption::VALUE_NEGATABLE, description: 'Generate PHPUnit Tests') ->setHelp($help) ; @@ -46,11 +46,7 @@ public function interactSetGenerateTests(InputInterface $input, ConsoleStyle $io throw new RuntimeCommandException('Whoops! "--with-tests" option does not exist. Call "addWithTestsOptions()" in the makers "configureCommand().'); } - $this->generateTests = $input->getOption('with-tests'); - - if (!$this->generateTests) { - $this->generateTests = $io->confirm('Do you want to generate PHPUnit tests? [Experimental]', false); - } + $this->generateTests = $input->getOption('with-tests') ?? $io->confirm('Do you want to generate PHPUnit tests? [Experimental]', false); } public function shouldGenerateTests(): bool diff --git a/src/Maker/Security/MakeFormLogin.php b/src/Maker/Security/MakeFormLogin.php index 641c048d9..c282dbb02 100644 --- a/src/Maker/Security/MakeFormLogin.php +++ b/src/Maker/Security/MakeFormLogin.php @@ -35,7 +35,9 @@ use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Routing\Attribute\Route; @@ -77,11 +79,12 @@ public static function getCommandName(): string public function configureCommand(Command $command, InputConfiguration $inputConfig): void { - $command - ->setHelp($this->getHelpFileContents('security/MakeFormLogin.txt')) - ; + $command->addArgument('controllerName', InputArgument::OPTIONAL, 'The class name of the Controller (e.g. SecurityController)') + ->addOption('will-logout', null, InputOption::VALUE_NEGATABLE, 'Will generate a \'/logout\' URL? ') + ->setHelp($this->getHelpFileContents('security/MakeFormLogin.txt')); $this->configureCommandWithTestsOption($command); + $inputConfig->setArgumentAsNonInteractive('controllerName'); } public static function getCommandDescription(): string @@ -120,7 +123,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma throw new RuntimeCommandException('To generate a form login authentication, you must configure at least one entry under "providers" in "security.yaml".'); } - $this->controllerName = $io->ask( + $this->controllerName = $input->getArgument('controllerName') ?? $io->ask( 'Choose a name for the controller class (e.g. SecurityController)', 'SecurityController', Validator::validateClassName(...) @@ -130,7 +133,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $this->firewallToUpdate = $securityHelper->guessFirewallName($io, $securityData); $this->userClass = $securityHelper->guessUserClass($io, $securityData['security']['providers']); $this->userNameField = $securityHelper->guessUserNameField($io, $this->userClass, $securityData['security']['providers']); - $this->willLogout = $io->confirm('Do you want to generate a \'/logout\' URL?'); + $this->willLogout = $input->getOption('will-logout') ?? $io->confirm('Do you want to generate a \'/logout\' URL?'); $this->interactSetGenerateTests($input, $io); } @@ -188,7 +191,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen ); $testClassDetails = $generator->createClassNameDetails( - 'LoginControllerTest', + $controllerNameDetails->getShortName().'Test', 'Test\\', );