Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 454
Prathyush Lal Avatar asked Jul 04 '26 10:07

Prathyush Lal


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);
like image 74
matiaslauriti Avatar answered Jul 06 '26 05:07

matiaslauriti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!