DEV Community

Cover image for Mock Config in Laravel
Hamid Haghdoost
Hamid Haghdoost

Posted on • Edited on

1

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.

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay