laravel / browser-kit-testing

Provides backwards compatibility for BrowserKit testing in the latest Laravel release.
MIT License
508 stars 75 forks source link

[6.x] allow APP_ENV to be defined by the environment #138

Closed splatEric closed 4 years ago

splatEric commented 4 years ago

APP_ENV is an environment variable that Laravel uses to determine which .env file to load when creating the application. The test case hardcodes this to testing which prevents the system environment variable from having the desired effect of picking the correct .env file when running my tests in CI.

I have basically removed the line that does this, which means that tests will now pick up the correct environment file in line with how Laravel works. Given that this is also set by default in the environment variables of phpunit.xml, I think it's reasonable to have simply removed this, rather than trying to do something more defensive with the change.

driesvints commented 4 years ago

No plans to merge sorry.

splatEric commented 4 years ago

Okay, I would humbly suggest that it would be worth considering for the next major version, as to me this is:

a) rather well hidden. b) inconsistent with Laravel's testing behaviour as it stands now.

(basically I spent an afternoon very confused as to why my .env.codeship file wasn't being picked up, which was my motivation for submitting the change).

For anyone who comes across this issue btw, I have created my own BrowserKitTestCase base class in my project, and overridden the refreshApplication method on it:

use Laravel\BrowserKitTesting\TestCase as BaseTestCase;

class BrowserKitTestCase extends BaseTestCase
{
    protected function refreshApplication()
    {
        $this->app = $this->createApplication();
    }
}