Jason Swett
Jason Swett

Reputation: 45094

Database cleaning in Symfony2 tests

Is there a standard way of cleaning your database before (or after) each test when you're testing with Symfony2/PHPUnit? There seems to be a standard, obvious way to do this in Rails but I haven't found an analog in the Symfony community.

Upvotes: 5

Views: 2657

Answers (2)

igneus
igneus

Reputation: 1002

If you are using the LiipFunctionalTestBundle, database is purged on each loading of fixtures. If you don't need any fixtures loaded, you can still call $this->loadFixtures(array()); ("load no fixtures") to have database purged.

Upvotes: 1

Jakub Zalas
Jakub Zalas

Reputation: 36191

You can either purge the tables with Doctrine's data purger or rebuild the schema before every test.

Purger is part of data-fixtures package: https://github.com/doctrine/data-fixtures

I once wrote a KernelAwareTest which rebuilds the schema before every test: https://gist.github.com/1319290

Upvotes: 1

Related Questions