我在下面做了一个简单的测试:
public function test_return_success_if_reminder_is_set(){
Cache::shouldReceive('remember')
->once()
->with($this->user->email, 60, \Closure::class)
->andReturn([
"message" => "Cool"
]);
$response = $this->json("POST", "my-awesome-endpoint");
$response->assertStatus(200)
->assertJson([
"success"=>true,
"message"=> "Awesome"
]);
}
由于某种原因,出现此错误:
Received Mockery_0_Illuminate_Cache_CacheManager::driver(), but no expectations were specified
我想念什么?
答案 0 :(得分:0)
Cache::shouldReceive('remember')
->once()
->with($this->user->email, 60, \Closure::class)
->andReturn([
"message" => "Cool"
]);
Cache::makePartial();
请尝试上面的代码
请参阅:http://docs.mockery.io/en/latest/reference/partial_mocks.html?highlight=runtime
答案 1 :(得分:0)
请尝试以下代码。我做得很好。 :)
public function setUp()
{
Cache::shouldReceive('get')->with('key')->andReturn('value');
Cache::makePartial();
parent::setUp();
// other init code...
}