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

The loaded environment differs between the testing scope and the running scope #204

Closed
nesk opened this issue Mar 22, 2017 · 4 comments
Closed

Comments

@nesk
Copy link
Contributor

nesk commented Mar 22, 2017

I've create a new project to showcase what's happening.

Installation and running:

git clone https://github.com/nesk/laravel-env-issue-showcase.git
cd laravel-env-issue-showcase
composer install
php artisan serve

# You might want to run this in another terminal
php artisan dusk

The only browser test will fail, so what's happening?

I've created a .env file containing a APP_ENV=local line. I've also created a .env.dusk.local file containing the APP_ENV=testing line.

The EnvTest tries to check if the app is running in the testing environment and obviously fails.

For better comprehension, I've logged the environment in two places:

If you run cat storage/logs/laravel.log in your terminal after a failed test, you will see something like that:

[2017-03-22 09:14:54] testing.DEBUG: Env inside test: testing  
[2017-03-22 09:14:56] local.DEBUG: Env inside route: local

Here is the issue: the EnvTest class runs with the testing environment, while the application runs with the local environment. I expect the environments to be the same, maybe it's a misunderstanding?

However, despite this issue, thank you for this awesome package!

@nesk
Copy link
Contributor Author

nesk commented Mar 22, 2017

A possible solution could be to let Dusk run php artisan serve by itself, which is something discussed in #162.

@deleugpn
Copy link
Contributor

Although the approach of #162 is a great suggestion (which I yet intend to follow up on), it is not something that I think should be on core because you cannot make such assumption of the desired behavior for everyone.

The core of what you're describing is caused by the Browser and Dusk being on separate processes. So Dusk, although inside of Laravel, is acting as a Web Browser going to your application and it will work like .env is the environment definition. Personally, I bypass this issue by starting php artisan serve --env=dusk.local

@deleugpn deleugpn mentioned this issue Apr 21, 2017
@driesvints
Copy link
Member

Closing this issue because it's already solved, old or not relevant anymore. Feel free to reply if you're still experiencing this issue.

@bagardavidyanisntreal
Copy link

bagardavidyanisntreal commented Sep 9, 2019

the greatest thing to do before running the dusk is to make sure you run dev server in the right way, I'll describe (3 days and nights was burned to solve this puzzle):

  1. make sure you have a .env.dusk.{environment} file with the correct APP_URL=domain.name:port
  2. clean your config artisan config:clear
  3. run the dev server typing artisan serve --env=dusk.{environment}
  4. run artisan dusk
    I really hope this will save you time because I didn't find this kind of subtleties in docs. And definitely you don't need to toggle some dummy construction in your \Tests\CreatesApplication::createApplication method or add crutch in \App\Providers\AppServiceProvider::register method, because a notify about running in PROD_ENV already exists and will throw.

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

No branches or pull requests

4 participants