laravel-zero / laravel-zero

A PHP framework for console artisans

Home Page:https://laravel-zero.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to check if I'm in a testing environment

mattstauffer opened this issue · comments

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!

What I've done that worked, but I didn't know if it was preferred:

  1. Add this block to the bottom of phpunit.xml.dist, right before </phpunit>:
    <php>
        <server name="APP_ENV" value="testing"/>
    </php>
  1. Update the env key in config/app.php to this:
'env' => env('APP_ENV', 'development'),

@owenvoke Do know why this is not working on Laravel Zero? Couldn't find the reason.

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. 🤔