Skip to content

Commit 6616894

Browse files
committed
wip
1 parent 7107cc9 commit 6616894

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

console-tests.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Laravel allows you to easily "mock" user input for your console commands using t
5858
$this->line('Your name is '.$name.' and you prefer '.$language.'.');
5959
});
6060

61-
You may test this command with the following test which utilizes the `expectsQuestion`, `expectsOutput`, `doesntExpectOutput`, `expectsOutputToContain`, `doesntExpectOutputToContain`, and `assertExitCode` methods:
61+
You may test this command with the following test:
6262

6363
```php tab=Pest
6464
test('console command', function () {
@@ -67,8 +67,6 @@ test('console command', function () {
6767
->expectsQuestion('Which language do you prefer?', 'PHP')
6868
->expectsOutput('Your name is Taylor Otwell and you prefer PHP.')
6969
->doesntExpectOutput('Your name is Taylor Otwell and you prefer Ruby.')
70-
->expectsOutputToContain('Taylor Otwell')
71-
->doesntExpectOutputToContain('you prefer Ruby')
7270
->assertExitCode(0);
7371
});
7472
```
@@ -84,8 +82,6 @@ public function test_console_command(): void
8482
->expectsQuestion('Which language do you prefer?', 'PHP')
8583
->expectsOutput('Your name is Taylor Otwell and you prefer PHP.')
8684
->doesntExpectOutput('Your name is Taylor Otwell and you prefer Ruby.')
87-
->expectsOutputToContain('Taylor Otwell')
88-
->doesntExpectOutputToContain('you prefer Ruby')
8985
->assertExitCode(0);
9086
}
9187
```
@@ -110,6 +106,28 @@ public function test_console_command(): void
110106
->doesntExpectOutput()
111107
->assertExitCode(0);
112108
}
109+
```
110+
111+
The `expectsOutputToContain` and `doesntExpectOutputToContain` methods may be used to make assertions against a portion of the output:
112+
113+
```php tab=Pest
114+
test('console command', function () {
115+
$this->artisan('example')
116+
->expectsOutputToContain('Taylor')
117+
->assertExitCode(0);
118+
});
119+
```
120+
121+
```php tab=PHPUnit
122+
/**
123+
* Test a console command.
124+
*/
125+
public function test_console_command(): void
126+
{
127+
$this->artisan('example')
128+
->expectsOutputToContain('Taylor')
129+
->assertExitCode(0);
130+
}
113131
```
114132

115133
<a name="confirmation-expectations"></a>

0 commit comments

Comments
 (0)