In Laravel, Facades are used to provide a static interface to classes available inside the application’s service container.
Now, unlike conventional static method calls, facades can be mocked in Laravel. It can be done using the shouldRecieve method, which shall return an instance of a facade mock.
Example:
1 2 3 | $value = Cache::get('key'); Cache::shouldReceive('get')->once()->with('key')->andReturn('value'); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.