|
22 | 22 | - [Clearing the Terminal](#clear)
|
23 | 23 | - [Terminal Considerations](#terminal-considerations)
|
24 | 24 | - [Unsupported Environments and Fallbacks](#fallbacks)
|
| 25 | +- [Testing](#testing) |
25 | 26 |
|
26 | 27 | <a name="introduction"></a>
|
27 | 28 | ## Introduction
|
@@ -1001,3 +1002,49 @@ TextPrompt::fallbackUsing(function (TextPrompt $prompt) use ($input, $output) {
|
1001 | 1002 | ```
|
1002 | 1003 |
|
1003 | 1004 | Fallbacks must be configured individually for each prompt class. The closure will receive an instance of the prompt class and must return an appropriate type for the prompt.
|
| 1005 | + |
| 1006 | +<a name="testing"></a> |
| 1007 | +## Testing |
| 1008 | + |
| 1009 | +Laravel provides a variety of methods for testing that your command displays the expected Prompt messages: |
| 1010 | + |
| 1011 | +```php tab=Pest |
| 1012 | +test('report generation', function () { |
| 1013 | + $this->artisan('report:generate') |
| 1014 | + ->expectsPromptsInfo('Welcome to the application!') |
| 1015 | + ->expectsPromptsWarning('This action cannot be undone') |
| 1016 | + ->expectsPromptsError('Something went wrong') |
| 1017 | + ->expectsPromptsAlert('Important notice!') |
| 1018 | + ->expectsPromptsIntro('Starting process...') |
| 1019 | + ->expectsPromptsOutro('Process completed!') |
| 1020 | + ->expectsPromptsTable( |
| 1021 | + headers: ['Name', 'Email'], |
| 1022 | + rows: [ |
| 1023 | + ['Taylor Otwell', ' [email protected]'], |
| 1024 | + ['Jason Beggs', ' [email protected]'], |
| 1025 | + ] |
| 1026 | + ) |
| 1027 | + ->assertExitCode(0); |
| 1028 | +}); |
| 1029 | +``` |
| 1030 | + |
| 1031 | +```php tab=PHPUnit |
| 1032 | +public function test_report_generation(): void |
| 1033 | +{ |
| 1034 | + $this->artisan('report:generate') |
| 1035 | + ->expectsPromptsInfo('Welcome to the application!') |
| 1036 | + ->expectsPromptsWarning('This action cannot be undone') |
| 1037 | + ->expectsPromptsError('Something went wrong') |
| 1038 | + ->expectsPromptsAlert('Important notice!') |
| 1039 | + ->expectsPromptsIntro('Starting process...') |
| 1040 | + ->expectsPromptsOutro('Process completed!') |
| 1041 | + ->expectsPromptsTable( |
| 1042 | + headers: ['Name', 'Email'], |
| 1043 | + rows: [ |
| 1044 | + ['Taylor Otwell', ' [email protected]'], |
| 1045 | + ['Jason Beggs', ' [email protected]'], |
| 1046 | + ] |
| 1047 | + ) |
| 1048 | + ->assertExitCode(0); |
| 1049 | +} |
| 1050 | +``` |
0 commit comments