Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump DBAL to 3.5 and remove BC hacks #10173

Merged
merged 1 commit into from
Oct 25, 2022
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
"ext-ctype": "*",
"doctrine/collections": "^2.0",
"doctrine/common": "^3.3",
"doctrine/dbal": "^3.4",
"doctrine/dbal": "^3.5",
"doctrine/deprecations": "^0.5.3 || ^1",
"doctrine/event-manager": "^1.2 || ^2",
"doctrine/inflector": "^1.4 || ^2.0",
35 changes: 6 additions & 29 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
@@ -340,8 +340,7 @@ public function getSchemaFromMetadata(array $classes): Schema
$uniqIndex = new Index($indexName, $this->getIndexColumns($class, $indexData), true, false, [], $indexData['options'] ?? []);

foreach ($table->getIndexes() as $tableIndexName => $tableIndex) {
$method = method_exists($tableIndex, 'isFulfilledBy') ? 'isFulfilledBy' : 'isFullfilledBy';
if ($tableIndex->$method($uniqIndex)) {
if ($tableIndex->isFulfilledBy($uniqIndex)) {
$table->dropIndex($tableIndexName);
break;
}
@@ -502,9 +501,8 @@ private function gatherColumn(
}

if ($table->hasColumn($columnName)) {
$method = method_exists($table, 'modifyColumn') ? 'modifyColumn' : 'changeColumn';
// required in some inheritance scenarios
$table->$method($columnName, $options);
$table->modifyColumn($columnName, $options);
} else {
$table->addColumn($columnName, $columnType, $options);
}
@@ -838,12 +836,8 @@ public function dropDatabase(): void
*/
public function getDropDatabaseSQL(): array
{
$method = method_exists(AbstractSchemaManager::class, 'introspectSchema') ?
'introspectSchema' :
'createSchema';

return $this->schemaManager
->$method()
->introspectSchema()
->toDropSql($this->platform);
}

@@ -858,7 +852,7 @@ public function getDropSchemaSQL(array $classes): array
{
$schema = $this->getSchemaFromMetadata($classes);

$deployedSchema = $this->introspectSchema();
$deployedSchema = $this->schemaManager->introspectSchema();

foreach ($schema->getTables() as $table) {
if (! $deployedSchema->hasTable($table->getName())) {
@@ -949,10 +943,6 @@ public function getUpdateSchemaSql(array $classes, bool $saveMode = false): arra
return $schemaDiff->toSaveSql($this->platform);
}

if (! method_exists(AbstractPlatform::class, 'getAlterSchemaSQL')) {
return $schemaDiff->toSql($this->platform);
}

return $this->platform->getAlterSchemaSQL($schemaDiff);
}

@@ -967,12 +957,8 @@ 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->introspectSchema();
return $this->schemaManager->introspectSchema();
}

// whitelist assets we already know about in $toSchema, use the existing filter otherwise
@@ -983,19 +969,10 @@ private function createSchemaForComparison(Schema $toSchema): Schema
});

try {
return $this->introspectSchema();
return $this->schemaManager->introspectSchema();
} finally {
// restore schema assets filter
$config->setSchemaAssetsFilter($previousFilter);
}
}

