Can I put my databse configuration in a configuration file in config/packages/test/ somehow?
I want to run my tests on my development PC and do the dev work in parallel. In Symfony 3 I had 2 configurations files
config_test.yaml and config_dev.yaml
where I could put in 2 different database connections. Now the database connection is in the .env File, so I can not have 2 of them.
I also need to run my fixtures and database helpers and the 2 databases (dev and test) seperatly:
php bin/console doctrine:schema:update --force --env=dev
php bin/console doctrine:fixtures:load --no-interaction --env=dev
the solution was to remove the databse connection from the .env file and move it into seperated config files again:
config/packages/dev/doctrine.yaml:
parameters:
DATABASE_URL: 'mysql://root@localhost:3306/database'
and config/packages/test/doctrine.yaml:
parameters:
DATABASE_URL: 'mysql://root@localhost:3306/database_test'
and inthe main doctrine configuration file config/packages/doctrine.yaml:
doctrine:
dbal:
url: '%DATABASE_URL%'
also in phpunit.xml.dist:
<env name="DATABASE_URL" value="mysql://root@localhost:3306/database_test" />
Now you can have your test and dev environment on the same system and your databse is not polluted by testing data and you can update your databases with:
php bin/console doctrine:schema:update --force --env=dev
php bin/console doctrine:schema:update --force --env=test