LiipTestFixturesBundle icon indicating copy to clipboard operation
LiipTestFixturesBundle copied to clipboard

Caching mysql database with its data

Open emr opened this issue 5 years ago • 2 comments

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?

emr avatar Oct 14 '20 09:10 emr

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.

magnetik avatar Dec 09 '20 14:12 magnetik

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.

alexislefebvre avatar Jul 20 '21 21:07 alexislefebvre

Closing since this is the expected result

alexislefebvre avatar Oct 04 '22 22:10 alexislefebvre