Skip to content

Commit

Permalink
Remove deprecated type commenting feature
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Oct 14, 2019
1 parent 15967f6 commit d2d1489
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 212 deletions.
75 changes: 0 additions & 75 deletions ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -53,10 +50,6 @@ public function createConnection(array $params, Configuration $config = null, Ev
}
}

if (! empty($this->typesConfig)) {
$this->markTypesCommented($this->getDatabasePlatform($connection));
}

return $connection;
}

Expand Down Expand Up @@ -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
);
}
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions Resources/doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -414,7 +413,6 @@ Configuration Reference
<doctrine:type
name="some_custom_type"
class="Acme\HelloBundle\MyCustomType"
commented="true"
/>
<!-- example -->
Expand Down
108 changes: 0 additions & 108 deletions Tests/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
24 changes: 0 additions & 24 deletions Tests/DependencyInjection/TestCommentedType.php

This file was deleted.

1 change: 0 additions & 1 deletion Tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function createYamlBundleTestContainer()
'types' => [
'test' => [
'class' => TestType::class,
'commented' => false,
],
],
], 'orm' => [
Expand Down
8 changes: 8 additions & 0 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
UPGRADE FROM 2.x to 3.0
=======================

Types
-----

* The `commented` configuration option for types is no longer supported and
deprecated.

0 comments on commit d2d1489

Please sign in to comment.