Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking Cache Facade throws InvalidArgumentException #10480

Closed
tillkruss opened this issue Oct 4, 2015 · 3 comments
Closed

Mocking Cache Facade throws InvalidArgumentException #10480

tillkruss opened this issue Oct 4, 2015 · 3 comments

Comments

@tillkruss
Copy link
Collaborator

The code from the 5.1 docs to mock the Cache facade doesn't work: http://laravel.com/docs/5.1/testing#mocking-facades

Cache::shouldReceive('get')
   ->once()
   ->with('key')
   ->andReturn('value');

Error:

InvalidArgumentException: get() cannot be mocked as it a protected method and mocking protected methods is not allowed for this mock

Should this be fixed, or removed from the docs?

@crynobone
Copy link
Member

Does this work?

Cache::shouldReceive('driver->get')
   ->once()
   ->with('key')
   ->andReturn('value');

@tillkruss
Copy link
Collaborator Author

Throws:

BadMethodCallException: Method Mockery_0_Illuminate_Cache_CacheManager::tags() does not exist on this mock object

If I alter the code to:

Cache::shouldReceive('driver->get')
   ->once()
   ->tags('tag')
   ->with('key')
   ->andReturn('value');

It throws:

ErrorException: call_user_func_array() expects parameter 1 to be a valid callback, class 'Mockery\Expectation' does not have a method 'tags'

@tillkruss
Copy link
Collaborator Author

@GrahamCampbell So is this a bug, or should it be removed from the docs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants