Skip to content

Commit 20030a5

Browse files
[11.x] Ask About View Next To Name For Create Mail Command (#52057)
* Add prompts for mail views when no options are provided * Fix test by using correct working * formatting * fix tests --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 2f1f330 commit 20030a5

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/Illuminate/Foundation/Console/MailMakeCommand.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
use Illuminate\Foundation\Inspiring;
88
use Illuminate\Support\Str;
99
use Symfony\Component\Console\Attribute\AsCommand;
10+
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Input\InputOption;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
use function Laravel\Prompts\select;
1114

1215
#[AsCommand(name: 'make:mail')]
1316
class MailMakeCommand extends GeneratorCommand
@@ -193,4 +196,28 @@ protected function getOptions()
193196
['view', null, InputOption::VALUE_OPTIONAL, 'Create a new Blade template for the mailable', false],
194197
];
195198
}
199+
200+
/**
201+
* Interact further with the user if they were prompted for missing arguments.
202+
*
203+
* @param \Symfony\Component\Console\Input\InputInterface $input
204+
* @param \Symfony\Component\Console\Output\OutputInterface $output
205+
* @return void
206+
*/
207+
protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output)
208+
{
209+
if ($this->didReceiveOptions($input)) {
210+
return;
211+
}
212+
213+
$type = select('Would you like to create a view?', [
214+
'markdown' => 'Markdown View',
215+
'view' => 'Empty View',
216+
'none' => 'No View',
217+
]);
218+
219+
if ($type !== 'none') {
220+
$input->setOption($type, null);
221+
}
222+
}
196223
}

tests/Integration/Generators/ViewMakeCommandTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,38 @@ public function testItCanGenerateViewFileWithTest()
2626
$this->assertFilenameExists('resources/views/foo.blade.php');
2727
$this->assertFilenameExists('tests/Feature/View/FooTest.php');
2828
}
29+
30+
public function testItCanGenerateMailWithNoInitialInput()
31+
{
32+
$this->artisan('make:mail')
33+
->expectsQuestion('What should the mailable be named?','FooMail')
34+
->expectsQuestion('Would you like to create a view?','none')
35+
->assertExitCode(0);
36+
37+
$this->assertFilenameExists('app/Mail/FooMail.php');
38+
$this->assertFilenameDoesNotExists('resources/views/mail/foo-mail.blade.php');
39+
}
40+
41+
public function testItCanGenerateMailWithViewWithNoInitialInput()
42+
{
43+
$this->artisan('make:mail')
44+
->expectsQuestion('What should the mailable be named?','MyFooMail')
45+
->expectsQuestion('Would you like to create a view?','view')
46+
->assertExitCode(0);
47+
48+
$this->assertFilenameExists('app/Mail/MyFooMail.php');
49+
$this->assertFilenameExists('resources/views/mail/my-foo-mail.blade.php');
50+
}
51+
52+
public function testItCanGenerateMailWithMarkdownViewWithNoInitialInput()
53+
{
54+
$this->artisan('make:mail')
55+
56+
->expectsQuestion('What should the mailable be named?','FooMail')
57+
->expectsQuestion('Would you like to create a view?','markdown')
58+
->assertExitCode(0);
59+
60+
$this->assertFilenameExists('app/Mail/MyFooMail.php');
61+
$this->assertFilenameExists('resources/views/mail/my-foo-mail.blade.php');
62+
}
2963
}

0 commit comments

Comments
 (0)