-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[12.x] use fenced code blocks (#10172)
* use fenced code blocks - better syntax highlighting - easier copy/pasting of code examples - consistency throughout docs block * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
- Loading branch information
Showing
78 changed files
with
25,389 additions
and
18,768 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,30 +33,36 @@ public function test_console_command(): void | |
|
||
You may use the `assertNotExitCode` method to assert that the command did not exit with a given exit code: | ||
|
||
$this->artisan('inspire')->assertNotExitCode(1); | ||
```php | ||
$this->artisan('inspire')->assertNotExitCode(1); | ||
``` | ||
|
||
Of course, all terminal commands typically exit with a status code of `0` when they are successful and a non-zero exit code when they are not successful. Therefore, for convenience, you may utilize the `assertSuccessful` and `assertFailed` assertions to assert that a given command exited with a successful exit code or not: | ||
|
||
$this->artisan('inspire')->assertSuccessful(); | ||
```php | ||
$this->artisan('inspire')->assertSuccessful(); | ||
|
||
$this->artisan('inspire')->assertFailed(); | ||
$this->artisan('inspire')->assertFailed(); | ||
``` | ||
|
||
<a name="input-output-expectations"></a> | ||
## Input / Output Expectations | ||
|
||
Laravel allows you to easily "mock" user input for your console commands using the `expectsQuestion` method. In addition, you may specify the exit code and text that you expect to be output by the console command using the `assertExitCode` and `expectsOutput` methods. For example, consider the following console command: | ||
|
||
Artisan::command('question', function () { | ||
$name = $this->ask('What is your name?'); | ||
```php | ||
Artisan::command('question', function () { | ||
$name = $this->ask('What is your name?'); | ||
|
||
$language = $this->choice('Which language do you prefer?', [ | ||
'PHP', | ||
'Ruby', | ||
'Python', | ||
]); | ||
$language = $this->choice('Which language do you prefer?', [ | ||
'PHP', | ||
'Ruby', | ||
'Python', | ||
]); | ||
|
||
$this->line('Your name is '.$name.' and you prefer '.$language.'.'); | ||
}); | ||
$this->line('Your name is '.$name.' and you prefer '.$language.'.'); | ||
}); | ||
``` | ||
|
||
You may test this command with the following test: | ||
|
||
|
@@ -165,23 +171,27 @@ public function test_console_command(): void | |
|
||
When writing a command which expects confirmation in the form of a "yes" or "no" answer, you may utilize the `expectsConfirmation` method: | ||
|
||
$this->artisan('module:import') | ||
->expectsConfirmation('Do you really wish to run this command?', 'no') | ||
->assertExitCode(1); | ||
```php | ||
$this->artisan('module:import') | ||
->expectsConfirmation('Do you really wish to run this command?', 'no') | ||
->assertExitCode(1); | ||
``` | ||
|
||
<a name="table-expectations"></a> | ||
#### Table Expectations | ||
|
||
If your command displays a table of information using Artisan's `table` method, it can be cumbersome to write output expectations for the entire table. Instead, you may use the `expectsTable` method. This method accepts the table's headers as its first argument and the table's data as its second argument: | ||
|
||
$this->artisan('users:all') | ||
->expectsTable([ | ||
'ID', | ||
'Email', | ||
], [ | ||
[1, '[email protected]'], | ||
[2, '[email protected]'], | ||
]); | ||
```php | ||
$this->artisan('users:all') | ||
->expectsTable([ | ||
'ID', | ||
'Email', | ||
], [ | ||
[1, '[email protected]'], | ||
[2, '[email protected]'], | ||
]); | ||
``` | ||
|
||
<a name="console-events"></a> | ||
## Console Events | ||
|
Oops, something went wrong.