Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Allowed schema & fixture files be accessed from Kernel #242

Closed
wants to merge 1 commit into from

Conversation

Steveb-p
Copy link
Contributor

Question Answer
JIRA issue N/A
Type improvement
Target Ibexa version v3.3
BC breaks no

Request for comments

This change proposes one of possible ways of exposing schema & fixture files for consumption in our & third party packages, so they can be coupled with https://github.com/dmaicher/doctrine-test-bundle, and subsequently improve the performance of database-related tests.

This solution directly provides new methods to IbexaTestKernel. A different solution I've come up would be to provide schema & fixture registry as a test service.

I have created a local test to change the performance impact on testing for a MySQL database (mind you, using a normal filesystem). The results are as follows:

without transaction bundle & database bootstraping
image

with transaction bundle & database bootstraping
(8 second execution)
image

Note that these include ~2-3 sec of container compilation & database setup, which means that each tests is reduced from ~300ms to a few ms in execution.

Samples bootstrapping (executed in context of ibexa migrations, used for result above)

<?php

use eZ\Publish\API\Repository\Tests\LegacySchemaImporter;
use eZ\Publish\SPI\Tests\Persistence\FixtureImporter;
use eZ\Publish\SPI\Tests\Persistence\YamlFixture;

require_once __DIR__.'/../vendor/autoload.php';

function bootstrap(): void
{
    $kernel = new \Ibexa\Platform\Tests\Bundle\Migration\IbexaTestKernel('test', true);
    $kernel->boot();

    $application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
    $application->setAutoExit(false);

    $application->run(new \Symfony\Component\Console\Input\ArrayInput([
        'command' => 'doctrine:database:drop',
        '--if-exists' => '1',
        '--force' => '1',
    ]));

    $application->run(new \Symfony\Component\Console\Input\ArrayInput([
        'command' => 'doctrine:database:create',
    ]));

    /** @var \eZ\Publish\API\Repository\Tests\LegacySchemaImporter $schemaImporter */
    $schemaImporter = $kernel->getContainer()->get(LegacySchemaImporter::class);
    foreach ($kernel->getSchemaFiles() as $schemaFile) {
        $schemaImporter->importSchema($schemaFile);
    }

    /** @var \eZ\Publish\SPI\Tests\Persistence\FixtureImporter $fixtureImporter */
    $fixtureImporter = $kernel->getContainer()->get(FixtureImporter::class);
    foreach ($kernel->getFixtures() as $fixture) {
        $fixtureImporter->import($fixture);
    }

    $kernel->shutdown();
}

bootstrap();

Checklist:

  • Provided PR description.
  • Tested the solution manually.
  • Provided automated test coverage.
  • Checked that target branch is set correctly (master for features, the oldest supported for bugs).
  • Ran PHP CS Fixer for new PHP code (use $ composer fix-cs).
  • Asked for a review (ping @ezsystems/engineering-team).

@sonarcloud
Copy link

sonarcloud bot commented Oct 10, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Steveb-p
Copy link
Contributor Author

Steveb-p commented Feb 8, 2022

Made obsolete by #284

@Steveb-p Steveb-p closed this Feb 8, 2022
@Steveb-p Steveb-p deleted the allow-doctrine-test-bundle branch February 8, 2022 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant