Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 11, 2024
1 parent 7107cc9 commit 6616894
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions console-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Laravel allows you to easily "mock" user input for your console commands using t
$this->line('Your name is '.$name.' and you prefer '.$language.'.');
});

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

```php tab=Pest
test('console command', function () {
Expand All @@ -67,8 +67,6 @@ test('console command', function () {
->expectsQuestion('Which language do you prefer?', 'PHP')
->expectsOutput('Your name is Taylor Otwell and you prefer PHP.')
->doesntExpectOutput('Your name is Taylor Otwell and you prefer Ruby.')
->expectsOutputToContain('Taylor Otwell')
->doesntExpectOutputToContain('you prefer Ruby')
->assertExitCode(0);
});
```
Expand All @@ -84,8 +82,6 @@ public function test_console_command(): void
->expectsQuestion('Which language do you prefer?', 'PHP')
->expectsOutput('Your name is Taylor Otwell and you prefer PHP.')
->doesntExpectOutput('Your name is Taylor Otwell and you prefer Ruby.')
->expectsOutputToContain('Taylor Otwell')
->doesntExpectOutputToContain('you prefer Ruby')
->assertExitCode(0);
}
```
Expand All @@ -110,6 +106,28 @@ public function test_console_command(): void
->doesntExpectOutput()
->assertExitCode(0);
}
```

The `expectsOutputToContain` and `doesntExpectOutputToContain` methods may be used to make assertions against a portion of the output:

```php tab=Pest
test('console command', function () {
$this->artisan('example')
->expectsOutputToContain('Taylor')
->assertExitCode(0);
});
```

```php tab=PHPUnit
/**
* Test a console command.
*/
public function test_console_command(): void
{
$this->artisan('example')
->expectsOutputToContain('Taylor')
->assertExitCode(0);
}
```

<a name="confirmation-expectations"></a>
Expand Down

0 comments on commit 6616894

Please sign in to comment.