2
votes

I am running a basic artisan command test but phpunit complains that This test did not perform any assertions. But am asserting the exit code.

public function testCommandUsage()
{
   $this->artisan('cmd:test')->assertExitCode(0);
}

This test did not perform any assertions

OK, but incomplete, skipped, or risky tests!

Isn't assertExitCode and assertion?

1
What version of Laravel are you using? - Zoe Edwards

1 Answers

2
votes

This seems to be a bug in the framework. Here's the line that is wrong:

if ($this->expectedExitCode != null) 

This should have been if ($this->expectedExitCode !== null) because 0 == null in PHP.

The workaround here would be:

public function testCommandUsage()
{
    $statusCode = $this->artisan('cmd:test')->run();
    $this->assertEquals(0, $statusCode);
}

Note: Feel free to report this using Laravel's bug tracker if it's not already reported and hopefully it will be solved soon.

Apparently a fix for this has landed in the 5.7 branch as of 3 hours ago so a fix should be released soon. Until then the workaround should work.