1 year ago
#379955
Daniel
Why is Laravel facade spy not working in certain test cases (Laravel testing)
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.
php
laravel
testing
cookies
spy
0 Answers
Your Answer