bencarter78@hotmail.com's avatar

HTTP Test failing on actingAs

Hi there

I'm trying to write a simple HTTP test for an authenticated user but I'm getting the following error.

Failed asserting that '<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="1;url=http://myurl.dev" />

        <title>Redirecting to http://myurl.dev</title>
    </head>
    <body>
        Redirecting to <a href="http://localhost:3000">http://myurl.dev</a>.
    </body>
</html>' contains "Filter Criteria".

So it seems like it's attempting to do some kind of redirect (which I assume is where it's trying to authenticate?).

My test is just this...

$user = factory(User::class)->states('admin')->create();
$this->actingAs($user)
    ->get('/judi/analysis/criteria')
        ->assertSee('Filter Criteria');

Can anyone point me in the right direction?

0 likes
2 replies
martinbean's avatar

@bencarter78 Your test looks alright, but I usually open app/Exceptions/Handler.php and stick throw $e; as the first line of the render() method to get the exception in the console.

Laravel 5.5’s shipping with the ability to disable the exception handler, which will be handy for diagnosing issues like this.

bencarter78@hotmail.com's avatar

Well that was a frustrating couple of hours! Eventually realised the problem was that the route was inside a route group which had an extra middleware associated with it.

Please or to participate in this conversation.