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

[FrameworkBundle] Test missing environment variables with lint:container command #49135

Open
vincentmary opened this issue Jan 27, 2023 · 0 comments

Comments

@vincentmary
Copy link

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

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".     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants