LiipTestFixturesBundle
LiipTestFixturesBundle copied to clipboard
Caching mysql database with its data
While running all my e2e tests, the bundle caches the test database and restores it when it passes to another test. But it does not backup only the database schema, it also backup the test data. So when PHPUnit passes to another test, the database initializes with the previous tests' data. And occurs unexpected results.
Preconditions
Package versions
"liip/functional-test-bundle": "4.2.0",
"liip/test-fixtures-bundle": "1.9.1",
"doctrine/doctrine-bundle": "1.12.10",
"doctrine/common": "2.13.3",
"doctrine/dbal": "2.10.4",
"doctrine/orm": "2.7.4"
Steps to reproduce
My config
liip_functional_test: ~
liip_test_fixtures:
cache_db:
mysql: liip_test_fixtures.services_database_backup.mysql
My test case
class E2eTestCase extends TestCase
{
use FixturesTrait;
protected function setUp(): void
{
parent::setUp();
$this->loadFixtures();
}
// ...
}
Expected result
I would expect the bundle to backup only database schema, not test data. How can I achieve this?
I think it's working as designed: it's supposed to cache the data with only the fixtures you loaded. It's keeping different fixtures files depending on the classes.
It looks like you don't want backups, you can disable them by removing cache_db
To keep the database schema during tests, enable the option keep_database_and_schema: true. Then add a step in your tests to create the database schema, and run PHPUnit tests. The data will be wiped but the schema will be kept across tests.
Closing since this is the expected result