Skip to content

Commit 8f0031b

Browse files
committed
wip
1 parent 1a11d1f commit 8f0031b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

console-tests.md

+26
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
# Console Tests
22

33
- [Introduction](#introduction)
4+
- [Success / Failure Expectations](#success-failure-expectations)
45
- [Input / Output Expectations](#input-output-expectations)
56

67
<a name="introduction"></a>
78
## Introduction
89

910
In addition to simplifying HTTP testing, Laravel provides a simple API for testing your application's [custom console commands](/docs/{{version}}/artisan).
1011

12+
<a name="success-failure-expectations"></a>
13+
## Success / Failure Expectations
14+
15+
To get started, let's explore how to make assertions regarding an Artisan command's exit code. To accomplish this, we will use the `artisan` method to invoke an Artisan command from our test. Then, we will use the `assertExitCode` method to assert that the command completed with a given exit code:
16+
17+
/**
18+
* Test a console command.
19+
*
20+
* @return void
21+
*/
22+
public function test_console_command()
23+
{
24+
$this->artisan('inspire')->assertExitCode(0);
25+
}
26+
27+
You may use the `assertNotExitCode` method to assert that the command did not exit with a given exit code:
28+
29+
$this->artisan('inspire')->assertNotExitCode(1);
30+
31+
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:
32+
33+
$this->artisan('inspire')->assertSuccessful();
34+
35+
$this->artisan('inspire')->assertFailed();
36+
1137
<a name="input-output-expectations"></a>
1238
## Input / Output Expectations
1339

0 commit comments

Comments
 (0)