Skip to content
Advertisement

How to enable “dev” bundles so that they are available during testing, on the “test” environment?

I was configuring environment of a symfony 5 project, and while testing the test environment (APP_ENV = test) there was an exception because it couldn’t find the web-profiler bundle. Which is normal since it’s installed by composer with a require –dev. Which is kinda a dilemma since even though I currently don’t need this bundle in a test env, I technically might.

Worse : I need the doctrine fixture bundle in dev and in test; but to have it in test too, I’d have to “remove the –dev” option, therefore having it in production too, which is pretty bad.

So I’m wondering what is the common way to handle that issue? I guess it’s a common problem.

Advertisement

Answer

Simply enable the bundles for multiple environments:

For example:

// config/bundles.php
DoctrineBundleFixturesBundleDoctrineFixturesBundle::class =>
    [
        'dev' => true,
        'test' => true
    ],

You still install (require) the packages with the --dev flag, which simply means that they are not installed when you create the installable version for production (composer install --no-dev).

If you need dev dependencies while testing, then the “testing” environment can’t be identical to production. Either you install those dependencies on production but leave them disabled them on bundles.php, or you accept that there are going to be slight differences in these environments.

Practically, they are never going to be identical. For example, you require phpunit on dev, but obviously do not want in prod.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement