Lumen Artisan command throws "Error: Call to a member function assertExitCode() on int" while testing

Viewed 213

my code is as follows:

class DailyUsageCommandTest extends TestCase
{
    public function testDailyUsageCommandTest()
    {
        $this->artisan('daily-usage')->assertExitCode(0);
    }
}

But it throws:

1) DailyUsageCommandTest::testDailyUsageCommandTest Error: Call to a member function assertExitCode() on int

1 Answers

The error is saying that $this->artisan('daily-usage') returns an int (Call to a member function assertExitCode() on int). So you have to store the result and do assertTrue with your value like this:

$result = $this->artisan('daily-usage');

$this->assertTrue($result === 0);
Related