How to check if I'm in a testing environment
mattstauffer opened this issue · comments
Matt Stauffer commented
In Laravel, I would normally use one of these methods to check if I'm in a testing environment:
\App\environment() === 'testing'
config('app.env') === 'testing'
\App::runningUnitTests()
But in Laravel Zero, the first two come back as development
and the third is false
.
What's the Laravel Zero idiomatic way to fix this?
Thanks!
Matt Stauffer commented
What I've done that worked, but I didn't know if it was preferred:
- Add this block to the bottom of
phpunit.xml.dist
, right before</phpunit>
:
<php>
<server name="APP_ENV" value="testing"/>
</php>
- Update the
env
key inconfig/app.php
to this:
'env' => env('APP_ENV', 'development'),
Nuno Maduro commented
@owenvoke Do know why this is not working on Laravel Zero? Couldn't find the reason.
Owen Voke commented
I think this is defaulted to development
because it is replaced with production
in-place during the build process. I'd say that @mattstauffer's solution is probably the easiest way to resolve this. 🤔