Skip to content

Commit 097ebc3

Browse files
[12.x] Add prompts tests (#10643)
* Add prompts tests * Update prompts.md --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 0dce9eb commit 097ebc3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

prompts.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [Clearing the Terminal](#clear)
2323
- [Terminal Considerations](#terminal-considerations)
2424
- [Unsupported Environments and Fallbacks](#fallbacks)
25+
- [Testing](#testing)
2526

2627
<a name="introduction"></a>
2728
## Introduction
@@ -1001,3 +1002,49 @@ TextPrompt::fallbackUsing(function (TextPrompt $prompt) use ($input, $output) {
10011002
```
10021003

10031004
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

Comments
 (0)