Symfony: `environment: 'prod'` not working
ThomasLandauer opened this issue · comments
What are you trying to achieve?
Run tests in Symfony's PROD environment.
What do you get instead?
Tests are still run in TEST environment.
Details
To investigate this, I created a controller which just outputs the environment (return new Response($kernel->getEnvironment());
). When browsing to its url I get whatever I have in Symfony's .env
. Fine.
When I access the url with codeception (codecept_debug($I->grabPageSource());
), I get whatever I write into functional.suite.yml
, even an arbitrary string like foo
.
However, if I put prod
, the app isn't really run in PROD environment. The feature I want to test is if the correct error page is shown. But in DEV/TEST environment Symfony always shows its internal Exception Page, not my own error page (see https://symfony.com/doc/current/controller/error_pages.html#testing-error-pages-during-development ) - that's how I know that I am still in TEST environment in fact.
I even tried with a @prepare
annotation ($symfony->_reconfigure(['environment' => 'prod']);
) to switch just for this single test (cause that's what I originally intended).
- Codeception version: 2.5.2
- Symfony version: 4.2.1
- Suite configuration:
actor: FunctionalTester
modules:
enabled:
- Symfony:
app_path: 'src'
environment: 'prod'
I can confirm this problem but coming at it from another direction.
I'm using API-Platform and have different DB config values for Dev and Test environments.
Regardless of the environment I specify, only the main .env file is loaded.
actor: ApiTester
modules:
enabled:
- Symfony:
app_path: 'src'
environment: 'FOOBAR'
So to make things work, I have .env pointed to my test database and rely on .env.test and .env.dev to work correctly in the regular symfony app.
I've tracked the code to my-app/src/Kernel.php where the correct env value is passed in, but .env files are read in the wrong order.
In the course of further research, I discovered that the .env files seem to have the desired affect over the environment value specified in the symfony configuration above. So I'm not setting environment in the Codeception > Symfony module. In its place, using .env files seems to work well enough for both the main symfony stack AND codeception
#codeception.yml
params:
- .env.FOOBAR
# .env.test
###> symfony/framework-bundle ###
APP_ENV=FOOBAR
...
# tests/api.suite.yml
# no environment specified since it doesn't appear to have any affect
actor: ApiTester
modules:
enabled:
- Symfony:
app_path: 'src'
@ThomasLandauer Can you reproduce this problem in the test project?
I need to know if this is still a problem with the supported versions of Symfony, at least Codeception 4 and version 1.6 of this module.
I am not able to reproduce or fix the problem with the versions described in this issue, so please update it.
Yes, the issue is still there. I created https://github.com/ThomasLandauer/symfony-module-tests/tree/issue_88
Run vendor/bin/codecept run Functional EnvironmentCest:try -vvv
, and you'll see "foo" in the output, which is the string I put in Functional.suite.yml
.
However, when you open /public/index.php/environment
in a browser, you'll see "prod".