I'm working on a package that relies on the Config
facade.
The code itself works fine, but I'm encountering issues when testing.
Initially, I was using this code:
Config::shouldReceive('foo.bar')
->andReturn(true);
As many others, I bumped into some issues.
I later read that mocking the Config
facade isn't encouraged.
To get around it, most people tend to suggest to use the following instead:
Config::set('foo.bar', true);
Which I reckon works fine, if you're testing from Laravel/Lumen.
But my issue is, I'm not. I just rely on a few Illuminate
packages, so that won't work since I get:
RuntimeException: A facade root has not been set.
At this point, some might suggest that I should just inject the Config
repository dependency, but I'm using the Config
facade in a trait which is used by an Eloquent
model, so DI won't work.
Is there any other way I can tackle this?
Thanks!
PS: This question has also been posted on Laracasts