Support the ongoing development of Laravel.io →
Requests Testing
Last updated 2 years ago.
0

You can't. Cookie::get() dispatches to Request::cookie, and per the docs Request isn't to be mocked. The way I've used is:

public function test_something() {
    $this->client->getCookieJar()->set(
        new \Symfony\Component\BrowserKit\Cookie('foo', 'bar')
    );

    $this->call('GET', '/a/route');
    $this->assertSame('bar', \Cookie::get('foo'));
}

You must absolutely call the route before the \Cookie::get assertion will pass BECAUSE cookies do not exist until given by the client.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

zaalbarxx zaalbarxx Joined 23 Mar 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.