如何为http假冒的饼干伪造响应?
我想与cookie嘲笑Laravel的HTTP响应。我尝试了:
Http::fake([
'my-mocked-route' => Http::response(['foo' => 'bar'], 200)->withCookie('a', 10),
]);
但是我收到
致电未定义的方法guzzlehttp \ promise \ eachillpromise :: withcookie()
如果我只使用cookie
而不是with cookie
。另外,我会添加cookie属性。
我还尝试了
Http::fake([
'qnnect' => Http::response(['foo' => 'bar'], 200, ['Cookie' => 'a=10; Expiration=Wed, 21 Oct 2015 07:28:00 GMT']),
]);
,尽管响应在标题中包含正确的cookie,但$ response-> cookie()
返回一个空的cookiejar。
是否有可能在响应中嘲笑饼干?
I want to mock a HTTP response in Laravel with cookie. I tried this:
Http::fake([
'my-mocked-route' => Http::response(['foo' => 'bar'], 200)->withCookie('a', 10),
]);
but I receive
Call to undefined method GuzzleHttp\Promise\FulfilledPromise::withCookie()
same if I just use cookie
instead of withCookie
. Also, I would to add Cookie attributes aswell.
I also tried
Http::fake([
'qnnect' => Http::response(['foo' => 'bar'], 200, ['Cookie' => 'a=10; Expiration=Wed, 21 Oct 2015 07:28:00 GMT']),
]);
And although the response contains correct cookies in the header, $response->cookies()
returns an empty CookieJar.
Is there a possibility to mock cookies in the respond?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确的标头是
set-cookie
而不是cookie
。还需要域。输出将为
bar
The correct header is
Set-Cookie
and notCookie
. Domain is also required.Output will be
bar
- > with cookies
是您可以在http :: fake()
上使用的方法->withCookies
is a method you can use onHttp::fake()
and not onHttp::response()