Reputation: 8355
If you want to prevent the database fixtures from being loaded accidentally in the wrong environment, the (probably) best way is to activate the DoctrineFixturesBundle
only in certain environment(s).
Up to Symfony 3.4 this was done in app/AppKernel.php
, as described at https://symfony.com/doc/3.4/best_practices/business-logic.html#data-fixtures
How can this be achieved in Symfony 4 (Symfony Flex), where bundles are being loaded automatically?
Upvotes: 0
Views: 1923
Reputation: 8355
In Symfony 4, this can be configured in config/bundles.php
, by editing the line
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
See https://symfony.com/doc/4.1/best_practices/business-logic.html#data-fixtures
When you remove the 'dev' => true,
part, and then try to load the fixtures in DEV environment by running php bin/console doctrine:fixtures:load --env=dev
, you will get:
Error thrown while running command "'doctrine:fixtures:load' --env=dev". Message: "There are no commands defined in the "doctrine:fixtures" namespace.
However, loading them in TEST environment still works: php bin/console doctrine:fixtures:load --env=test
Upvotes: 3