Search code examples
laraveltestinglaravel-testing

Acces to config variable when testing a package in laravel


I'm writing a test in Laravel and I want to unittest this piece of code:

if (file_exists(\Config::get('maintenance.dir.api'))) {
        throw new ServiceUnavailableException('We are down for maintenance');
    }

I'm using Illuminate\Foundation\Testing\TestCase and I can't access to the config variables from the main app in the test. In my package, I don't have any config. Can I mock the config folder or something like that?

Thank you!


Solution

  • You can 'mock' config variables by simply setting them:

    config(['maintenance.dir.api' => 'mock value'])