mercredi 30 décembre 2015

How to mock Cache::remember in Laravel

Within a unit test method, I tried to mock a Cache::remember response like this:

Cache::shouldReceive('remember')
    ->once()
    ->with('my_key', 120, function() {}) // There are 3 args in remember method
    ->andReturn([]);

But I get this error:

exception 'Mockery\Exception\NoMatchingExpectationException' with message 'No matching handler found for Mockery_0_Illuminate_Cache_CacheManager::remember ("my_key", 120, object(Closure)). Either the method was unexpected or its arguments matched no expected argument list for this method

I don't understand why I got this error and did not found anything in Laravel documentation about this. It says there is no matching, but it seems to match.

How can I mock a mock a Cache::remember response?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1mi376c
via IFTTT

Aucun commentaire:

Enregistrer un commentaire