DEV Community

Cover image for Mock Config in Laravel
Hamid Haghdoost
Hamid Haghdoost

Posted on • Updated on

Mock Config in Laravel

Hi all. If you are testing your application and you need to make your config constant or change it to a specific value for testing you can mock it simply!
Config facade of Laravel has a method named set() which overwrites the default value of configs like this:

Config::set('name', 'Laravel');
Enter fullscreen mode Exit fullscreen mode

So in testing env you can do something like this:

public function test_that_home_page_is_working()
{
    Config::set('name', 'Laravel');
    $this->get('/')->assertSee("Laravel");
}
Enter fullscreen mode Exit fullscreen mode

Generally Laravel facades have several benefits because of their testability. You can Mock all facades of Laravel easily. Also if you want to have deeper knowledge about testing tools you can take a look at PHP Mockery.

Oldest comments (0)