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
Changes from 1 commit
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
Next Next commit
[11.x] Ask about markdown template for notification command
  • Loading branch information
christophrumpel committed Aug 1, 2024
commit 6e5055346f4f9481408265722102f43a53b9daa5
19 changes: 19 additions & 0 deletions src/Illuminate/Foundation/Console/NotificationMakeCommand.php
Original file line number Diff line number Diff line change
@@ -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
@@ -134,4 +138,19 @@ protected function getOptions()
['markdown', 'm', InputOption::VALUE_OPTIONAL, 'Create a new Markdown template for the notification'],
];
}

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);
}
}

}
23 changes: 23 additions & 0 deletions tests/Integration/Generators/NotificationMakeCommandTest.php
Original file line number Diff line number Diff line change
@@ -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?', 'ExportFinishedNotification')
->expectsQuestion('Would you like to create a markdown view?', false)
->assertExitCode(0);

$this->assertFilenameExists('app/Notifications/ExportFinishedNotification.php');
$this->assertFileDoesNotExist('resources/views/export.blade.php');
}

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

$this->assertFilenameExists('app/Notifications/ExportFinishedNotification.php');
$this->assertFilenameExists('resources/views/export.blade.php');
}
}
Loading
Oops, something went wrong.