From d2d1489054e09394ee8fe9c3367854425e7ab8cf Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Sun, 13 Oct 2019 15:08:21 +0200 Subject: [PATCH] Remove deprecated type commenting feature --- ConnectionFactory.php | 75 ------------ DependencyInjection/Configuration.php | 2 +- Resources/doc/configuration.rst | 2 - Tests/ConnectionFactoryTest.php | 108 ------------------ .../AbstractDoctrineExtensionTest.php | 2 +- .../DependencyInjection/TestCommentedType.php | 24 ---- Tests/TestCase.php | 1 - UPGRADE-3.0.md | 8 ++ 8 files changed, 10 insertions(+), 212 deletions(-) delete mode 100644 Tests/DependencyInjection/TestCommentedType.php create mode 100644 UPGRADE-3.0.md diff --git a/ConnectionFactory.php b/ConnectionFactory.php index a75e1159e..4fb04b2e6 100644 --- a/ConnectionFactory.php +++ b/ConnectionFactory.php @@ -10,9 +10,6 @@ use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; -use const E_USER_DEPRECATED; -use function get_class; -use function trigger_error; class ConnectionFactory { @@ -53,10 +50,6 @@ public function createConnection(array $params, Configuration $config = null, Ev } } - if (! empty($this->typesConfig)) { - $this->markTypesCommented($this->getDatabasePlatform($connection)); - } - return $connection; } @@ -102,72 +95,4 @@ private function initializeTypes() $this->initialized = true; } - - private function markTypesCommented(AbstractPlatform $platform) : void - { - foreach ($this->typesConfig as $typeName => $typeConfig) { - $type = Type::getType($typeName); - $requiresSQLCommentHint = $type->requiresSQLCommentHint($platform); - - // Attribute is missing, make sure a type that doesn't require a comment is marked as commented - // This is deprecated behaviour that will be dropped in 2.0. - if ($typeConfig['commented'] === null) { - if (! $requiresSQLCommentHint) { - @trigger_error( - sprintf( - 'The type "%s" was implicitly marked as commented due to the configuration. This is deprecated and will be removed in DoctrineBundle 2.0. Either set the "commented" attribute in the configuration to "false" or mark the type as commented in "%s::requiresSQLCommentHint()."', - $typeName, - get_class($type) - ), - E_USER_DEPRECATED - ); - - $platform->markDoctrineTypeCommented($type); - } - - continue; - } - - // The following logic generates appropriate deprecation notices telling the user how to update their type configuration. - if ($typeConfig['commented']) { - if (! $requiresSQLCommentHint) { - @trigger_error( - sprintf( - 'The type "%s" was marked as commented in its configuration but not in the type itself. This is deprecated and will be removed in DoctrineBundle 2.0. Please update the return value of "%s::requiresSQLCommentHint()."', - $typeName, - get_class($type) - ), - E_USER_DEPRECATED - ); - - $platform->markDoctrineTypeCommented($type); - - continue; - } - - @trigger_error( - sprintf( - 'The type "%s" was explicitly marked as commented in its configuration. This is no longer necessary and will be removed in DoctrineBundle 2.0. Please remove the "commented" attribute from the type configuration.', - $typeName - ), - E_USER_DEPRECATED - ); - - continue; - } - - if (! $requiresSQLCommentHint) { - continue; - } - - @trigger_error( - sprintf( - 'The type "%s" was marked as uncommented in its configuration but commented in the type itself. This is deprecated and will be removed in DoctrineBundle 2.0. Please update the return value of "%s::requiresSQLCommentHint()" or remove the "commented" attribute from the type configuration.', - $typeName, - get_class($type) - ), - E_USER_DEPRECATED - ); - } - } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b80c57c48..af9e68a93 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -97,7 +97,7 @@ private function addDbalSection(ArrayNodeDefinition $node) ->end() ->children() ->scalarNode('class')->isRequired()->end() - ->booleanNode('commented')->defaultNull()->end() + ->booleanNode('commented')->setDeprecated()->end() ->end() ->end() ->end() diff --git a/Resources/doc/configuration.rst b/Resources/doc/configuration.rst index 86b982bea..ad21f0b07 100644 --- a/Resources/doc/configuration.rst +++ b/Resources/doc/configuration.rst @@ -18,7 +18,6 @@ Configuration Reference # example some_custom_type: class: Acme\HelloBundle\MyCustomType - commented: true connections: # A collection of different named connections (e.g. default, conn2, etc) @@ -414,7 +413,6 @@ Configuration Reference diff --git a/Tests/ConnectionFactoryTest.php b/Tests/ConnectionFactoryTest.php index 5e708bc36..d82bed875 100644 --- a/Tests/ConnectionFactoryTest.php +++ b/Tests/ConnectionFactoryTest.php @@ -3,8 +3,6 @@ namespace Doctrine\Bundle\DoctrineBundle\Tests; use Doctrine\Bundle\DoctrineBundle\ConnectionFactory; -use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestCommentedType; -use Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Exception\DriverException; @@ -51,112 +49,6 @@ public function testContainer() FakeDriver::$exception = null; } } - - /** - * @dataProvider getValidTypeConfigurations - */ - public function testRegisterTypes(array $type, int $expectedCalls) : void - { - $factory = new ConnectionFactory(['test' => $type]); - $params = ['driverClass' => FakeDriver::class]; - $config = null; - $eventManager = null; - $mappingTypes = []; - - $platform = $this->createMock(AbstractPlatform::class); - $platform - ->expects($this->exactly($expectedCalls)) - ->method('markDoctrineTypeCommented') - ->with($this->isInstanceOf($type['class'])); - - FakeDriver::$platform = $platform; - - try { - $factory->createConnection($params, $config, $eventManager, $mappingTypes); - } finally { - FakeDriver::$platform = null; - } - } - - public static function getValidTypeConfigurations() : array - { - return [ - 'uncommentedTypeMarkedNotCommented' => [ - 'type' => [ - 'class' => TestType::class, - 'commented' => false, - ], - 'expectedCalls' => 0, - ], - 'commentedTypeNotMarked' => [ - 'type' => [ - 'class' => TestCommentedType::class, - 'commented' => null, - ], - 'expectedCalls' => 0, - ], - ]; - } - - /** - * @group legacy - * @expectedDeprecation The type "test" was implicitly marked as commented due to the configuration. This is deprecated and will be removed in DoctrineBundle 2.0. Either set the "commented" attribute in the configuration to "false" or mark the type as commented in "Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType::requiresSQLCommentHint()." - */ - public function testRegisterUncommentedTypeNotMarked() : void - { - $this->testRegisterTypes( - [ - 'class' => TestType::class, - 'commented' => null, - ], - 1 - ); - } - - /** - * @group legacy - * @expectedDeprecation The type "test" was marked as commented in its configuration but not in the type itself. This is deprecated and will be removed in DoctrineBundle 2.0. Please update the return value of "Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType::requiresSQLCommentHint()." - */ - public function testRegisterUncommentedTypeMarkedCommented() : void - { - $this->testRegisterTypes( - [ - 'class' => TestType::class, - 'commented' => true, - ], - 1 - ); - } - - /** - * @group legacy - * @expectedDeprecation The type "test" was explicitly marked as commented in its configuration. This is no longer necessary and will be removed in DoctrineBundle 2.0. Please remove the "commented" attribute from the type configuration. - */ - public function testRegisterCommentedTypeMarkedCommented() : void - { - $this->testRegisterTypes( - [ - 'class' => TestCommentedType::class, - 'commented' => true, - ], - 0 - ); - } - - /** - * @group legacy - * @expectedDeprecation The type "test" was marked as uncommented in its configuration but commented in the type itself. This is deprecated and will be removed in DoctrineBundle 2.0. Please update the return value of "Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\TestCommentedType::requiresSQLCommentHint()" or remove the "commented" attribute from the type configuration. - */ - public function testRegisterCommentedTypeMarkedNotCommented() : void - { - $this->testRegisterTypes( - [ - 'class' => TestCommentedType::class, - 'commented' => false, - ], - 0 - ); - } } /** diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 73aba0738..9a3a6c9f1 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -502,7 +502,7 @@ public function testSetTypes() $container = $this->loadContainer('dbal_types'); $this->assertEquals( - ['test' => ['class' => TestType::class, 'commented' => null]], + ['test' => ['class' => TestType::class]], $container->getParameter('doctrine.dbal.connection_factory.types') ); $this->assertEquals('%doctrine.dbal.connection_factory.types%', $container->getDefinition('doctrine.dbal.connection_factory')->getArgument(0)); diff --git a/Tests/DependencyInjection/TestCommentedType.php b/Tests/DependencyInjection/TestCommentedType.php deleted file mode 100644 index a453c964f..000000000 --- a/Tests/DependencyInjection/TestCommentedType.php +++ /dev/null @@ -1,24 +0,0 @@ - [ 'test' => [ 'class' => TestType::class, - 'commented' => false, ], ], ], 'orm' => [ diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md new file mode 100644 index 000000000..03ee914eb --- /dev/null +++ b/UPGRADE-3.0.md @@ -0,0 +1,8 @@ +UPGRADE FROM 2.x to 3.0 +======================= + +Types +----- + + * The `commented` configuration option for types is no longer supported and + deprecated.