From d066f24bbb386f5c4796a2dfd5229a81caa92cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Sat, 26 Sep 2026 16:54:52 +0200 Subject: [PATCH 1/2] IBX-11939: Adapted OrmEntitiesSchemaSubscriber and its test to 5.0 Uses 5.0's readonly class / promoted constructor style, passes array_values() of the foreign key columns (DBAL 4 requires a list), and the test uses APIs present in both DBAL 3 and 4 (getCreateTablesSQL(), connection-provided SQLite platform) with XSD validation enabled, so it carries over to 6.0 unchanged. --- .../OrmEntitiesSchemaSubscriber.php | 40 +++++--------- .../OrmEntitiesSchemaSubscriberTest.php | 54 ++++++++----------- 2 files changed, 35 insertions(+), 59 deletions(-) diff --git a/src/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriber.php b/src/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriber.php index bd420da371..f61bb43b36 100644 --- a/src/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriber.php +++ b/src/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriber.php @@ -35,21 +35,15 @@ * * Tables already present in the schema are left as they are. */ -final class OrmEntitiesSchemaSubscriber implements EventSubscriberInterface +final readonly class OrmEntitiesSchemaSubscriber implements EventSubscriberInterface { - private EntityManagerInterface $entityManager; - - /** @var list */ - private array $entityClasses; - /** * @param list $entityClasses */ - public function __construct(EntityManagerInterface $entityManager, array $entityClasses) - { - $this->entityManager = $entityManager; - $this->entityClasses = $entityClasses; - } + public function __construct( + private EntityManagerInterface $entityManager, + private array $entityClasses + ) {} public static function getSubscribedEvents(): array { @@ -62,9 +56,7 @@ public function onBuildSchema(SchemaBuilderEvent $event): void { $metadataFactory = $this->entityManager->getMetadataFactory(); $classMetadata = array_map( - static function (string $class) use ($metadataFactory): ClassMetadata { - return $metadataFactory->getMetadataFor($class); - }, + static fn (string $class): ClassMetadata => $metadataFactory->getMetadataFor($class), $this->entityClasses, ); @@ -77,9 +69,7 @@ static function (string $class) use ($metadataFactory): ClassMetadata { // own table, regardless of which classes were actually requested here. Only transplant the // tables that genuinely belong to the requested entities. $ownTableNames = array_map( - static function (ClassMetadata $metadata): string { - return $metadata->getTableName(); - }, + static fn (ClassMetadata $metadata): string => $metadata->getTableName(), $classMetadata, ); @@ -97,11 +87,7 @@ static function (ClassMetadata $metadata): string { } $ownSequenceNames = array_filter(array_map( - static function (ClassMetadata $metadata): ?string { - return isset($metadata->sequenceGeneratorDefinition['sequenceName']) - ? $metadata->sequenceGeneratorDefinition['sequenceName'] - : null; - }, + static fn (ClassMetadata $metadata): ?string => $metadata->sequenceGeneratorDefinition['sequenceName'] ?? null, $classMetadata, )); @@ -129,8 +115,10 @@ static function (ClassMetadata $metadata): ?string { * SchemaImporter uses when building a table from a parsed Yaml array, just reading from an * already-built Table here instead. */ - private function copyTable(Table $source, Table $target): void - { + private function copyTable( + Table $source, + Table $target + ): void { foreach ($source->getColumns() as $column) { $options = [ 'length' => $column->getLength(), @@ -170,8 +158,8 @@ private function copyTable(Table $source, Table $target): void foreach ($source->getForeignKeys() as $foreignKey) { $target->addForeignKeyConstraint( $foreignKey->getForeignTableName(), - $foreignKey->getUnquotedLocalColumns(), - $foreignKey->getUnquotedForeignColumns(), + array_values($foreignKey->getUnquotedLocalColumns()), + array_values($foreignKey->getUnquotedForeignColumns()), $foreignKey->getOptions(), $foreignKey->getName(), ); diff --git a/tests/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriberTest.php b/tests/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriberTest.php index 55951b01cb..cdfd5fe3c5 100644 --- a/tests/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriberTest.php +++ b/tests/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriberTest.php @@ -11,13 +11,11 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Platforms\MySQL57Platform; -use Doctrine\DBAL\Platforms\PostgreSQL94Platform; -use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\MySQLPlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Sequence; -use Doctrine\DBAL\Schema\Table; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; @@ -49,9 +47,10 @@ final class OrmEntitiesSchemaSubscriberTest extends TestCase protected function setUp(): void { $configuration = new Configuration(); - $configuration->setMetadataDriverImpl(new SimplifiedXmlDriver([ - __DIR__ . '/Fixtures/orm' => 'Ibexa\Tests\Bundle\RepositoryInstaller\Event\Subscriber\Fixtures\Entity', - ])); + $configuration->setMetadataDriverImpl(new SimplifiedXmlDriver( + [__DIR__ . '/Fixtures/orm' => 'Ibexa\Tests\Bundle\RepositoryInstaller\Event\Subscriber\Fixtures\Entity'], + isXsdValidationEnabled: true, + )); $configuration->setProxyDir(sys_get_temp_dir()); $configuration->setProxyNamespace('Ibexa\Tests\Bundle\RepositoryInstaller\Event\Subscriber\Proxies'); @@ -77,13 +76,14 @@ public function testAddsTablesOfListedEntitiesAsSchemaToolGeneratesThem(Abstract } /** - * @return iterable + * @return iterable */ public static function providePlatforms(): iterable { - yield 'MySQL' => [new MySQL57Platform()]; - yield 'PostgreSQL' => [new PostgreSQL94Platform()]; - yield 'SQLite' => [new SqlitePlatform()]; + yield 'MySQL' => [new MySQLPlatform()]; + yield 'PostgreSQL' => [new PostgreSQLPlatform()]; + // The SQLite platform class was renamed between DBAL 3 and 4 - let DBAL pick it. + yield 'SQLite' => [DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true])->getDatabasePlatform()]; } public function testAddsSequencesOfListedEntitiesAsSchemaToolGeneratesThem(): void @@ -123,9 +123,7 @@ public function testLeavesTablesAlreadyInTheSchemaUntouched(): void $schema = $this->dispatch($schema); $columnNames = array_map( - static function (Column $column): string { - return $column->getName(); - }, + static fn (Column $column): string => $column->getName(), array_values($schema->getTable('test_orm_category')->getColumns()), ); @@ -138,27 +136,19 @@ private function getSchemaToolSchema(): Schema $metadataFactory = $this->entityManager->getMetadataFactory(); return (new SchemaTool($this->entityManager))->getSchemaFromMetadata(array_map( - static function (string $class) use ($metadataFactory) { - return $metadataFactory->getMetadataFor($class); - }, + static fn (string $class) => $metadataFactory->getMetadataFor($class), self::ENTITY_CLASSES, )); } /** - * @return array> + * @return list */ - private function getCreateTablesSql(Schema $schema, AbstractPlatform $platform): array - { - return array_map( - static function (Table $table) use ($platform): array { - return $platform->getCreateTableSQL( - $table, - AbstractPlatform::CREATE_INDEXES | AbstractPlatform::CREATE_FOREIGNKEYS, - ); - }, - $schema->getTables(), - ); + private function getCreateTablesSql( + Schema $schema, + AbstractPlatform $platform + ): array { + return $platform->getCreateTablesSQL($schema->getTables()); } /** @@ -168,12 +158,10 @@ static function (Table $table) use ($platform): array { */ private function getCreateSequencesSql(Schema $schema): array { - $platform = new PostgreSQL94Platform(); + $platform = new PostgreSQLPlatform(); return array_map( - static function (Sequence $sequence) use ($platform): string { - return $platform->getCreateSequenceSQL($sequence); - }, + static fn (Sequence $sequence): string => $platform->getCreateSequenceSQL($sequence), $schema->getSequences(), ); } From 58534c73f6c423aa21e7caebc3d8a95168037745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Sat, 26 Sep 2026 17:40:16 +0200 Subject: [PATCH 2/2] IBX-11939: Fixed code style of OrmEntitiesSchemaSubscriber's constructor --- .../Event/Subscriber/OrmEntitiesSchemaSubscriber.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriber.php b/src/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriber.php index f61bb43b36..8ddf981eba 100644 --- a/src/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriber.php +++ b/src/bundle/RepositoryInstaller/Event/Subscriber/OrmEntitiesSchemaSubscriber.php @@ -43,7 +43,8 @@ public function __construct( private EntityManagerInterface $entityManager, private array $entityClasses - ) {} + ) { + } public static function getSubscribedEvents(): array {