Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Illuminate/Testing/PendingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ public function assertSuccessful()
return $this->assertExitCode(Command::SUCCESS);
}

/**
* Assert that the command has the success exit code.
*
* @return $this
*/
public function assertOk()
{
return $this->assertSuccessful();
}

/**
* Assert that the command does not have the success exit code.
*
Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/Testing/ArtisanCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,27 @@ protected function setUp(): void
$this->line($this->ask('Huh?'));
});

Artisan::command('exit {code}', fn () => (int) $this->argument('code'));

Artisan::command('contains', function () {
$this->line('My name is Taylor Otwell');
});
}

public function test_console_command_that_passes()
{
$this->artisan('exit', ['code' => 0])->assertOk();
}

public function test_console_command_that_fails()
{
$this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage('Expected status code 0 but received 1.');

$this->artisan('exit', ['code' => 1])->assertOk();
}

public function test_console_command_that_passes_with_output()
{
$this->artisan('survey')
->expectsQuestion('What is your name?', 'Taylor Otwell')
Expand Down