Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Ask about markdown template for notification command with no initial input #52355

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Illuminate/Foundation/Console/NotificationMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
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\confirm;
use function Laravel\Prompts\text;

#[AsCommand(name: 'make:notification')]
class NotificationMakeCommand extends GeneratorCommand
Expand Down Expand Up @@ -122,6 +126,27 @@ protected function getDefaultNamespace($rootNamespace)
return $rootNamespace.'\Notifications';
}

/**
* Perform actions after the user was 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;
}

$wantsMarkdownView = confirm('Would you like to create a markdown view?');

if ($wantsMarkdownView) {
$markdownView = text('What should the markdown view be named?', 'E.g. invoice-paid');
$input->setOption('markdown', $markdownView);
}
}

/**
* Get the console command options.
*
Expand Down
23 changes: 23 additions & 0 deletions tests/Integration/Generators/NotificationMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,27 @@ public function testItCanGenerateNotificationFileWithTest()
$this->assertFilenameNotExists('resources/views/foo-notification.blade.php');
$this->assertFilenameExists('tests/Feature/Notifications/FooNotificationTest.php');
}

public function testItCanGenerateNotificationFileWithNotInitialInput()
{
$this->artisan('make:notification')
->expectsQuestion('What should the notification be named?', 'FooNotification')
->expectsQuestion('Would you like to create a markdown view?', false)
->assertExitCode(0);

$this->assertFilenameExists('app/Notifications/FooNotification.php');
$this->assertFileDoesNotExist('resources/views/foo-notification.blade.php');
}

public function testItCanGenerateNotificationFileWithMarkdownTemplateWithNotInitialInput()
{
$this->artisan('make:notification')
->expectsQuestion('What should the notification be named?', 'FooNotification')
->expectsQuestion('Would you like to create a markdown view?', true)
->expectsQuestion('What should the markdown view be named?', 'foo-notification')
->assertExitCode(0);

$this->assertFilenameExists('app/Notifications/FooNotification.php');
$this->assertFilenameExists('resources/views/foo-notification.blade.php');
}
}