regal2157's avatar

Console test failing to test in order?

I'm running through https://laracasts.com/series/whats-new-in-laravel-5-7/episodes/3 and my testing results don't line up...

It appears the assertDatabaseHas assertion takes priority over expectsQuestion.

tests/Feature/Console/MakeUserCommandTest.php

function it_generates_a_new_user()
    {
        $this->artisan('make:user')
            ->expectsQuestion('What name should we use?', 'John Doe')
            ->expectsQuestion('And the email address?', '[email protected]')
            ->expectsQuestion('And the password?', 'password')
            ->expectsOutput('The user John Doe has been created')
            ->assertExitCode(0);

        $this->assertDatabaseHas('users', ['name' => 'John Doe']);
    }

routes/console.php

Artisan::command('make:user', function() {
});

I should see the test fail because no question was asked, but I'm getting an fail for the database not having the user.


There was 1 failure:

1) Tests\Feature\Console\MakeUserCommandTest::it_generates_a_new_user
Failed asserting that a row in the table [users] matches the attributes {
    "name": "John Doe"
}.

The table is empty.

Am I missing something? If I comment out the assertDatabaseHas I can see the error for the question not asked..

Laravel 5.7.15

Thanks!

0 likes
0 replies

Please or to participate in this conversation.