Testing Laravel HTTPNOTFOUND Exception on second pass

Posted 3 months ago by longestdrive

Hi I'm trying to set up some simple tests for an app to check a user can view specific pages etc.

Most of the tests I can set up ok but one set of tests is coming up with strange behaviour - If I run each test individually it passes and the expected page is viewed but if I run them in sequence the second test fails giving an HttpNotFound exception.

Here's the tests:

public function testUserCanSeeLeagueIndex()
{
    $this->disableExceptionHandling();

    $response = $this->actingAs($this->user)
        ->get('leagues');

    $response->assertStatus(200)
        ->assertSee('Leagues');

}

public function testUserCanSeeEclecticLeagueIndex()
{
    $this->disableExceptionHandling();

    $response = $this->actingAs($this->user)
        ->get('leagues');

    $response->assertStatus(200)
        ->assertSee('Eclectic Leagues');

}

The second test fails but if I run it on it's own it passes as expected

For now I've deliberately set the URL the same just to get past this test.

I've checked the routes for any declared twice.

What do I need to do to overcome this problem?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.