S
S
slip312021-05-03 16:52:03
symfony
slip31, 2021-05-03 16:52:03

How to work with a test environment?

Hello. I can't figure out how to work with env files and tests, in particular, have my own test base.
There is a project on Symfony 5 and Codeception. I would like to run tests, including those working with a database created specifically for tests.
There is a `project` base and a `project_test` base. I created a file .env.test.localand put it in

APP_ENV=test
DATABASE_URL="mysql://root:[email protected]:3306/project_test"

Everything is fine with this. If I run
bin/console doctrine:migrations:migrate --env=testmigrations they end up in `project_test`. But what to do next? If I run `codecept_run` the tests run against the `project` base, not the test base. Where and what should I specify in order to work with the test base? Symphony's documentation
contains such a "recipe"
$ APP_ENV=test symfony php bin/phpunit tests/Controller/ConferenceControllerTest.php
, but can I just specify APP_ENV=test in env.local.test and have symphony "accept" it, or how does it even work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2021-05-04
@myks92

You need to set the test environment variable for tests, then everything will work for you. This can be done in the test configuration file.
Unit test setup example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question