为什么Laravel立面间谍在某些测试案例中不工作(Laravel测试)
我正在研究Laravel的外观间谍,但我不明白为什么下面的第一个测试可以起作用,而第二个测试则不行。
<?php
namespace Tests\Unit\Helpers;
use Tests\TestCase;
use Illuminate\Support\Facades\Cookie;
class MyTest extends TestCase
{
/** @test */
public function it_sets_a_cookie()
{
Cookie::spy();
Cookie::queue('name', 'value', minutes: 100);
Cookie::shouldHaveReceived('queue'); // This works
}
/** @test */
public function it_reads_a_cookie()
{
Cookie::spy();
Cookie::get('name');
Cookie::shouldHaveReceived('get'); // This fails
}
}
我正在使用Laravel 9。
I am studying Laravel's facade spies, but I can't understand why the first test below works and the second doesn't.
<?php
namespace Tests\Unit\Helpers;
use Tests\TestCase;
use Illuminate\Support\Facades\Cookie;
class MyTest extends TestCase
{
/** @test */
public function it_sets_a_cookie()
{
Cookie::spy();
Cookie::queue('name', 'value', minutes: 100);
Cookie::shouldHaveReceived('queue'); // This works
}
/** @test */
public function it_reads_a_cookie()
{
Cookie::spy();
Cookie::get('name');
Cookie::shouldHaveReceived('get'); // This fails
}
}
Laravel documentation reference
I'm using Laravel 9.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论