Darkstarone
Darkstarone

Reputation: 4730

Symfony 3 setting up a test database

I'm trying to set up a testing suite for my Symfony 3 app, and I'm wondering what the correct method for setting up the test database is. I've found this article, but it doesn't actually explain how to add fixtures programmatically.

Also, it appears their example sets up the test database for every test.

Is there a way to setup a test database which is automatically loaded with fixtures when phpunit is run? The official documentation is kind of sparse

Upvotes: 2

Views: 1679

Answers (2)

LBA
LBA

Reputation: 4089

If you extend your TestCases from KernelTestCase or WebTestCase, basically extend from \PHPUnit_Framework_TestCase you have methods like setUpBeforeClass() or setUp() which are run by PhpUnit before your test/test cases is/are executed.

Use this to e.g. create your fixtures, load your SQL file or whatever and however you might require your prerequisites for your tests.

Upvotes: 0

pogeybait
pogeybait

Reputation: 3145

Symfony has different environments you can operate in. By default those are prod(production), dev(developement) and test. Although it may not be exactly what you want, you can configure different config, paramaters, routes and so on for each environment. Read the official documentation for more info but yeah, you can setup your parameters.yml file for test mode which could have a different database configured there.

https://symfony.com/doc/current/configuration/environments.html

Upvotes: 2

Related Questions