Skip to content

Commit b4a46a3

Browse files
committed
Fix Artisan output assertions for zero values
1 parent 5c5c1f3 commit b4a46a3

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/Illuminate/Testing/PendingCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,11 @@ protected function verifyExpectations()
532532
$this->test->fail('Output does not contain "'.Arr::first($this->test->expectedOutputSubstrings).'".');
533533
}
534534

535-
if ($output = array_search(true, $this->test->unexpectedOutput)) {
535+
if (($output = array_search(true, $this->test->unexpectedOutput)) !== false) {
536536
$this->test->fail('Output "'.$output.'" was printed.');
537537
}
538538

539-
if ($output = array_search(true, $this->test->unexpectedOutputSubstrings)) {
539+
if (($output = array_search(true, $this->test->unexpectedOutputSubstrings)) !== false) {
540540
$this->test->fail('Output "'.$output.'" was printed.');
541541
}
542542
}

tests/Integration/Testing/ArtisanCommandTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ protected function setUp(): void
5656
$this->line('My name is Taylor Otwell');
5757
});
5858

59+
Artisan::command('zero', function () {
60+
$this->line('0');
61+
});
62+
5963
Artisan::command('new-england', function () {
6064
$this->line('The region of New England consists of the following states:');
6165
$this->info('Connecticut');
@@ -125,6 +129,26 @@ public function test_console_command_that_fails_from_unexpected_output_substring
125129
->assertExitCode(0);
126130
}
127131

132+
public function test_console_command_that_fails_from_zero_as_unexpected_output()
133+
{
134+
$this->expectException(AssertionFailedError::class);
135+
$this->expectExceptionMessage('Output "0" was printed.');
136+
137+
$this->artisan('zero')
138+
->doesntExpectOutput('0')
139+
->assertExitCode(0);
140+
}
141+
142+
public function test_console_command_that_fails_from_zero_as_unexpected_output_substring()
143+
{
144+
$this->expectException(AssertionFailedError::class);
145+
$this->expectExceptionMessage('Output "0" was printed.');
146+
147+
$this->artisan('zero')
148+
->doesntExpectOutputToContain('0')
149+
->assertExitCode(0);
150+
}
151+
128152
public function test_console_command_that_fails_from_missing_output()
129153
{
130154
$this->expectException(AssertionFailedError::class);

0 commit comments

Comments
 (0)