Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check if I'm in a testing environment #420

Open
mattstauffer opened this issue Jul 5, 2022 · 3 comments
Open

How to check if I'm in a testing environment #420

mattstauffer opened this issue Jul 5, 2022 · 3 comments

Comments

@mattstauffer
Copy link

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!

@mattstauffer
Copy link
Author

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'),

@nunomaduro
Copy link
Member

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

@owenvoke
Copy link
Member

owenvoke commented Jul 5, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants