Skip to content

Commit

Permalink
Fully address Comparator constructor deprecation (#1239)
Browse files Browse the repository at this point in the history
* Address Connection::getWrappedConnection() deprecation

* Fully address Comparator constructor deprecation
  • Loading branch information
greg0ire committed Jan 28, 2022
1 parent e17a946 commit e7df670
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
Expand Up @@ -26,6 +26,7 @@

use function array_change_key_case;
use function floatval;
use function method_exists;
use function round;
use function sprintf;
use function strlen;
Expand Down Expand Up @@ -184,7 +185,9 @@ private function needsUpdate(Table $expectedTable): ?TableDiff
return null;
}

$comparator = new Comparator();
$comparator = method_exists($this->schemaManager, 'createComparator') ?
$this->schemaManager->createComparator() :
new Comparator();
$currentTable = $this->schemaManager->listTableDetails($this->configuration->getTableName());
$diff = $comparator->diffTable($currentTable, $expectedTable);

Expand Down
3 changes: 2 additions & 1 deletion phpstan-common.neon.dist
Expand Up @@ -24,7 +24,7 @@ parameters:
message: '~^Method Doctrine\\Migrations\\Tests\\Stub\\DoctrineRegistry::getService\(\) should return Doctrine\\Persistence\\ObjectManager but returns Doctrine\\DBAL\\Connection\|Doctrine\\ORM\\EntityManager~'
path: tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php

# https://github.com/phpstan/phpstan/issues/5982
# https://github.com/phpstan/phpstan/issues/5982
-
message: '~^Cannot call method getWrappedConnection\(\) on class-string\|object\.~'
path: lib/Doctrine/Migrations/Tools/TransactionHelper.php
Expand All @@ -35,6 +35,7 @@ parameters:
paths:
- tests/Doctrine/Migrations/Tests/Generator/ClassNameGeneratorTest.php


symfony:
console_application_loader: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/doctrine-migrations-phpstan-app.php
includes:
Expand Down
11 changes: 11 additions & 0 deletions phpstan-dbal-3.neon.dist
Expand Up @@ -30,12 +30,23 @@ parameters:
- lib/Doctrine/Migrations/Generator/DiffGenerator.php
- lib/Doctrine/Migrations/Provider/DBALSchemaDiffProvider.php

-
message: '~Call to deprecated method getWrappedConnection~'
paths:
- tests/Doctrine/Migrations/Tests/Metadata/Storage/TableMetadataStorageTest.php

-
message: "~Call to function method_exists.*'getNativeConnection' will always evaluate to true.~"
path: tests/Doctrine/Migrations/Tests/Metadata/Storage/TableMetadataStorageTest.php

-
message: "~Call to function method_exists.*'createComparator' will always evaluate to true.~"
paths:
- lib/Doctrine/Migrations/Generator/DiffGenerator.php
- lib/Doctrine/Migrations/Provider/DBALSchemaDiffProvider.php
- lib/Doctrine/Migrations/Metadata/Storage/TableMetadataStorage.php
- tests/Doctrine/Migrations/Tests/Generator/DiffGeneratorTest.php
- tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php

# That method will no longer be static in the future
-
Expand Down
Expand Up @@ -27,6 +27,7 @@
use Doctrine\Migrations\Version\Version;
use PHPUnit\Framework\TestCase;

use function method_exists;
use function sprintf;

class TableMetadataStorageTest extends TestCase
Expand Down Expand Up @@ -216,9 +217,14 @@ public function testCompleteWillAlwaysCastTimeToInteger(): void
$config = new TableMetadataStorageConfiguration();
$executedAt = new DateTimeImmutable('2010-01-05 10:30:21');

$connection = $this->getSqliteConnection();
$pdo = method_exists($connection, 'getNativeConnection')
? $connection->getNativeConnection()
: $connection->getWrappedConnection();

$connection = $this->getMockBuilder(Connection::class)
->setConstructorArgs([
['pdo' => $this->getSqliteConnection()->getWrappedConnection()],
['pdo' => $pdo],
new SQLiteDriver(),
])
->onlyMethods(['insert'])
Expand Down
Expand Up @@ -39,6 +39,7 @@

use function getcwd;
use function in_array;
use function method_exists;
use function sprintf;
use function strpos;
use function trim;
Expand Down Expand Up @@ -500,14 +501,18 @@ protected function setUp(): void

private function alterMetadataTable(): void
{
$originalTable = $this->connection->getSchemaManager()
$schemaManager = $this->connection->getSchemaManager();
$originalTable = $schemaManager
->listTableDetails($this->metadataConfiguration->getTableName());

$modifiedTable = clone $originalTable;
$modifiedTable->addColumn('extra', Types::STRING, ['notnull' => false]);

$comparator = new Comparator();
$diff = $comparator->diffTable($originalTable, $modifiedTable);
$comparator = method_exists($schemaManager, 'createComparator') ?
$schemaManager->createComparator() :
new Comparator();

$diff = $comparator->diffTable($originalTable, $modifiedTable);
if (! ($diff instanceof TableDiff)) {
return;
}
Expand Down

0 comments on commit e7df670

Please sign in to comment.