private function introspectSchema(): Schema
{
$method = method_exists($this->schemaManager, 'introspectSchema')
? 'introspectSchema'
: 'createSchema';

return $this->schemaManager->$method();
}
}
5 changes: 0 additions & 5 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -132,11 +132,6 @@
<exclude-pattern>tests/Doctrine/Tests/Models/DDC1872/DDC1872ExampleTrait.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse">
<!-- The Sniff does not understand native intersection types -->
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<rule name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
4 changes: 0 additions & 4 deletions phpstan-dbal4.neon
Original file line number Diff line number Diff line change
@@ -28,7 +28,3 @@ parameters:
message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Schema\\\\SchemaDiff\\:\\:toSaveSql\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/Tools/SchemaTool.php
-
message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Schema\\\\SchemaDiff\\:\\:toSql\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ORM/Tools/SchemaTool.php
3 changes: 1 addition & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -173,9 +173,8 @@
</ArgumentTypeCoercion>
</file>
<file src="lib/Doctrine/ORM/EntityManager.php">
<ArgumentTypeCoercion occurrences="2">
<ArgumentTypeCoercion occurrences="1">
<code>$className</code>
<code>$connection</code>
</ArgumentTypeCoercion>
<InvalidReturnStatement occurrences="10">
<code>$entity</code>
31 changes: 1 addition & 30 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -30,10 +30,9 @@
<errorLevel type="suppress">
<!-- Compatibility with DBAL 3 -->
<referencedMethod name="Doctrine\DBAL\Connection::getEventManager"/>
<!-- Remove on 3.0.x -->
<referencedMethod name="Doctrine\DBAL\Schema\Schema::visit"/>
<!-- Remove on 3.0.x -->
<referencedMethod name="Doctrine\DBAL\Schema\SchemaDiff::toSaveSql"/>
<referencedMethod name="Doctrine\DBAL\Schema\SchemaDiff::toSql"/>
<referencedMethod name="Doctrine\ORM\ORMSetup::createDefaultAnnotationDriver"/>
</errorLevel>
</DeprecatedMethod>
@@ -49,18 +48,6 @@
<file name="lib/Doctrine/ORM/PersistentCollection.php"/>
</errorLevel>
</DocblockTypeContradiction>
<InvalidArgument>
<errorLevel type="suppress">
<!-- Argument type changes in DBAL 3.2 -->
<referencedFunction name="Doctrine\DBAL\Cache\QueryCacheProfile::__construct"/>
</errorLevel>
</InvalidArgument>
<InvalidClass>
<errorLevel type="suppress">
<!-- Class name changes in DBAL 3. -->
<referencedClass name="Doctrine\DBAL\Platforms\PostgreSQLPlatform" />
</errorLevel>
</InvalidClass>
<LessSpecificReturnStatement>
<errorLevel type="suppress">
<!-- In DBAL 4, column precision is nullable. See https://github.com/doctrine/dbal/pull/3511 -->
@@ -79,14 +66,6 @@
<file name="lib/Doctrine/ORM/Mapping/ReflectionReadonlyProperty.php"/>
</errorLevel>
</MethodSignatureMismatch>
<MissingDependency>
<errorLevel type="suppress">
<!-- DBAL 3.2 forward compatibility -->
<file name="lib/Doctrine/ORM/Internal/SQLResultCasing.php"/>
<file name="lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php"/>
<file name="lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php"/>
</errorLevel>
</MissingDependency>
<MissingParamType>
<errorLevel type="suppress">
<!-- Persistence 2 compatibility -->
@@ -133,14 +112,6 @@
</TypeDoesNotContainType>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="Doctrine\Common\Cache\ApcCache"/>
<referencedClass name="Doctrine\Common\Cache\ArrayCache"/>
<referencedClass name="Doctrine\Common\Cache\XcacheCache"/>

<!-- DBAL 3.2 forward compatibility -->
<referencedClass name="Doctrine\DBAL\Platforms\PostgreSQLPlatform"/>
<referencedClass name="Doctrine\DBAL\Platforms\SQLServerPlatform"/>

<!-- Persistence 2 compatibility -->
<referencedClass name="Doctrine\Persistence\ObjectManagerAware"/>

8 changes: 1 addition & 7 deletions tests/Doctrine/Tests/DbalTypes/CustomIdObjectType.php
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

use function method_exists;

class CustomIdObjectType extends Type
{
public const NAME = 'CustomIdObject';
@@ -34,11 +32,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): CustomIdO
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if (method_exists($platform, 'getStringTypeDeclarationSQL')) {
return $platform->getStringTypeDeclarationSQL($column);
}

return $platform->getVarcharTypeDeclarationSQL($column);
return $platform->getStringTypeDeclarationSQL($column);
}

public function getName(): string
17 changes: 1 addition & 16 deletions tests/Doctrine/Tests/DbalTypes/Rot13Type.php
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

use function method_exists;
use function str_rot13;

/**
@@ -48,21 +47,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): string|nu
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if (method_exists($platform, 'getStringTypeDeclarationSQL')) {
return $platform->getStringTypeDeclarationSQL($column);
}

return $platform->getVarcharTypeDeclarationSQL($column);
}

/**
* {@inheritdoc}
*
* @return int|null
*/
public function getDefaultLength(AbstractPlatform $platform)
{
return $platform->getVarcharDefaultLength();
return $platform->getStringTypeDeclarationSQL($column);
}

public function getName(): string
4 changes: 0 additions & 4 deletions tests/Doctrine/Tests/ORM/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -4,9 +4,6 @@

namespace Doctrine\Tests\ORM;

