Hello! Does anyone knows if there is a chance to somehow mock call to Cookie::get() method ? I know it's facade and there is shouldReceive() method, but this method does not belong to CookieJar, but to Facade itself and it's a static method. Or maybe there is a way to call request like $this->call() and pass some parameter which would create a cookie ?
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community