Skip to content

Commit

Permalink
Address DBAL deprecations
Browse files Browse the repository at this point in the history
listTableDetails() has been deprecated in favor of getTable().
createSchema() has been deprecated in favor of introspectSchema()
  • Loading branch information
greg0ire committed Aug 29, 2022
1 parent 883c8c4 commit 158b269
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
17 changes: 13 additions & 4 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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())) {
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH6823Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']);
}
Expand Down

0 comments on commit 158b269

Please sign in to comment.