Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/contracts/Bootstrapper/SchemaInstallPath.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Test\Core\Bootstrapper;

use Ibexa\Bundle\RepositoryInstaller\Bootstrapper\DoctrineMigrationsSchemaHook;

/**
* Selects which of the two coexisting schema install paths a bootstrap exercises: the
* SchemaBuilderEvent one, through {@see DatabaseSchemaHook}, or the Doctrine Migrations one, through
* ibexa/core's {@see DoctrineMigrationsSchemaHook}. Exactly one of them installs the schema.
*
* Which path a run takes is up to the package, usually an environment variable its CI sets:
*
* ```php
* $doctrineMigrationsEnabled = getenv('IBEXA_TEST_SCHEMA_BUILDER_EVENT_ENABLED') === '0';
*
* (new Bootstrapper())->bootstrap(null, SchemaInstallPath::getBootstrapperOptions($doctrineMigrationsEnabled));
* ```
*/
final class SchemaInstallPath
{
/**
* @return array<class-string<HookInterface>, array<string, bool>>
*/
public static function getBootstrapperOptions(bool $doctrineMigrationsEnabled): array
{
return [
DatabaseSchemaHook::class => [DatabaseSchemaHook::OPTION_LOAD_SCHEMA => !$doctrineMigrationsEnabled],
DoctrineMigrationsSchemaHook::class => [
DoctrineMigrationsSchemaHook::OPTION_INSTALL_SCHEMA => $doctrineMigrationsEnabled,
],
];
}
}
54 changes: 54 additions & 0 deletions tests/contracts/Bootstrapper/SchemaInstallPathTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Contracts\Test\Core\Bootstrapper;

use Ibexa\Bundle\RepositoryInstaller\Bootstrapper\DoctrineMigrationsSchemaHook;
use Ibexa\Contracts\Test\Core\Bootstrapper\DatabaseSchemaHook;
use Ibexa\Contracts\Test\Core\Bootstrapper\SchemaInstallPath;
use PHPUnit\Framework\TestCase;

/**
* @covers \Ibexa\Contracts\Test\Core\Bootstrapper\SchemaInstallPath
*/
final class SchemaInstallPathTest extends TestCase
{
/**
* @dataProvider provideInstallPaths
*
* @param array<string, array<string, bool>> $expectedOptions
*/
public function testEnablesExactlyOneSchemaHook(
bool $doctrineMigrationsEnabled,
array $expectedOptions
): void {
self::assertSame($expectedOptions, SchemaInstallPath::getBootstrapperOptions($doctrineMigrationsEnabled));
}

/**
* @return iterable<string, array{bool, array<string, array<string, bool>>}>
*/
public static function provideInstallPaths(): iterable
{
yield 'SchemaBuilderEvent' => [
false,
[
DatabaseSchemaHook::class => [DatabaseSchemaHook::OPTION_LOAD_SCHEMA => true],
DoctrineMigrationsSchemaHook::class => [DoctrineMigrationsSchemaHook::OPTION_INSTALL_SCHEMA => false],
],
];

yield 'Doctrine Migrations' => [
true,
[
DatabaseSchemaHook::class => [DatabaseSchemaHook::OPTION_LOAD_SCHEMA => false],
DoctrineMigrationsSchemaHook::class => [DoctrineMigrationsSchemaHook::OPTION_INSTALL_SCHEMA => true],
],
];
}
}
Loading