From 016be5ef99ca71a5c410e894a77de57dfa5324c5 Mon Sep 17 00:00:00 2001 From: Christoph Rumpel Date: Mon, 8 Jul 2024 14:25:50 +0200 Subject: [PATCH 1/4] Add prompts for mail views when no options are provided --- .../Foundation/Console/MailMakeCommand.php | 20 +++++++++++ .../Generators/ViewMakeCommandTest.php | 34 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/Illuminate/Foundation/Console/MailMakeCommand.php b/src/Illuminate/Foundation/Console/MailMakeCommand.php index 2941dccd9375..98e72b004352 100644 --- a/src/Illuminate/Foundation/Console/MailMakeCommand.php +++ b/src/Illuminate/Foundation/Console/MailMakeCommand.php @@ -7,7 +7,10 @@ use Illuminate\Foundation\Inspiring; use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use function Laravel\Prompts\select; #[AsCommand(name: 'make:mail')] class MailMakeCommand extends GeneratorCommand @@ -193,4 +196,21 @@ protected function getOptions() ['view', null, InputOption::VALUE_OPTIONAL, 'Create a new Blade template for the mailable', false], ]; } + + protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) + { + if ($this->didReceiveOptions($input)) { + return; + } + + $type = select('Would you like to create a view for you mailable?', [ + 'markdown' => 'Markdown View', + 'view' => 'Empty View', + 'none' => 'No View', + ]); + + if ($type !== 'none') { + $input->setOption($type, null); + } + } } diff --git a/tests/Integration/Generators/ViewMakeCommandTest.php b/tests/Integration/Generators/ViewMakeCommandTest.php index 202bc15656ab..fe5d08e52985 100644 --- a/tests/Integration/Generators/ViewMakeCommandTest.php +++ b/tests/Integration/Generators/ViewMakeCommandTest.php @@ -26,4 +26,38 @@ public function testItCanGenerateViewFileWithTest() $this->assertFilenameExists('resources/views/foo.blade.php'); $this->assertFilenameExists('tests/Feature/View/FooTest.php'); } + + public function testItCanGenerateMailWithNoInitialInput() + { + $this->artisan('make:mail') + ->expectsQuestion('What should the mailable be named?','FooMail') + ->expectsQuestion('Would you like a view for you mailable?','none') + ->assertExitCode(0); + + $this->assertFilenameExists('app/Mail/FooMail.php'); + $this->assertFilenameDoesNotExists('resources/views/mail/foo-mail.blade.php'); + } + + public function testItCanGenerateMailWithViewWithNoInitialInput() + { + $this->artisan('make:mail') + ->expectsQuestion('What should the mailable be named?','MyFooMail') + ->expectsQuestion('Would you like a view for you mailable?','view') + ->assertExitCode(0); + + $this->assertFilenameExists('app/Mail/MyFooMail.php'); + $this->assertFilenameExists('resources/views/mail/my-foo-mail.blade.php'); + } + + public function testItCanGenerateMailWithMarkdownViewWithNoInitialInput() + { + $this->artisan('make:mail') + + ->expectsQuestion('What should the mailable be named?','FooMail') + ->expectsQuestion('Would you like a view for you mailable?','markdown') + ->assertExitCode(0); + + $this->assertFilenameExists('app/Mail/MyFooMail.php'); + $this->assertFilenameExists('resources/views/mail/my-foo-mail.blade.php'); + } } From 86355b1fc8551401a524e63a21ed1745c377c3b8 Mon Sep 17 00:00:00 2001 From: Christoph Rumpel Date: Mon, 8 Jul 2024 15:49:40 +0200 Subject: [PATCH 2/4] Fix test by using correct working --- tests/Integration/Generators/ViewMakeCommandTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Generators/ViewMakeCommandTest.php b/tests/Integration/Generators/ViewMakeCommandTest.php index fe5d08e52985..b84afbce4cbb 100644 --- a/tests/Integration/Generators/ViewMakeCommandTest.php +++ b/tests/Integration/Generators/ViewMakeCommandTest.php @@ -31,7 +31,7 @@ public function testItCanGenerateMailWithNoInitialInput() { $this->artisan('make:mail') ->expectsQuestion('What should the mailable be named?','FooMail') - ->expectsQuestion('Would you like a view for you mailable?','none') + ->expectsQuestion('Would you like to create a view for you mailable?','none') ->assertExitCode(0); $this->assertFilenameExists('app/Mail/FooMail.php'); @@ -42,7 +42,7 @@ public function testItCanGenerateMailWithViewWithNoInitialInput() { $this->artisan('make:mail') ->expectsQuestion('What should the mailable be named?','MyFooMail') - ->expectsQuestion('Would you like a view for you mailable?','view') + ->expectsQuestion('Would you like to create a view for you mailable?','view') ->assertExitCode(0); $this->assertFilenameExists('app/Mail/MyFooMail.php'); @@ -54,7 +54,7 @@ public function testItCanGenerateMailWithMarkdownViewWithNoInitialInput() $this->artisan('make:mail') ->expectsQuestion('What should the mailable be named?','FooMail') - ->expectsQuestion('Would you like a view for you mailable?','markdown') + ->expectsQuestion('Would you like to create a view for you mailable?','markdown') ->assertExitCode(0); $this->assertFilenameExists('app/Mail/MyFooMail.php'); From d8d690f0fc4d4a2dacff2bd7e551668fa1c7126f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Jul 2024 10:24:49 -0500 Subject: [PATCH 3/4] formatting --- src/Illuminate/Foundation/Console/MailMakeCommand.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/MailMakeCommand.php b/src/Illuminate/Foundation/Console/MailMakeCommand.php index 98e72b004352..6cca4e3cd49f 100644 --- a/src/Illuminate/Foundation/Console/MailMakeCommand.php +++ b/src/Illuminate/Foundation/Console/MailMakeCommand.php @@ -197,13 +197,20 @@ protected function getOptions() ]; } + /** + * Interact further with the user if they were prompted for missing arguments. + * + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @return void + */ protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) { if ($this->didReceiveOptions($input)) { return; } - $type = select('Would you like to create a view for you mailable?', [ + $type = select('Would you like to create a view?', [ 'markdown' => 'Markdown View', 'view' => 'Empty View', 'none' => 'No View', From 86ac8340c0329eece4dcedc594bc83040545a73a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Jul 2024 10:25:31 -0500 Subject: [PATCH 4/4] fix tests --- tests/Integration/Generators/ViewMakeCommandTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Generators/ViewMakeCommandTest.php b/tests/Integration/Generators/ViewMakeCommandTest.php index b84afbce4cbb..6aed7ff3fb19 100644 --- a/tests/Integration/Generators/ViewMakeCommandTest.php +++ b/tests/Integration/Generators/ViewMakeCommandTest.php @@ -31,7 +31,7 @@ public function testItCanGenerateMailWithNoInitialInput() { $this->artisan('make:mail') ->expectsQuestion('What should the mailable be named?','FooMail') - ->expectsQuestion('Would you like to create a view for you mailable?','none') + ->expectsQuestion('Would you like to create a view?','none') ->assertExitCode(0); $this->assertFilenameExists('app/Mail/FooMail.php'); @@ -42,7 +42,7 @@ public function testItCanGenerateMailWithViewWithNoInitialInput() { $this->artisan('make:mail') ->expectsQuestion('What should the mailable be named?','MyFooMail') - ->expectsQuestion('Would you like to create a view for you mailable?','view') + ->expectsQuestion('Would you like to create a view?','view') ->assertExitCode(0); $this->assertFilenameExists('app/Mail/MyFooMail.php'); @@ -54,7 +54,7 @@ public function testItCanGenerateMailWithMarkdownViewWithNoInitialInput() $this->artisan('make:mail') ->expectsQuestion('What should the mailable be named?','FooMail') - ->expectsQuestion('Would you like to create a view for you mailable?','markdown') + ->expectsQuestion('Would you like to create a view?','markdown') ->assertExitCode(0); $this->assertFilenameExists('app/Mail/MyFooMail.php');