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 in Laravel by kartik
• 16,870 points
203 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 by Niroj
• 35,060 points

Related Questions In Laravel

0 votes
1 answer

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

Hii @kartik, To create a migration, you may ...READ MORE

answered Mar 30 in Laravel by Niroj
• 35,060 points
3,192 views
0 votes
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 in Laravel by Niroj
• 35,060 points
1,133 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 in Laravel by Niroj
• 35,060 points
595 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 in Laravel by Niroj
• 35,060 points
137 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 in Laravel by Niroj
• 35,060 points
104 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 in Laravel by Niroj
• 35,060 points
39 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 in Laravel by Niroj
• 35,060 points
49 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 in Laravel by Niroj
• 35,060 points
48 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 in Laravel by Niroj
• 35,060 points
233 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 in Laravel by Niroj
• 35,060 points
54 views