From e6dc2f94ebfdfd11cb872568ed3811b43f144dea Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 15 Apr 2019 17:36:12 +0200 Subject: [PATCH 01/11] Remove deprecated json_array type --- UPGRADE.md | 4 + lib/Doctrine/DBAL/Schema/Comparator.php | 23 ---- .../DBAL/Schema/PostgreSqlSchemaManager.php | 2 +- lib/Doctrine/DBAL/Types/JsonArrayType.php | 48 ------- lib/Doctrine/DBAL/Types/Type.php | 4 - .../Schema/PostgreSqlSchemaManagerTest.php | 20 +-- .../SchemaManagerFunctionalTestCase.php | 123 ------------------ .../DBAL/Functional/TypeConversionTest.php | 4 +- .../Platforms/AbstractPlatformTestCase.php | 2 +- .../Tests/DBAL/Types/JsonArrayTest.php | 86 ------------ 10 files changed, 11 insertions(+), 305 deletions(-) delete mode 100644 lib/Doctrine/DBAL/Types/JsonArrayType.php delete mode 100644 tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php diff --git a/UPGRADE.md b/UPGRADE.md index 1dd6743e2a8..473a59eff7e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 3.0 +## BC BREAK Removed previously deprecated features + + * Removed `json_array` type and all associated hacks. + ## BC BREAK `Connection::ping()` returns `void`. `Connection::ping()` and `PingableConnection::ping()` no longer return a boolean value. They will throw an exception in case of failure. diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index f7712ec2da4..a59e71ad1bc 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -10,7 +10,6 @@ use function array_keys; use function array_map; use function array_merge; -use function array_shift; use function array_unique; use function assert; use function count; @@ -436,13 +435,6 @@ public function diffColumn(Column $column1, Column $column2) $changedProperties[] = $property; } - // This is a very nasty hack to make comparator work with the legacy json_array type, which should be killed in v3 - if ($this->isALegacyJsonComparison($properties1['type'], $properties2['type'])) { - array_shift($changedProperties); - - $changedProperties[] = 'comment'; - } - // Null values need to be checked additionally as they tell whether to create or drop a default value. // null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation. if (($properties1['default'] === null) !== ($properties2['default'] === null) @@ -505,21 +497,6 @@ public function diffColumn(Column $column1, Column $column2) return array_unique($changedProperties); } - /** - * TODO: kill with fire on v3.0 - * - * @deprecated - */ - private function isALegacyJsonComparison(Types\Type $one, Types\Type $other) : bool - { - if (! $one instanceof Types\JsonType || ! $other instanceof Types\JsonType) { - return false; - } - - return ( ! $one instanceof Types\JsonArrayType && $other instanceof Types\JsonArrayType) - || ( ! $other instanceof Types\JsonArrayType && $one instanceof Types\JsonArrayType); - } - /** * Finds the difference between the indexes $index1 and $index2. * diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 9a3025ae78b..3635ee46573 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -458,7 +458,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) $column->setPlatformOption('collation', $tableColumn['collation']); } - if (in_array($column->getType()->getName(), [Types::JSON_ARRAY, Types::JSON], true)) { + if ($column->getType()->getName() === Types::JSON) { $column->setPlatformOption('jsonb', $jsonb); } diff --git a/lib/Doctrine/DBAL/Types/JsonArrayType.php b/lib/Doctrine/DBAL/Types/JsonArrayType.php deleted file mode 100644 index 999433d0c79..00000000000 --- a/lib/Doctrine/DBAL/Types/JsonArrayType.php +++ /dev/null @@ -1,48 +0,0 @@ - GuidType::class, Types::INTEGER => IntegerType::class, Types::JSON => JsonType::class, - Types::JSON_ARRAY => JsonArrayType::class, Types::OBJECT => ObjectType::class, Types::SIMPLE_ARRAY => SimpleArrayType::class, Types::SMALLINT => SmallIntType::class, diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index c7080cb7a57..c52d5af4a7f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -386,10 +386,7 @@ public function testPartialIndexes() : void self::assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where')); } - /** - * @dataProvider jsonbColumnTypeProvider - */ - public function testJsonbColumn(string $type) : void + public function testJsonbColumn() : void { if (! $this->schemaManager->getDatabasePlatform() instanceof PostgreSQL94Platform) { $this->markTestSkipped('Requires PostgresSQL 9.4+'); @@ -398,26 +395,15 @@ public function testJsonbColumn(string $type) : void } $table = new Schema\Table('test_jsonb'); - $table->addColumn('foo', $type)->setPlatformOption('jsonb', true); + $table->addColumn('foo', Types::JSON)->setPlatformOption('jsonb', true); $this->schemaManager->dropAndCreateTable($table); $columns = $this->schemaManager->listTableColumns('test_jsonb'); - self::assertSame($type, $columns['foo']->getType()->getName()); + self::assertSame(Types::JSON, $columns['foo']->getType()->getName()); self::assertTrue($columns['foo']->getPlatformOption('jsonb')); } - /** - * @return mixed[][] - */ - public function jsonbColumnTypeProvider() : array - { - return [ - [Types::JSON], - [Types::JSON_ARRAY], - ]; - } - /** * @group DBAL-2427 */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index ecd2258e8d1..4e850c1be34 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1312,129 +1312,6 @@ public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() : void self::assertArrayHasKey('idx_3d6c147fdc58d6c', $indexes); } - /** - * @after - */ - public function removeJsonArrayTable() : void - { - if (! $this->schemaManager->tablesExist(['json_array_test'])) { - return; - } - - $this->schemaManager->dropTable('json_array_test'); - } - - /** - * @group 2782 - * @group 6654 - */ - public function testComparatorShouldReturnFalseWhenLegacyJsonArrayColumnHasComment() : void - { - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json_array'); - - $this->schemaManager->createTable($table); - - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); - - self::assertFalse($tableDiff); - } - - /** - * @group 2782 - * @group 6654 - */ - public function testComparatorShouldModifyOnlyTheCommentWhenUpdatingFromJsonArrayTypeOnLegacyPlatforms() : void - { - if ($this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { - $this->markTestSkipped('This test is only supported on platforms that do not have native JSON type.'); - } - - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json_array'); - - $this->schemaManager->createTable($table); - - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json'); - - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); - - self::assertInstanceOf(TableDiff::class, $tableDiff); - - $changedColumn = $tableDiff->changedColumns['parameters'] ?? $tableDiff->changedColumns['PARAMETERS']; - - self::assertSame(['comment'], $changedColumn->changedProperties); - } - - /** - * @group 2782 - * @group 6654 - */ - public function testComparatorShouldAddCommentToLegacyJsonArrayTypeThatDoesNotHaveIt() : void - { - if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { - $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); - } - - $this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON NOT NULL)'); - - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json_array'); - - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); - - self::assertInstanceOf(TableDiff::class, $tableDiff); - self::assertSame(['comment'], $tableDiff->changedColumns['parameters']->changedProperties); - } - - /** - * @group 2782 - * @group 6654 - */ - public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType() : void - { - if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { - $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); - } - - $this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)'); - - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json_array'); - - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); - - self::assertInstanceOf(TableDiff::class, $tableDiff); - self::assertSame(['notnull', 'comment'], $tableDiff->changedColumns['parameters']->changedProperties); - } - - /** - * @group 2782 - * @group 6654 - */ - public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayTypeEvenWhenPlatformHasJsonSupport() : void - { - if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { - $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); - } - - $this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)'); - - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json_array'); - - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); - - self::assertInstanceOf(TableDiff::class, $tableDiff); - self::assertSame(['notnull', 'comment'], $tableDiff->changedColumns['parameters']->changedProperties); - } - /** * @group 2782 * @group 6654 diff --git a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php index 6870cecfcd3..ccb3f3b59cb 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php @@ -33,7 +33,7 @@ protected function setUp() : void $table->addColumn('test_time', 'time', ['notnull' => false]); $table->addColumn('test_text', 'text', ['notnull' => false]); $table->addColumn('test_array', 'array', ['notnull' => false]); - $table->addColumn('test_json_array', 'json_array', ['notnull' => false]); + $table->addColumn('test_json', 'json', ['notnull' => false]); $table->addColumn('test_object', 'object', ['notnull' => false]); $table->addColumn('test_float', 'float', ['notnull' => false]); $table->addColumn('test_decimal', 'decimal', ['notnull' => false, 'scale' => 2, 'precision' => 10]); @@ -166,7 +166,7 @@ public static function toArrayProvider() : iterable { return [ 'array' => ['array', ['foo' => 'bar']], - 'json_array' => ['json_array', ['foo' => 'bar']], + 'json' => ['json', ['foo' => 'bar']], ]; } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index c289c9fcbd5..31c320f439b 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -880,7 +880,7 @@ public function testReturnsJsonTypeDeclarationSQL() : void $column = [ 'length' => 666, 'notnull' => true, - 'type' => Type::getType('json_array'), + 'type' => Type::getType('json'), ]; self::assertSame( diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php deleted file mode 100644 index baa8b953f48..00000000000 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ /dev/null @@ -1,86 +0,0 @@ -platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('json_array'); - } - - public function testReturnsBindingType() : void - { - self::assertSame(ParameterType::STRING, $this->type->getBindingType()); - } - - public function testReturnsName() : void - { - self::assertSame(Types::JSON_ARRAY, $this->type->getName()); - } - - public function testReturnsSQLDeclaration() : void - { - $this->platform->expects($this->once()) - ->method('getJsonTypeDeclarationSQL') - ->willReturn('TEST_JSON'); - - self::assertSame('TEST_JSON', $this->type->getSQLDeclaration([], $this->platform)); - } - - public function testJsonNullConvertsToPHPValue() : void - { - self::assertSame([], $this->type->convertToPHPValue(null, $this->platform)); - } - - public function testJsonEmptyStringConvertsToPHPValue() : void - { - self::assertSame([], $this->type->convertToPHPValue('', $this->platform)); - } - - public function testJsonStringConvertsToPHPValue() : void - { - $value = ['foo' => 'bar', 'bar' => 'foo']; - $databaseValue = json_encode($value); - $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); - - self::assertEquals($value, $phpValue); - } - - public function testJsonResourceConvertsToPHPValue() : void - { - $value = ['foo' => 'bar', 'bar' => 'foo']; - $databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r'); - $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); - - self::assertSame($value, $phpValue); - } - - public function testRequiresSQLCommentHint() : void - { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); - } -} From 8c082083e1d298f54fb9d3b0e2cf551f7c6caf60 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 15 Apr 2019 17:37:46 +0200 Subject: [PATCH 02/11] Remove deprecated Connection::TRANSACTION_* constants --- UPGRADE.md | 1 + lib/Doctrine/DBAL/Connection.php | 28 ---------------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 473a59eff7e..5b9660a7460 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -3,6 +3,7 @@ ## BC BREAK Removed previously deprecated features * Removed `json_array` type and all associated hacks. + * Removed `Connection::TRANSACTION_*` constants. ## BC BREAK `Connection::ping()` returns `void`. diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index ea2d1299570..e02b4c4b3ee 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -45,34 +45,6 @@ */ class Connection implements DriverConnection { - /** - * Constant for transaction isolation level READ UNCOMMITTED. - * - * @deprecated Use TransactionIsolationLevel::READ_UNCOMMITTED. - */ - public const TRANSACTION_READ_UNCOMMITTED = TransactionIsolationLevel::READ_UNCOMMITTED; - - /** - * Constant for transaction isolation level READ COMMITTED. - * - * @deprecated Use TransactionIsolationLevel::READ_COMMITTED. - */ - public const TRANSACTION_READ_COMMITTED = TransactionIsolationLevel::READ_COMMITTED; - - /** - * Constant for transaction isolation level REPEATABLE READ. - * - * @deprecated Use TransactionIsolationLevel::REPEATABLE_READ. - */ - public const TRANSACTION_REPEATABLE_READ = TransactionIsolationLevel::REPEATABLE_READ; - - /** - * Constant for transaction isolation level SERIALIZABLE. - * - * @deprecated Use TransactionIsolationLevel::SERIALIZABLE. - */ - public const TRANSACTION_SERIALIZABLE = TransactionIsolationLevel::SERIALIZABLE; - /** * Represents an array of ints to be expanded by Doctrine SQL parsing. */ From dad894b81074314fd0c7278d91cba4ce12f129e9 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 15 Apr 2019 17:39:52 +0200 Subject: [PATCH 03/11] Remove deprecated AbstractPlatform::DATE_INTERVAL_UNIT_* and AbstractPlatform::TRIM_* constants --- UPGRADE.md | 1 + .../DBAL/Platforms/AbstractPlatform.php | 60 ------------------- 2 files changed, 1 insertion(+), 60 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 5b9660a7460..2f187a6e72c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -4,6 +4,7 @@ * Removed `json_array` type and all associated hacks. * Removed `Connection::TRANSACTION_*` constants. + * Removed `AbstractPlatform::DATE_INTERVAL_UNIT_*` and `AbstractPlatform::TRIM_*` constants. ## BC BREAK `Connection::ping()` returns `void`. diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 2efaff474ad..cce9ae493ce 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -70,66 +70,6 @@ abstract class AbstractPlatform public const CREATE_FOREIGNKEYS = 2; - /** - * @deprecated Use DateIntervalUnit::INTERVAL_UNIT_SECOND. - */ - public const DATE_INTERVAL_UNIT_SECOND = DateIntervalUnit::SECOND; - - /** - * @deprecated Use DateIntervalUnit::MINUTE. - */ - public const DATE_INTERVAL_UNIT_MINUTE = DateIntervalUnit::MINUTE; - - /** - * @deprecated Use DateIntervalUnit::HOUR. - */ - public const DATE_INTERVAL_UNIT_HOUR = DateIntervalUnit::HOUR; - - /** - * @deprecated Use DateIntervalUnit::DAY. - */ - public const DATE_INTERVAL_UNIT_DAY = DateIntervalUnit::DAY; - - /** - * @deprecated Use DateIntervalUnit::WEEK. - */ - public const DATE_INTERVAL_UNIT_WEEK = DateIntervalUnit::WEEK; - - /** - * @deprecated Use DateIntervalUnit::MONTH. - */ - public const DATE_INTERVAL_UNIT_MONTH = DateIntervalUnit::MONTH; - - /** - * @deprecated Use DateIntervalUnit::QUARTER. - */ - public const DATE_INTERVAL_UNIT_QUARTER = DateIntervalUnit::QUARTER; - - /** - * @deprecated Use DateIntervalUnit::QUARTER. - */ - public const DATE_INTERVAL_UNIT_YEAR = DateIntervalUnit::YEAR; - - /** - * @deprecated Use TrimMode::UNSPECIFIED. - */ - public const TRIM_UNSPECIFIED = TrimMode::UNSPECIFIED; - - /** - * @deprecated Use TrimMode::LEADING. - */ - public const TRIM_LEADING = TrimMode::LEADING; - - /** - * @deprecated Use TrimMode::TRAILING. - */ - public const TRIM_TRAILING = TrimMode::TRAILING; - - /** - * @deprecated Use TrimMode::BOTH. - */ - public const TRIM_BOTH = TrimMode::BOTH; - /** @var string[]|null */ protected $doctrineTypeMapping = null; From 7fe873b7d2e6db2679352faf99fcb0a6af881aa2 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 15 Apr 2019 17:43:33 +0200 Subject: [PATCH 04/11] Remove deprecated MysqlSessionInit listener --- UPGRADE.md | 1 + .../DBAL/Event/Listeners/MysqlSessionInit.php | 60 ------------------- .../DBAL/Events/MysqlSessionInitTest.php | 33 ---------- 3 files changed, 1 insertion(+), 93 deletions(-) delete mode 100644 lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php delete mode 100644 tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php diff --git a/UPGRADE.md b/UPGRADE.md index 2f187a6e72c..44c10c59374 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -5,6 +5,7 @@ * Removed `json_array` type and all associated hacks. * Removed `Connection::TRANSACTION_*` constants. * Removed `AbstractPlatform::DATE_INTERVAL_UNIT_*` and `AbstractPlatform::TRIM_*` constants. + * Removed `MysqlSessionInit` listener. ## BC BREAK `Connection::ping()` returns `void`. diff --git a/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php deleted file mode 100644 index 75fa6c3287f..00000000000 --- a/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php +++ /dev/null @@ -1,60 +0,0 @@ -charset = $charset; - $this->collation = $collation; - } - - /** - * @return void - */ - public function postConnect(ConnectionEventArgs $args) - { - $collation = $this->collation ? ' COLLATE ' . $this->collation : ''; - $args->getConnection()->executeUpdate('SET NAMES ' . $this->charset . $collation); - } - - /** - * {@inheritdoc} - */ - public function getSubscribedEvents() - { - return [Events::postConnect]; - } -} diff --git a/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php deleted file mode 100644 index d8e8a256862..00000000000 --- a/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php +++ /dev/null @@ -1,33 +0,0 @@ -createMock(Connection::class); - $connectionMock->expects($this->once()) - ->method('executeUpdate') - ->with($this->equalTo('SET NAMES foo COLLATE bar')); - - $eventArgs = new ConnectionEventArgs($connectionMock); - - $listener = new MysqlSessionInit('foo', 'bar'); - $listener->postConnect($eventArgs); - } - - public function testGetSubscribedEvents() : void - { - $listener = new MysqlSessionInit(); - self::assertEquals([Events::postConnect], $listener->getSubscribedEvents()); - } -} From 62e1eb281afe8cefb268848b7f0fafdde2342e08 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 15 Apr 2019 17:45:52 +0200 Subject: [PATCH 05/11] Remove deprecated MysqlPlatform::getCollationFieldDeclaration() --- UPGRADE.md | 1 + lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 16 ---------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 44c10c59374..85317526e89 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -6,6 +6,7 @@ * Removed `Connection::TRANSACTION_*` constants. * Removed `AbstractPlatform::DATE_INTERVAL_UNIT_*` and `AbstractPlatform::TRIM_*` constants. * Removed `MysqlSessionInit` listener. + * Removed `MysqlPlatform::getCollationFieldDeclaration()`. ## BC BREAK `Connection::ping()` returns `void`. diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index d8fb568bf1b..cea69abe2df 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -290,22 +290,6 @@ public function getBooleanTypeDeclarationSQL(array $field) return 'TINYINT(1)'; } - /** - * Obtain DBMS specific SQL code portion needed to set the COLLATION - * of a field declaration to be used in statements like CREATE TABLE. - * - * @deprecated Deprecated since version 2.5, Use {@link self::getColumnCollationDeclarationSQL()} instead. - * - * @param string $collation name of the collation - * - * @return string DBMS specific SQL code portion needed to set the COLLATION - * of a field declaration. - */ - public function getCollationFieldDeclaration($collation) - { - return $this->getColumnCollationDeclarationSQL($collation); - } - /** * {@inheritDoc} * From b701b081edc6988cfb982a09c90ad62590537c44 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 15 Apr 2019 17:46:57 +0200 Subject: [PATCH 06/11] Remove deprecated AbstractPlatform::getIdentityColumnNullInsertSQL() --- UPGRADE.md | 1 + lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 85317526e89..3ec4c472e3c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -7,6 +7,7 @@ * Removed `AbstractPlatform::DATE_INTERVAL_UNIT_*` and `AbstractPlatform::TRIM_*` constants. * Removed `MysqlSessionInit` listener. * Removed `MysqlPlatform::getCollationFieldDeclaration()`. + * Removed `AbstractPlatform::getIdentityColumnNullInsertSQL()`. ## BC BREAK `Connection::ping()` returns `void`. diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index cce9ae493ce..02bcb75c480 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -3149,16 +3149,6 @@ public function hasNativeJsonType() return false; } - /** - * @deprecated - * - * @todo Remove in 3.0 - */ - public function getIdentityColumnNullInsertSQL() - { - return ''; - } - /** * Whether this platform supports views. * From e26130f9abb80d8631f18efb0e03cf5155c1343c Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 15 Apr 2019 18:37:10 +0200 Subject: [PATCH 07/11] Remove deprecated Table::addUnnamedForeignKeyConstraint() and Table::addNamedForeignKeyConstraint() --- UPGRADE.md | 1 + lib/Doctrine/DBAL/Schema/Table.php | 47 ++----------------- .../Schema/PostgreSqlSchemaManagerTest.php | 2 +- .../AbstractPostgreSqlPlatformTestCase.php | 2 +- .../Tests/DBAL/Schema/ComparatorTest.php | 4 +- .../DBAL/Schema/Platforms/MySQLSchemaTest.php | 2 +- 6 files changed, 10 insertions(+), 48 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 3ec4c472e3c..2565385d6e6 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,7 @@ * Removed `MysqlSessionInit` listener. * Removed `MysqlPlatform::getCollationFieldDeclaration()`. * Removed `AbstractPlatform::getIdentityColumnNullInsertSQL()`. + * Removed `Table::addUnnamedForeignKeyConstraint()` and `Table::addNamedForeignKeyConstraint()`. ## BC BREAK `Connection::ping()` returns `void`. diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 6eb93a51ad2..8c3a19d755b 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -362,59 +362,20 @@ public function dropColumn($columnName) * @param string[] $localColumnNames * @param string[] $foreignColumnNames * @param mixed[] $options - * @param string|null $constraintName + * @param string|null $name * * @return self */ - public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $constraintName = null) + public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $name = null) { - if (! $constraintName) { - $constraintName = $this->_generateIdentifierName( + if (! $name) { + $name = $this->_generateIdentifierName( array_merge((array) $this->getName(), $localColumnNames), 'fk', $this->_getMaxIdentifierLength() ); } - return $this->addNamedForeignKeyConstraint($constraintName, $foreignTable, $localColumnNames, $foreignColumnNames, $options); - } - - /** - * Adds a foreign key constraint. - * - * Name is to be generated by the database itself. - * - * @deprecated Use {@link addForeignKeyConstraint} - * - * @param Table|string $foreignTable Table schema instance or table name - * @param string[] $localColumnNames - * @param string[] $foreignColumnNames - * @param mixed[] $options - * - * @return self - */ - public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = []) - { - return $this->addForeignKeyConstraint($foreignTable, $localColumnNames, $foreignColumnNames, $options); - } - - /** - * Adds a foreign key constraint with a given name. - * - * @deprecated Use {@link addForeignKeyConstraint} - * - * @param string $name - * @param Table|string $foreignTable Table schema instance or table name - * @param string[] $localColumnNames - * @param string[] $foreignColumnNames - * @param mixed[] $options - * - * @return self - * - * @throws SchemaException - */ - public function addNamedForeignKeyConstraint($name, $foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = []) - { if ($foreignTable instanceof Table) { foreach ($foreignColumnNames as $columnName) { if (! $foreignTable->hasColumn($columnName)) { diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index c52d5af4a7f..b71c0249ae0 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -161,7 +161,7 @@ public function testTableWithSchema() : void $column = $nestedSchemaTable->addColumn('id', 'integer'); $column->setAutoincrement(true); $nestedSchemaTable->setPrimaryKey(['id']); - $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, ['id'], ['id']); + $nestedSchemaTable->addForeignKeyConstraint($nestedRelatedTable, ['id'], ['id']); $this->schemaManager->createTable($nestedRelatedTable); $this->schemaManager->createTable($nestedSchemaTable); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 7f335f96d23..2f2f240f581 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -585,7 +585,7 @@ public function testDroppingConstraintsBeforeColumns() : void $oldTable = clone $newTable; $oldTable->addColumn('parent_id', 'integer'); - $oldTable->addUnnamedForeignKeyConstraint('mytable', ['parent_id'], ['id']); + $oldTable->addForeignKeyConstraint('mytable', ['parent_id'], ['id']); $comparator = new Comparator(); $tableDiff = $comparator->diffTable($oldTable, $newTable); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index c59df12621f..f86b2a3c4c7 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -681,11 +681,11 @@ public function testCompareForeignKeyBasedOnPropertiesNotName() : void { $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); - $tableA->addNamedForeignKeyConstraint('foo_constraint', 'bar', ['id'], ['id']); + $tableA->addForeignKeyConstraint('bar', ['id'], ['id'], [], 'foo_constraint'); $tableB = new Table('foo'); $tableB->addColumn('ID', 'integer'); - $tableB->addNamedForeignKeyConstraint('bar_constraint', 'bar', ['id'], ['id']); + $tableB->addForeignKeyConstraint('bar', ['id'], ['id'], [], 'bar_constraint'); $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); diff --git a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php index fcffe6f1a8c..751d49f2025 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php @@ -53,7 +53,7 @@ public function testGenerateForeignKeySQL() : void { $tableOld = new Table('test'); $tableOld->addColumn('foo_id', 'integer'); - $tableOld->addUnnamedForeignKeyConstraint('test_foreign', ['foo_id'], ['foo_id']); + $tableOld->addForeignKeyConstraint('test_foreign', ['foo_id'], ['foo_id']); $sqls = []; foreach ($tableOld->getForeignKeys() as $fk) { From 5c4f4cd0d695a177279d9e55ccd9afda5676e710 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 15 Apr 2019 18:40:13 +0200 Subject: [PATCH 08/11] SQLParserUtils::*_TOKEN constants made private --- UPGRADE.md | 1 + lib/Doctrine/DBAL/SQLParserUtils.php | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 2565385d6e6..c7522481dd8 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -9,6 +9,7 @@ * Removed `MysqlPlatform::getCollationFieldDeclaration()`. * Removed `AbstractPlatform::getIdentityColumnNullInsertSQL()`. * Removed `Table::addUnnamedForeignKeyConstraint()` and `Table::addNamedForeignKeyConstraint()`. + * `SQLParserUtils::*_TOKEN` constants made private. ## BC BREAK `Connection::ping()` returns `void`. diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 642e5691291..d12039bc3ad 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -28,13 +28,14 @@ */ class SQLParserUtils { + private const POSITIONAL_TOKEN = '\?'; + private const NAMED_TOKEN = '(? Date: Mon, 15 Apr 2019 18:41:45 +0200 Subject: [PATCH 09/11] Remove deprecated SQLParserUtils::getPlaceholderPositions() --- UPGRADE.md | 1 + lib/Doctrine/DBAL/SQLParserUtils.php | 20 --- .../Tests/DBAL/SQLParserUtilsTest.php | 130 +++++++++++------- 3 files changed, 79 insertions(+), 72 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index c7522481dd8..ba1e5a9882d 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -9,6 +9,7 @@ * Removed `MysqlPlatform::getCollationFieldDeclaration()`. * Removed `AbstractPlatform::getIdentityColumnNullInsertSQL()`. * Removed `Table::addUnnamedForeignKeyConstraint()` and `Table::addNamedForeignKeyConstraint()`. + * Removed `SQLParserUtils::getPlaceholderPositions()`. * `SQLParserUtils::*_TOKEN` constants made private. ## BC BREAK `Connection::ping()` returns `void`. diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index d12039bc3ad..a9af7b70ec0 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -43,26 +43,6 @@ class SQLParserUtils private const ESCAPED_BRACKET_QUOTED_TEXT = '(? 42, 0 => 30]], // explicit keys + ['SELECT ?', [7]], + ['SELECT * FROM Foo WHERE bar IN (?, ?, ?)', [32, 35, 38]], + ['SELECT ? FROM ?', [7, 14]], + ['SELECT "?" FROM foo', []], + ["SELECT '?' FROM foo", []], + ['SELECT `?` FROM foo', []], // Ticket DBAL-552 + ['SELECT [?] FROM foo', []], + ["SELECT 'Doctrine\DBAL?' FROM foo", []], // Ticket DBAL-558 + ['SELECT "Doctrine\DBAL?" FROM foo', []], // Ticket DBAL-558 + ['SELECT `Doctrine\DBAL?` FROM foo', []], // Ticket DBAL-558 + ['SELECT [Doctrine\DBAL?] FROM foo', []], // Ticket DBAL-558 + ['SELECT "?" FROM foo WHERE bar = ?', [32]], + ["SELECT '?' FROM foo WHERE bar = ?", [32]], + ['SELECT `?` FROM foo WHERE bar = ?', [32]], // Ticket DBAL-552 + ['SELECT [?] FROM foo WHERE bar = ?', [32]], + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[?])', [56]], // Ticket GH-2295 + ["SELECT 'Doctrine\DBAL?' FROM foo WHERE bar = ?", [45]], // Ticket DBAL-558 + ['SELECT "Doctrine\DBAL?" FROM foo WHERE bar = ?', [45]], // Ticket DBAL-558 + ['SELECT `Doctrine\DBAL?` FROM foo WHERE bar = ?', [45]], // Ticket DBAL-558 + ['SELECT [Doctrine\DBAL?] FROM foo WHERE bar = ?', [45]], // Ticket DBAL-558 + ["SELECT * FROM FOO WHERE bar = 'it\\'s a trap? \\\\' OR bar = ?\nAND baz = \"\\\"quote\\\" me on it? \\\\\" OR baz = ?", [58, 104]], + ['SELECT * FROM foo WHERE foo = ? AND bar = ?', [1 => 42, 0 => 30]], // explicit keys + + ]; + } + + /** + * @return iterable> + */ + public function dataGetPlaceholderNamedPositions() : iterable + { + return [ + // none + ['SELECT * FROM Foo', []], // named - ['SELECT :foo FROM :bar', false, [7 => 'foo', 17 => 'bar']], - ['SELECT * FROM Foo WHERE bar IN (:name1, :name2)', false, [32 => 'name1', 40 => 'name2']], - ['SELECT ":foo" FROM Foo WHERE bar IN (:name1, :name2)', false, [37 => 'name1', 45 => 'name2']], - ["SELECT ':foo' FROM Foo WHERE bar IN (:name1, :name2)", false, [37 => 'name1', 45 => 'name2']], - ['SELECT :foo_id', false, [7 => 'foo_id']], // Ticket DBAL-231 - ['SELECT @rank := 1', false, []], // Ticket DBAL-398 - ['SELECT @rank := 1 AS rank, :foo AS foo FROM :bar', false, [27 => 'foo', 44 => 'bar']], // Ticket DBAL-398 - ['SELECT * FROM Foo WHERE bar > :start_date AND baz > :start_date', false, [30 => 'start_date', 52 => 'start_date']], // Ticket GH-113 - ['SELECT foo::date as date FROM Foo WHERE bar > :start_date AND baz > :start_date', false, [46 => 'start_date', 68 => 'start_date']], // Ticket GH-259 - ['SELECT `d.ns:col_name` FROM my_table d WHERE `d.date` >= :param1', false, [57 => 'param1']], // Ticket DBAL-552 - ['SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, [57 => 'param1']], // Ticket DBAL-552 - ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, [56 => 'foo']], // Ticket GH-2295 - ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', false, [56 => 'foo']], - ['SELECT table.field1, ARRAY[\'3\'] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']', false, [73 => 'foo']], - ['SELECT table.field1, ARRAY[\'3\']::integer[] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']::integer[]', false, [84 => 'foo']], - ['SELECT table.field1, ARRAY[:foo] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']', false, [27 => 'foo', 74 => 'bar']], - ['SELECT table.field1, ARRAY[:foo]::integer[] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']::integer[]', false, [27 => 'foo', 85 => 'bar']], + ['SELECT :foo FROM :bar', [7 => 'foo', 17 => 'bar']], + ['SELECT * FROM Foo WHERE bar IN (:name1, :name2)', [32 => 'name1', 40 => 'name2']], + ['SELECT ":foo" FROM Foo WHERE bar IN (:name1, :name2)', [37 => 'name1', 45 => 'name2']], + ["SELECT ':foo' FROM Foo WHERE bar IN (:name1, :name2)", [37 => 'name1', 45 => 'name2']], + ['SELECT :foo_id', [7 => 'foo_id']], // Ticket DBAL-231 + ['SELECT @rank := 1', []], // Ticket DBAL-398 + ['SELECT @rank := 1 AS rank, :foo AS foo FROM :bar', [27 => 'foo', 44 => 'bar']], // Ticket DBAL-398 + ['SELECT * FROM Foo WHERE bar > :start_date AND baz > :start_date', [30 => 'start_date', 52 => 'start_date']], // Ticket GH-113 + ['SELECT foo::date as date FROM Foo WHERE bar > :start_date AND baz > :start_date', [46 => 'start_date', 68 => 'start_date']], // Ticket GH-259 + ['SELECT `d.ns:col_name` FROM my_table d WHERE `d.date` >= :param1', [57 => 'param1']], // Ticket DBAL-552 + ['SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', [57 => 'param1']], // Ticket DBAL-552 + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', [56 => 'foo']], // Ticket GH-2295 + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', [56 => 'foo']], + ['SELECT table.field1, ARRAY[\'3\'] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']', [73 => 'foo']], + ['SELECT table.field1, ARRAY[\'3\']::integer[] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']::integer[]', [84 => 'foo']], + ['SELECT table.field1, ARRAY[:foo] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']', [27 => 'foo', 74 => 'bar']], + ['SELECT table.field1, ARRAY[:foo]::integer[] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']::integer[]', [27 => 'foo', 85 => 'bar']], [ <<<'SQLDATA' SELECT * FROM foo WHERE @@ -79,18 +91,17 @@ public static function dataGetPlaceholderPositions() : iterable OR bar=:a_param3 SQLDATA , - false, [ 73 => 'a_param1', 90 => 'a_param2', 189 => 'a_param3', ], ], - ["SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE '\\\\') AND (data.description LIKE :condition_1 ESCAPE '\\\\') ORDER BY id ASC", false, [121 => 'condition_0', 174 => 'condition_1']], - ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE "\\\\") ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], - ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE \'\\\\\') ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], - ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE `\\\\`) AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], - ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE \'\\\\\') AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], + ["SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE '\\\\') AND (data.description LIKE :condition_1 ESCAPE '\\\\') ORDER BY id ASC", [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE "\\\\") ORDER BY id ASC', [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE \'\\\\\') ORDER BY id ASC', [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE `\\\\`) AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE \'\\\\\') AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', [121 => 'condition_0', 174 => 'condition_1']], ]; } @@ -98,12 +109,27 @@ public static function dataGetPlaceholderPositions() : iterable /** * @param int[] $expectedParamPos * - * @dataProvider dataGetPlaceholderPositions + * @dataProvider dataGetPlaceholderPositionalPositions */ - public function testGetPlaceholderPositions(string $query, bool $isPositional, array $expectedParamPos) : void + public function testGetPositionalPlaceholderPositions(string $query, array $expectedParamPos) : void { - $actualParamPos = SQLParserUtils::getPlaceholderPositions($query, $isPositional); - self::assertEquals($expectedParamPos, $actualParamPos); + $reflection = new ReflectionMethod(SQLParserUtils::class, 'getPositionalPlaceholderPositions'); + $reflection->setAccessible(true); + + self::assertEquals($expectedParamPos, $reflection->invoke(null, $query)); + } + + /** + * @param array $expectedParamPos + * + * @dataProvider dataGetPlaceholderNamedPositions + */ + public function testGetNamedPlaceholderPositions(string $query, array $expectedParamPos) : void + { + $reflection = new ReflectionMethod(SQLParserUtils::class, 'getNamedPlaceholderPositions'); + $reflection->setAccessible(true); + + self::assertEquals($expectedParamPos, $reflection->invoke(null, $query)); } /** From 5cdd4e16e33eca52e80519a66ffea8465de8fbed Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 15 Apr 2019 18:53:35 +0200 Subject: [PATCH 10/11] Remove deprecated Table::renameColumn() --- UPGRADE.md | 1 + lib/Doctrine/DBAL/Schema/Table.php | 19 ------------------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index ba1e5a9882d..d272ce3df1c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -9,6 +9,7 @@ * Removed `MysqlPlatform::getCollationFieldDeclaration()`. * Removed `AbstractPlatform::getIdentityColumnNullInsertSQL()`. * Removed `Table::addUnnamedForeignKeyConstraint()` and `Table::addNamedForeignKeyConstraint()`. + * Removed `Table::renameColumn()`. * Removed `SQLParserUtils::getPlaceholderPositions()`. * `SQLParserUtils::*_TOKEN` constants made private. diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 8c3a19d755b..8dfef9ac6e7 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -301,25 +301,6 @@ public function addColumn($columnName, $typeName, array $options = []) return $column; } - /** - * Renames a Column. - * - * @deprecated - * - * @param string $oldColumnName - * @param string $newColumnName - * - * @throws DBALException - */ - public function renameColumn($oldColumnName, $newColumnName) - { - throw new DBALException( - 'Table#renameColumn() was removed, because it drops and recreates the column instead. ' . - 'There is no fix available, because a schema diff cannot reliably detect if a column ' . - 'was renamed or one column was created and another one dropped.' - ); - } - /** * Change Column Details. * From 71675d506b5839cb46c87090a2f84e4b5997ca35 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Mon, 15 Apr 2019 19:04:42 +0200 Subject: [PATCH 11/11] Remove deprecated AbstractSchemaManager::getFilterSchemaAssetsExpression(), Configuration::getFilterSchemaAssetsExpression() and Configuration::getFilterSchemaAssetsExpression() --- UPGRADE.md | 2 + lib/Doctrine/DBAL/Configuration.php | 12 -- .../DBAL/Schema/AbstractSchemaManager.php | 10 -- .../Schema/PostgreSqlSchemaManagerTest.php | 11 +- .../DBAL/Schema/DB2SchemaManagerTest.php | 108 +----------------- 5 files changed, 14 insertions(+), 129 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index d272ce3df1c..fbcfa1fa48b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -11,6 +11,8 @@ * Removed `Table::addUnnamedForeignKeyConstraint()` and `Table::addNamedForeignKeyConstraint()`. * Removed `Table::renameColumn()`. * Removed `SQLParserUtils::getPlaceholderPositions()`. + * Removed `AbstractSchemaManager::getFilterSchemaAssetsExpression()`, `Configuration::getFilterSchemaAssetsExpression()` + and `Configuration::getFilterSchemaAssetsExpression()`. * `SQLParserUtils::*_TOKEN` constants made private. ## BC BREAK `Connection::ping()` returns `void`. diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 7cbca89a26a..9fe9382b89f 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -85,18 +85,6 @@ public function setFilterSchemaAssetsExpression($filterExpression) } } - /** - * Returns filter schema assets expression. - * - * @deprecated Use Configuration::getSchemaAssetsFilter() instead - * - * @return string|null - */ - public function getFilterSchemaAssetsExpression() - { - return $this->_attributes['filterSchemaAssetsExpression'] ?? null; - } - /** * @param string $filterExpression */ diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 69af7a5eadc..2a71f88dde8 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -234,16 +234,6 @@ protected function filterAssetNames($assetNames) return array_values(array_filter($assetNames, $filter)); } - /** - * @deprecated Use Configuration::getSchemaAssetsFilter() instead - * - * @return string|null - */ - protected function getFilterSchemaAssetsExpression() - { - return $this->_conn->getConfiguration()->getFilterSchemaAssetsExpression(); - } - /** * Lists the tables for this connection. * diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index b71c0249ae0..cae1835500b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -18,6 +18,7 @@ use function array_map; use function array_pop; use function count; +use function preg_match; use function strtolower; class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase @@ -30,7 +31,7 @@ protected function tearDown() : void return; } - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression(null); + $this->connection->getConfiguration()->setSchemaAssetsFilter(null); } /** @@ -214,11 +215,15 @@ public function testFilterSchemaExpression() : void $column = $testTable->addColumn('id', 'integer'); $this->schemaManager->createTable($testTable); - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_#'); + $this->connection->getConfiguration()->setSchemaAssetsFilter(static function (string $name) : bool { + return preg_match('#^dbal204_#', $name) === 1; + }); $names = $this->schemaManager->listTableNames(); self::assertCount(2, $names); - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_test#'); + $this->connection->getConfiguration()->setSchemaAssetsFilter(static function (string $name) : bool { + return preg_match('#^dbal204_test#', $name) === 1; + }); $names = $this->schemaManager->listTableNames(); self::assertCount(1, $names); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index 46b8fd3949e..bcf2622b295 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use function in_array; +use function preg_match; /** * @covers \Doctrine\DBAL\Schema\DB2SchemaManager @@ -50,7 +51,9 @@ protected function setUp() : void */ public function testListTableNamesFiltersAssetNamesCorrectly() : void { - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); + $this->conn->getConfiguration()->setSchemaAssetsFilter(static function (string $name) : bool { + return preg_match('/^(?!T_)/', $name) === 1; + }); $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ ['name' => 'FOO'], ['name' => 'T_FOO'], @@ -67,35 +70,6 @@ public function testListTableNamesFiltersAssetNamesCorrectly() : void ); } - /** - * @group DBAL-2701 - */ - public function testAssetFilteringSetsACallable() : void - { - $filterExpression = '/^(?!T_)/'; - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); - $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ - ['name' => 'FOO'], - ['name' => 'T_FOO'], - ['name' => 'BAR'], - ['name' => 'T_BAR'], - ])); - - self::assertSame( - [ - 'FOO', - 'BAR', - ], - $this->manager->listTableNames() - ); - - $callable = $this->conn->getConfiguration()->getSchemaAssetsFilter(); - self::assertIsCallable($callable); - - // BC check: Test that regexp expression is still preserved & accessible. - $this->assertEquals($filterExpression, $this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); - } - public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() : void { $accepted = ['T_FOO', 'T_BAR']; @@ -117,79 +91,5 @@ public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() : voi ], $this->manager->listTableNames() ); - - $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); - } - - public function testSettingNullExpressionWillResetCallable() : void - { - $accepted = ['T_FOO', 'T_BAR']; - $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { - return in_array($assetName, $accepted); - }); - - $this->conn->expects($this->atLeastOnce())->method('fetchAll')->will($this->returnValue([ - ['name' => 'FOO'], - ['name' => 'T_FOO'], - ['name' => 'BAR'], - ['name' => 'T_BAR'], - ])); - - self::assertSame( - [ - 'T_FOO', - 'T_BAR', - ], - $this->manager->listTableNames() - ); - - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression(null); - - self::assertSame( - [ - 'FOO', - 'T_FOO', - 'BAR', - 'T_BAR', - ], - $this->manager->listTableNames() - ); - - $this->assertNull($this->conn->getConfiguration()->getSchemaAssetsFilter()); - } - - public function testSettingNullAsCallableClearsExpression() : void - { - $filterExpression = '/^(?!T_)/'; - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); - - $this->conn->expects($this->exactly(2))->method('fetchAll')->will($this->returnValue([ - ['name' => 'FOO'], - ['name' => 'T_FOO'], - ['name' => 'BAR'], - ['name' => 'T_BAR'], - ])); - - self::assertSame( - [ - 'FOO', - 'BAR', - ], - $this->manager->listTableNames() - ); - - $this->conn->getConfiguration()->setSchemaAssetsFilter(null); - - self::assertSame( - [ - 'FOO', - 'T_FOO', - 'BAR', - 'T_BAR', - ], - $this->manager->listTableNames() - ); - - $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); } }