Skip to content

Commit 3b6c7ad

Browse files
authored
Adds "PendingCommand::assertOk()" (#43968)
1 parent 6c18db4 commit 3b6c7ad

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Illuminate/Testing/PendingCommand.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ public function assertSuccessful()
249249
return $this->assertExitCode(Command::SUCCESS);
250250
}
251251

252+
/**
253+
* Assert that the command has the success exit code.
254+
*
255+
* @return $this
256+
*/
257+
public function assertOk()
258+
{
259+
return $this->assertSuccessful();
260+
}
261+
252262
/**
253263
* Assert that the command does not have the success exit code.
254264
*

tests/Integration/Testing/ArtisanCommandTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,27 @@ protected function setUp(): void
3333
$this->line($this->ask('Huh?'));
3434
});
3535

36+
Artisan::command('exit {code}', fn () => (int) $this->argument('code'));
37+
3638
Artisan::command('contains', function () {
3739
$this->line('My name is Taylor Otwell');
3840
});
3941
}
4042

4143
public function test_console_command_that_passes()
44+
{
45+
$this->artisan('exit', ['code' => 0])->assertOk();
46+
}
47+
48+
public function test_console_command_that_fails()
49+
{
50+
$this->expectException(AssertionFailedError::class);
51+
$this->expectExceptionMessage('Expected status code 0 but received 1.');
52+
53+
$this->artisan('exit', ['code' => 1])->assertOk();
54+
}
55+
56+
public function test_console_command_that_passes_with_output()
4257
{
4358
$this->artisan('survey')
4459
->expectsQuestion('What is your name?', 'Taylor Otwell')

0 commit comments

Comments
 (0)