Skip to content

Commit

Permalink
Adds "PendingCommand::assertOk()" (#43968)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Sep 1, 2022
1 parent 6c18db4 commit 3b6c7ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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

0 comments on commit 3b6c7ad

Please sign in to comment.