Closed 4d4ch4u32 closed 3 years ago
@antond1990
$_ENV
only has environment variables that are passed to the PHP script, which in the case of laravel
or symfony
would be from the .env
file.
Please use getenv
for system environment variables that are set in the workflow.
Ref: 1) https://www.php.net/manual/en/reserved.variables.environment.php 2) https://www.php.net/manual/en/function.getenv.php
That's right, but when I define a variable in the workflow, the variable is disappeared in Symfony, instead of overriden.
Happens when phpunit tests are running in the pipeline.
@antond1990
I could not reproduce the issue you are facing. I was able to get the environment variables in a PHPUnit test from the workflow using getenv
.
Test workflow: https://github.com/shivammathur/test-setup-php/runs/3087279025?check_suite_focus=true#step:13:21
If you can provide a link to your workflow or create a test repo to reproduce the issue, I can have a look.
Edit: Please re-open if you can reproduce the issue.
I've just run into this problem, as well. It took me by surprise that my environment variables were in $_SERVER
but not in $_ENV
. This was especially frustrating because vlucas/phpdotenv recommends against using getenv()
and putenv()
.
The reason this happens is because the variables_order
setting in setup-php's php.ini
is set to GPCS
. This excludes setting $_ENV
values (i.e., E
).
To override this behavior, you can configure setup-php with ini-values: variables_order=EGPCS
.
After doing this, $_ENV
values are populated, as expected.
For more info, see https://www.php.net/manual/en/ini.core.php#ini.variables-order
Describe the bug The workflow runs some checks and tests using this action in version 2. Because other services are used, some environment variables are defined in the github workflow which should override the variables defined in the
.env
file of Symfony. But the variables defined in the workflow are not available in the Symfony project.Version
v1
orv2
.v2
v1
Runners
Operating systems ubuntu-18.04
PHP versions 8.0
To Reproduce In the workflow yaml are some services such as
postgres
andredis
defined. In the.env
file of Symfony are the hosts defined with a default value, which are overriden in the workflow. So, for example we have the env varDATABASE_HOST
with default value (docker image)postgres
in.env
and the valuelocalhost
in the workflow. Github is showing the correct values of the defined variables.For debugging, I have added a step
php -r 'var_dump($_ENV)'
to get the variables from the docker setup which is done some steps before. The array is empty.When I dump the
$_ENV
variable directly in a phpunit test (in Symfony), there are only the default variables defined in '.env'.Expected behavior The environment variables must be available in the php setup and must override the .env-vars with the values defined in the github workflow.