thebigk's avatar
Level 13

Do not want to disable Middleware and yet get the test to green

My test is as follows:

/** @test */
    public function guests_cannot_create_quiz() {
        //$this->withoutMiddleware();
        $this->post('/quiz/store', [])
            ->assertRedirect('/register');
    }

I'm trying to post an empty array to my route and I expect the system to redirect the user to login page. While I'm not exactly sure if that's the right assertion to make; I'm now thinking maybe I should assert for an exception.

In either case, my controller isn't throwing the right error; which I believe should be 'authentication' exception.

Here's what I'm getting:

Response status code [419] is not a redirect status code.
Failed asserting that false is true.

If I disable the middleware, I get status code [200], because the system ignores the auth middleware and lets the user post.

Can someone help me figure out what's going on?

0 likes
2 replies
martinbean's avatar

@thebigk Dump the response to see what Laravel’s giving you back:

$response = $this->post('/quiz/store', []);

$response->dump();

The test will halt and show you the raw response from that request, and you can diagnose the issue from there.

thebigk's avatar
Level 13

It mentions page expired due to inactivity.

PHPUnit 6.4.4 by Sebastian Bergmann and contributors.

........"""
<!DOCTYPE html>\n
<html lang="en">\n
    <head>\n
        <meta charset="utf-8">\n
        <meta http-equiv="X-UA-Compatible" content="IE=edge">\n
        <meta name="viewport" content="width=device-width, initial-scale=1">\n
\n
        <title>Page Expired</title>\n
\n
        <!-- Fonts -->\n
        <link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">\n
\n
        <!-- Styles -->\n
        <style>\n
            html, body {\n
                background-color: #fff;\n
                color: #636b6f;\n
                font-family: 'Raleway', sans-serif;\n
                font-weight: 100;\n
                height: 100vh;\n
                margin: 0;\n
            }\n
\n
            .full-height {\n
                height: 100vh;\n
            }\n
\n
            .flex-center {\n
                align-items: center;\n
                display: flex;\n
                justify-content: center;\n
            }\n
\n
            .position-ref {\n
                position: relative;\n
            }\n
\n
            .content {\n
                text-align: center;\n
            }\n
\n
            .title {\n
                font-size: 36px;\n
                padding: 20px;\n
            }\n
        </style>\n
    </head>\n
    <body>\n
        <div class="flex-center position-ref full-height">\n
            <div class="content">\n
                <div class="title">\n
                        The page has expired due to inactivity.\n
    <br/><br/>\n
    Please refresh and try again.\n
                </div>\n
            </div>\n
        </div>\n
    </body>\n
</html>\n
"""

Please or to participate in this conversation.