How to mock a static facade methods in Laravel

0 votes
Is there any way to create static facade in Laravel? If yes, How to create them?
Mar 19, 2020 in Laravel by kartik
• 37,490 points
1,533 views

1 answer to this question.

0 votes

Hey,

Facades provide a "static" interface to classes that are available in the application's service container. 

Unlike traditional static method calls, facades may be mocked. We can mock the call to the static facade method by using the shouldReceive method, which will return an instance of a Mockery mock.

$value = Cache::get('key');

// testing
Cache::shouldReceive('get')
                    ->once()
                    ->with('key')
                    ->andReturn('value');
answered Mar 19, 2020 by Niroj
• 82,680 points

Related Questions In Laravel

+2 votes
2 answers

How to add a new column to existing table of laravel in a migration?

You need do little modification in your ...READ MORE

answered Dec 10, 2020 in Laravel by anonymous
• 82,680 points
28,074 views
+1 vote
1 answer

How to check if a record already exists in a laravel?

Hey, As a newbie it is most common ...READ MORE

answered Mar 31, 2020 in Laravel by Niroj
• 82,680 points
10,460 views
0 votes
1 answer

How to include a sub-view in Blade templates in Laravel?

Hello @kartik, You can use the blade template ...READ MORE

answered Mar 31, 2020 in Laravel by Niroj
• 82,680 points
5,369 views
0 votes
1 answer

How to get a list of registered route paths in Laravel?

Hello, Route::getRoutes() returns a RouteCollection. On each element, you can ...READ MORE

answered Mar 31, 2020 in Laravel by Niroj
• 82,680 points
720 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,680 points
333 views
0 votes
1 answer

Display Laravel in browser by using cmd promt?

Hello, First you need to have laravel install ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,680 points
167 views
0 votes
1 answer

How can we get started with Laravel through Xampp?

Hii, First you need to start Apache and ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,680 points
165 views
0 votes
1 answer

How to change Laravel official name to any customize name?

Hey, You just need to go Laravel folder through ...READ MORE

answered Mar 17, 2020 in Laravel by Niroj
• 82,680 points
255 views
0 votes
1 answer

.How to turn off CSRF protection for a particular route in Laravel?

Hey, We can add that particular URL or ...READ MORE

answered Mar 24, 2020 in Laravel by Niroj
• 82,680 points
1,849 views
0 votes
1 answer

How to make a constant and use globally in laravel?

Hii, You can create a constants.php page in config folder ...READ MORE

answered Mar 24, 2020 in Laravel by Niroj
• 82,680 points
487 views