Support the ongoing development of Laravel.io →
posted 9 years ago
Testing
Last updated 1 year ago.
0

This is a common when testing. I've never seen a proper solution for this.

Some people would disabling the csrd token middleware when testing.

0

To disable The CSFR Check you can add the following to your class:

class MyTest extends TestCase
{
    use WithoutMiddleware;
    ...
0

or you can use a check in the middleware if env == testing just return/go to next request.. (cant remember the exact code)

0

If you look at the middleware you can see how it works, it retrieves the stored session value for _token from session. So you can avoid the exception by simple passing some session data with your request:

            $this->withSession(['_token'=>'test']) //here
                ->makeRequest('POST', $deleteEntry, [
                    'id'=>1,
                    '_token'=>'test' //here 
            ])->seePageIs($url);
Last updated 7 years ago.

mmakita liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

Gazoo101 gazoo101 Joined 24 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.