When I test my application with unit-testing cache moking works well. But when I try test my api through feature tests I got an exception.
public function testGet()
{
Cache::shouldReceive('rememberForever')->times(5)->andReturn([]);
Cache::shouldReceive('has')
->once()
->andReturn(false);
Cache::shouldReceive('forever')
->once()
->andReturn([]);
$response = $this->getJson('/api/table/get');
$response->assertOk();
$responseArr = $response->getOriginalContent();
$this->assertEmpty($responseArr['table']);
}
Tests\Feature\Controller\API\Site\TableApiControllerTest::testGet Mockery\Exception\BadMethodCallException: Received Mockery_2_Illuminate_Cache_CacheManager::driver(), but no expectations were specified
Exactly the same mocking in other unit-tests works without errors.
Aucun commentaire:
Enregistrer un commentaire