From 158b26914c0c6f94c370609d5cd7cf7acfa1c794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 27 Aug 2022 22:15:36 +0200 Subject: [PATCH] Address DBAL deprecations listTableDetails() has been deprecated in favor of getTable(). createSchema() has been deprecated in favor of introspectSchema() --- lib/Doctrine/ORM/Tools/SchemaTool.php | 17 +++++++++++++---- .../Tests/ORM/Functional/Ticket/GH6823Test.php | 11 +++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 3f3e0ac3af5..18e14f718ea 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -834,8 +834,10 @@ public function dropDatabase(): void */ public function getDropDatabaseSQL(): array { + $method = method_exists(AbstractSchemaManager::class, 'introspectSchema') ? 'introspectSchema' : 'createSchema'; + return $this->schemaManager - ->createSchema() + ->$method() ->toDropSql($this->platform); } @@ -850,7 +852,10 @@ public function getDropSchemaSQL(array $classes): array { $schema = $this->getSchemaFromMetadata($classes); - $deployedSchema = $this->schemaManager->createSchema(); + $method = method_exists(AbstractSchemaManager::class, 'introspectSchema') ? + 'introspectSchema' : + 'createSchema'; + $deployedSchema = $this->schemaManager->$method(); foreach ($schema->getTables() as $table) { if (! $deployedSchema->hasTable($table->getName())) { @@ -934,8 +939,12 @@ private function createSchemaForComparison(Schema $toSchema): Schema $config = $connection->getConfiguration(); $previousFilter = $config->getSchemaAssetsFilter(); + $method = method_exists(AbstractSchemaManager::class, 'introspectSchema') ? + 'introspectSchema' : + 'createSchema'; + if ($previousFilter === null) { - return $this->schemaManager->createSchema(); + return $this->schemaManager->$method(); } // whitelist assets we already know about in $toSchema, use the existing filter otherwise @@ -946,7 +955,7 @@ private function createSchemaForComparison(Schema $toSchema): Schema }); try { - return $this->schemaManager->createSchema(); + return $this->schemaManager->$method(); } finally { // restore schema assets filter $config->setSchemaAssetsFilter($previousFilter); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6823Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6823Test.php index aa557150892..73f237aa306 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6823Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6823Test.php @@ -16,6 +16,8 @@ use Doctrine\ORM\Mapping\Table; use Doctrine\Tests\OrmFunctionalTestCase; +use function method_exists; + class GH6823Test extends OrmFunctionalTestCase { public function testCharsetCollationWhenCreatingForeignRelations(): void @@ -31,27 +33,28 @@ public function testCharsetCollationWhenCreatingForeignRelations(): void ); $schemaManager = $this->createSchemaManager(); + $method = method_exists($schemaManager, 'getTable') ? 'getTable' : 'listTableDetails'; /* gh6823_user.group_id should use charset ascii and collation * ascii_general_ci, because that is what gh6823_group.id falls back to */ - $userGroupIdOptions = $schemaManager->listTableDetails('gh6823_user')->getColumn('group_id')->toArray(); + $userGroupIdOptions = $schemaManager->$method('gh6823_user')->getColumn('group_id')->toArray(); self::assertSame('ascii', $userGroupIdOptions['charset']); self::assertSame('ascii_general_ci', $userGroupIdOptions['collation']); /* gh6823_user.status_id should use charset latin1 and collation * latin1_bin, because that is what gh6823_status.id uses */ - $userStatusIdOptions = $schemaManager->listTableDetails('gh6823_user')->getColumn('status_id')->toArray(); + $userStatusIdOptions = $schemaManager->$method('gh6823_user')->getColumn('status_id')->toArray(); self::assertSame('latin1', $userStatusIdOptions['charset']); self::assertSame('latin1_bin', $userStatusIdOptions['collation']); /* gh6823_user_tags.user_id should use charset utf8mb4 and collation * utf8mb4_bin, because that is what gh6823_user.id falls back to */ - $userTagsUserIdOptions = $schemaManager->listTableDetails('gh6823_user_tags')->getColumn('user_id')->toArray(); + $userTagsUserIdOptions = $schemaManager->$method('gh6823_user_tags')->getColumn('user_id')->toArray(); self::assertSame('utf8mb4', $userTagsUserIdOptions['charset']); self::assertSame('utf8mb4_bin', $userTagsUserIdOptions['collation']); /* gh6823_user_tags.tag_id should use charset latin1 and collation * latin1_bin, because that is what gh6823_tag.id falls back to */ - $userTagsTagIdOption = $schemaManager->listTableDetails('gh6823_user_tags')->getColumn('tag_id')->toArray(); + $userTagsTagIdOption = $schemaManager->$method('gh6823_user_tags')->getColumn('tag_id')->toArray(); self::assertSame('latin1', $userTagsTagIdOption['charset']); self::assertSame('latin1_bin', $userTagsTagIdOption['collation']); }