1

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!

Fran Roa Prieto
  • 385
  • 1
  • 3
  • 12

1 Answers1

5

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

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

nxu
  • 2,202
  • 1
  • 22
  • 34