use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\Psr6\CacheAdapter;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Configuration;
@@ -17,7 +14,6 @@
use Doctrine\ORM\Mapping\NamingStrategy;
use Doctrine\ORM\Mapping\QuoteStrategy;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Tests\DoctrineTestCase;
use Doctrine\Tests\Models\DDC753\DDC753CustomRepository;
4 changes: 0 additions & 4 deletions tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php
Original file line number Diff line number Diff line change
@@ -5,10 +5,6 @@
namespace Doctrine\Tests\ORM\Functional;

use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\Persistence\Proxy;
use Doctrine\Tests\Models\CMS\CmsAddress;
use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\OrmFunctionalTestCase;
7 changes: 1 addition & 6 deletions tests/Doctrine/Tests/ORM/Functional/GH5988Test.php
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
use Doctrine\Tests\DbalTypes\CustomIdObject;
use Doctrine\Tests\OrmFunctionalTestCase;

use function method_exists;
use function str_replace;

/**
@@ -79,11 +78,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): CustomIdO
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if (method_exists($platform, 'getStringTypeDeclarationSQL')) {
return $platform->getStringTypeDeclarationSQL($column);
}

return $platform->getVarcharTypeDeclarationSQL($column);
return $platform->getStringTypeDeclarationSQL($column);
}

public function getName(): string
Original file line number Diff line number Diff line change
@@ -4,12 +4,9 @@

namespace Doctrine\Tests\ORM\Functional\SchemaTool;

use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Tests\OrmFunctionalTestCase;

use function method_exists;

/**
* Functional tests for the Class Table Inheritance mapping strategy.
*/
@@ -24,10 +21,7 @@ protected function setUp(): void
/** @group DDC-966 */
public function testGeneratedSchema(): Schema
{
$method = method_exists(AbstractSchemaManager::class, 'introspectSchema') ?
'introspectSchema' :
'createSchema';
$schema = $this->createSchemaManager()->$method();
$schema = $this->createSchemaManager()->introspectSchema();

self::assertTrue($schema->hasTable('company_contracts'));

13 changes: 2 additions & 11 deletions tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php
Original file line number Diff line number Diff line change
@@ -4,16 +4,12 @@

namespace Doctrine\Tests\ORM\Functional\SchemaTool;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\Tests\Models;
use Doctrine\Tests\OrmFunctionalTestCase;

use function array_filter;
use function implode;
use function method_exists;
use function str_contains;

use const PHP_EOL;
@@ -69,17 +65,12 @@ public function assertCreatedSchemaNeedsNoUpdates(string ...$classes): void

$sm = $this->createSchemaManager();

$method = method_exists(AbstractSchemaManager::class, 'introspectSchema') ?
'introspectSchema' :
'createSchema';
$fromSchema = $sm->$method();
$fromSchema = $sm->introspectSchema();
$toSchema = $this->getSchemaForModels(...$classes);
$comparator = $sm->createComparator();
$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);

$sql = method_exists(AbstractPlatform::class, 'getAlterSchemaSQL') ?
$this->_em->getConnection()->getDatabasePlatform()->getAlterSchemaSQL($schemaDiff) :
$schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform());
$sql = $this->_em->getConnection()->getDatabasePlatform()->getAlterSchemaSQL($schemaDiff);

$sql = array_filter($sql, static fn ($sql) => ! str_contains($sql, 'DROP'));

7 changes: 1 addition & 6 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
use function explode;
use function implode;
use function is_array;
use function method_exists;
use function sprintf;
use function strtolower;

@@ -129,11 +128,7 @@ class DDC2012TsVectorType extends Type
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if (method_exists($platform, 'getStringTypeDeclarationSQL')) {
return $platform->getStringTypeDeclarationSQL($column);
}

return $platform->getVarcharTypeDeclarationSQL($column);
return $platform->getStringTypeDeclarationSQL($column);
}

/**
7 changes: 1 addition & 6 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2224Test.php
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
use Doctrine\Tests\OrmFunctionalTestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

use function method_exists;
use function sprintf;

/** @group DDC-2224 */
@@ -52,11 +51,7 @@ class DDC2224Type extends Type
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if (method_exists($platform, 'getStringTypeDeclarationSQL')) {
return $platform->getStringTypeDeclarationSQL($column);
}

return $platform->getVarcharTypeDeclarationSQL($column);
return $platform->getStringTypeDeclarationSQL($column);
}

public function getName(): string
Loading