Skip to content

Problems due overriding configuration that were previously set using env variables #22561

Closed
@fefas

Description

@fefas
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.2.7

Hello,

I don't know if it is a bug/issue or just a question. We are using environment variables to configure the application. For acceptance/feature tests purposes (using Behat), we need to switch the database, because we have to arrange the database state for each scenario. In this way, there are the following config files on app/config directory:

# doctrine.yml

doctrine:
  dbal:
    connections:
      default:
        driver: pdo_mysql
        host: "%env(DATABASE_HOST)%"
        dbname: "%env(DATABASE_DBNAME)%"
        user: "%env(DATABASE_USER)%"
        password: "%env(DATABASE_PASSWORD)%"

# ...

# config_dev.yml

imports:
  - resource: doctrine.yml

# ...

# config_behat.yml

imports:
  - resource: doctrine.yml

doctrine:
  dbal:
    connections:
      default:
        host: "%env(DATABASE_TEST_HOST)%"
        dbname: "%env(DATABASE_TEST_DBNAME)%"
        user: "%env(DATABASE_TEST_USER)%"
        password: "%env(DATABASE_TEST_PASSWORD)%"

# ...

But the following exception is throwed:

[Symfony\Component\DependencyInjection\Exception\EnvParameterException]
  Incompatible use of dynamic environment variables "UPX_DATABASE_HOST", "UPX_DATABASE_DBNAME", "UPX_DATABASE_USER", "UPX_DATABASE_PASSWORD" found in parameters.

It is throwed here.

After reading docs and debugging for a while, we've noted in the code is that Symfony doesn't allow us to override a config value that is an environment variable.

We've noted also that this verification was inserted in PR #19681.

The question: Is it Symfony's matter? Or are we missing something here and our configuration is not recommended?

In our humble opinion, problems due to override config values and then not using environment variables previously set should be responsibility of tests that run after application setup (integration, feature, ...).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions