Since Symfony 4, we can test that arguments injected into services match type declarations with lint:container command.
However, if we use %env(MY_ENV_VARIABLE)% parameters, lint:container does not verify if the value is correctly set.
We can have a warning with debug:container --env-vars command if MY_ENV_VARIABLE is missing
[WARNING] The following variables are missing:
MY_ENV_VARIABLE
but the command doesn't fail as it's only a warning
In our company, we separate production environment variables from code repository because it relies on different teams. If exploitation team wants to change production values, there is no need to make a new release of code they juste change environment variables in their project.
So if an environment variable is not correct in their project we can have issues on production even if the CI is all green.
My idea would be to add environment test on lint:container so that we can have this security before releasing a new deployment.
Example
parameters:
api_url: '%env(MY_ENV_VARIABLE)%'
.env
MY_ENV_VARIABLE_WRONGLY_DEFINED='value'
Before the feature: php bin/console lint:container
[OK] The container was linted successfully: all services are injected with values that are compatible with their type
declarations.
After the feature: php bin/console lint:container
The parameter "api_url" has a dependency on a non-existent environment variable "MY_ENV_VARIABLE".
The text was updated successfully, but these errors were encountered:
Description
Since Symfony 4, we can test that arguments injected into services match type declarations with lint:container command.
However, if we use %env(MY_ENV_VARIABLE)% parameters, lint:container does not verify if the value is correctly set.
We can have a warning with debug:container --env-vars command if MY_ENV_VARIABLE is missing
[WARNING] The following variables are missing:
MY_ENV_VARIABLE
but the command doesn't fail as it's only a warning
In our company, we separate production environment variables from code repository because it relies on different teams. If exploitation team wants to change production values, there is no need to make a new release of code they juste change environment variables in their project.
So if an environment variable is not correct in their project we can have issues on production even if the CI is all green.
My idea would be to add environment test on lint:container so that we can have this security before releasing a new deployment.
Example
Before the feature:
php bin/console lint:container
After the feature:
php bin/console lint:container
The text was updated successfully, but these errors were encountered: