1

I'm writing functional tests with Behat and Mink in a Symfony2 application.

I make use of the data that's already in the database to make the tests instead of adding fixtures (a lot would be needed).

Therefore, I can't use a SQLite database only for the test environment as data would not be available.

My tests work fine, but data is persisted in the database when tests are run.

How can I automatically clean up data that's been persisted with Doctrine after a scenario is run?

I can't use a transaction as functional tests involve page redirections (e.g. the form is filled and posted to an other Symfony2 action).

Michaël Perrin
  • 5,298
  • 4
  • 30
  • 58

1 Answers1

1

if you're persisting data I see no way to automatically revert everything. I would simply make a copy of the database, do the tests on it and drop it afterwards.

Andreas Linden
  • 11,975
  • 7
  • 46
  • 65
  • Ok, thanks for your answer. I tried to extend the `EntityManager` class, neutralize the `commit` method and make use of it in the `test` environment. But it seems there's no easy way to use an other `EntityManager` class... – Michaël Perrin Jun 20 '13 at 12:31
  • 3
    Some time later, it's of course much better to copy the database or initialize a copy with the database with data fixture. – Michaël Perrin Oct 27 '14 at 15:31