liip / LiipTestFixturesBundle

This bundles enables efficient loading of Doctrine fixtures in functional test-cases for Symfony applications
https://liip.ch
MIT License
165 stars 45 forks source link

refactor: MongoDB Integration + MongoDB Tests #275

Closed possi closed 6 months ago

possi commented 6 months ago

Regarding #258 (replaces #273 by my colleague @buffcode)

AbstractDatabaseTool is split to extract DBAL specific code, such that using MongoDBDatabaseTool doesn't fail anymore.

As requested test for the MongoDB-Integration are added. To make this work, I also needed to fix a the usage of SymfonyFixturesLoader. MongoDB-Fixtures extend a different base class then ORM fixtures and are tagged differently by Symfony. They are accessed by a different SymfonyFixturesLoader (Doctrine\Bundle\MongoDBBundle\Loader\SymfonyFixturesLoader).

This also removes the need for a workaround we had to use in our codebase to make use of MongoDBDatabaseTool (before it broke with 2.7.2).

        // Reihenfolge relevant, da wir die Fixtures manuell hinzufügen müssen
        $fixtures = [
            CountryFixture::class,
            TaxAuthorityFixture::class,
            // ...
        ];

        // Fixture Loader lädt nur ORM Fixtures und LiipTestBundle nutzt nicht den ODM Fixture Loader.
        // Daher ergänzen wir den Loader um die ODM Fixtures.
        $fixturesLoader = static::getContainer()->get('doctrine.fixtures.loader');
        foreach ($fixtures as $fixture) {
            $fixturesLoader->addFixture(new $fixture());
        }

        // add all your fixtures classes that implement
        // Doctrine\Common\DataFixtures\FixtureInterface
        $this->databaseTool = static::getContainer()->get(DatabaseToolCollection::class)->get(null, 'doctrine_mongodb');
        $this->databaseTool->loadFixtures($fixtures);
alexislefebvre commented 6 months ago

Thanks!

You can add a mongo service to run tests on your local environment: see https://github.com/liip/LiipTestFixturesBundle/blob/2.x/docker-compose.yml and https://github.com/liip/LiipTestFixturesBundle/blob/2.x/doc/contributing.md

possi commented 6 months ago

You can add a mongo service to run tests on your local environment: see https://github.com/liip/LiipTestFixturesBundle/blob/2.x/docker-compose.yml and https://github.com/liip/LiipTestFixturesBundle/blob/2.x/doc/contributing.md

Thanks for the hint. I could run all test within the docker for PHP 8.3 and PHP 7.4 (using skip).

possi commented 6 months ago

@alexislefebvre I changed php-cs-fixer again (copy-n-paste fail on my end). I allowed doctrine mongodb bundle ^5.0 as dependency to support symfony 7.0

But I have no idea why the tests fail, that should work (like https://github.com/liip/LiipTestFixturesBundle/actions/runs/8200830170/job/22436570853?pr=275) The mongodb service container is initialized, the hostname should be resolveable.

alexislefebvre commented 6 months ago

@alexislefebvre I changed php-cs-fixer again (copy-n-paste fail on my end). I allowed doctrine mongodb bundle ^5.0 as dependency to support symfony 7.0

But I have no idea why the tests fail, that should work (like https://github.com/liip/LiipTestFixturesBundle/actions/runs/8200830170/job/22436570853?pr=275) The mongodb service container is initialized, the hostname should be resolveable.

It should work by adding mongodb here: https://github.com/liip/LiipTestFixturesBundle/blob/eb137138615450f067a9afa78887476783e126a2/.github/workflows/tests.yml#L122

possi commented 6 months ago

🤦 so obvious... Thanks.

alexislefebvre commented 6 months ago

Tests are green. :tada:

Please apply the changes suggested by PHP-CS-Fixer.

alexislefebvre commented 6 months ago

Thanks a lot! Here is the last release, it contains these changes: https://github.com/liip/LiipTestFixturesBundle/releases/tag/2.8.0