diff --git a/.doctrine-project.json b/.doctrine-project.json index ca091627..73ba9db5 100644 --- a/.doctrine-project.json +++ b/.doctrine-project.json @@ -10,16 +10,22 @@ "slug": "latest", "upcoming": true }, + { + "name": "2.18", + "branchName": "2.18.x", + "slug": "2.18", + "upcoming": true + }, { "name": "2.17", "branchName": "2.17.x", "slug": "2.17", - "upcoming": true + "current": true }, { "name": "2.16", "slug": "2.16", - "current": true + "maintained": false }, { "name": "2.15", diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 092c2dd3..63a89fe5 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -89,7 +89,7 @@ jobs: with: php-version: "${{ matrix.php-version }}" coverage: "pcov" - ini-values: "zend.assertions=1" + ini-file: "development" extensions: "pdo_sqlite" tools: "flex" diff --git a/.github/workflows/test-dev-stability.yml b/.github/workflows/test-dev-stability.yml index 701cfab6..82b919db 100644 --- a/.github/workflows/test-dev-stability.yml +++ b/.github/workflows/test-dev-stability.yml @@ -35,7 +35,7 @@ jobs: uses: "shivammathur/setup-php@v2" with: php-version: "${{ matrix.php-version }}" - ini-values: "zend.assertions=1" + ini-file: "development" extensions: "pdo_sqlite" tools: "flex" diff --git a/.symfony.bundle.yaml b/.symfony.bundle.yaml index 55ec8acb..f06cf8cb 100644 --- a/.symfony.bundle.yaml +++ b/.symfony.bundle.yaml @@ -12,9 +12,10 @@ branches: - "2.15.x" - "2.16.x" - "2.17.x" + - "2.18.x" maintained_branches: - - "2.16.x" - "2.17.x" + - "2.18.x" doc_dir: "docs/en/" -current_branch: "2.16.x" -dev_branch: "2.17.x" +current_branch: "2.17.x" +dev_branch: "2.18.x" diff --git a/UPGRADE-2.17.md b/UPGRADE-2.17.md index 4b76ff35..52578346 100644 --- a/UPGRADE-2.17.md +++ b/UPGRADE-2.17.md @@ -26,20 +26,3 @@ deprecated. You should stop using it as soon as you upgrade to Doctrine DBAL 4. This option is a no-op when using `doctrine/dbal` 4 and has been conditionally deprecated. You should stop using it as soon as you upgrade to Doctrine DBAL 4. - -ConnectionFactory::createConnection() signature change ------------------------------------------------------- - -The signature of `ConnectionFactory::createConnection()` will change with -version 3.0 of the bundle. - -As soon as you upgrade to Doctrine DBAL 4, you should use stop passing an event -manager argument. - -```diff -- $connectionFactory->createConnection($params, $config, $eventManager, $mappingTypes) -+ $connectionFactory->createConnection($params, $config, $mappingTypes) -``` - -As a small breaking change, it is no longer fully possible to use named -arguments with that method until 3.0. diff --git a/src/ConnectionFactory.php b/src/ConnectionFactory.php index e45ec81d..1245e384 100644 --- a/src/ConnectionFactory.php +++ b/src/ConnectionFactory.php @@ -24,8 +24,6 @@ use function array_merge; use function class_exists; -use function func_num_args; -use function is_array; use function is_subclass_of; use function method_exists; @@ -63,52 +61,18 @@ public function __construct( /** * Create a connection by name. * - * @param mixed[] $params - * @param EventManager|array|null $eventManagerOrMappingTypes - * @param array $deprecatedMappingTypes + * @param mixed[] $params + * @param array $mappingTypes * @phpstan-param Params $params * * @return Connection - * - * @no-named-arguments */ - public function createConnection( - array $params, - Configuration|null $config = null, - EventManager|array|null $eventManagerOrMappingTypes = [], - array $deprecatedMappingTypes = [], - ) { - if (! method_exists(Connection::class, 'getEventManager') && $eventManagerOrMappingTypes instanceof EventManager) { + public function createConnection(array $params, Configuration|null $config = null, EventManager|null $eventManager = null, array $mappingTypes = []) + { + if (! method_exists(Connection::class, 'getEventManager') && $eventManager !== null) { throw new InvalidArgumentException('Passing an EventManager instance is not supported with DBAL > 3'); } - if (is_array($eventManagerOrMappingTypes) && func_num_args() === 4) { - throw new InvalidArgumentException('Passing mapping types both as 3rd and 4th argument makes no sense.'); - } - - if ($eventManagerOrMappingTypes instanceof EventManager) { - // DBAL 3 - $eventManager = $eventManagerOrMappingTypes; - $mappingTypes = $deprecatedMappingTypes; - } elseif (is_array($eventManagerOrMappingTypes)) { - // Future signature - $eventManager = null; - $mappingTypes = $eventManagerOrMappingTypes; - } else { - // Legacy signature - if (! method_exists(Connection::class, 'getEventManager')) { - Deprecation::trigger( - 'doctrine/doctrine-bundle', - 'https://github.com/doctrine/DoctrineBundle/pull/1976', - 'Passing mapping types as 4th argument to %s is deprecated when using DBAL 4 and will not be supported in version 3.0 of the bundle. Pass them as 3rd argument instead.', - __METHOD__, - ); - } - - $eventManager = null; - $mappingTypes = $deprecatedMappingTypes; - } - if (! $this->initialized) { $this->initializeTypes(); } diff --git a/src/DependencyInjection/DoctrineExtension.php b/src/DependencyInjection/DoctrineExtension.php index 0ef52ddd..6a461a90 100644 --- a/src/DependencyInjection/DoctrineExtension.php +++ b/src/DependencyInjection/DoctrineExtension.php @@ -302,13 +302,22 @@ protected function registerMappingDrivers(array $objectManager, ContainerBuilder if ($container->hasDefinition($mappingService)) { $mappingDriverDef = $container->getDefinition($mappingService); $args = $mappingDriverDef->getArguments(); - if ($driverType === 'attribute') { + if ($driverType === 'annotation') { $args[1] = array_merge(array_values($driverPaths), $args[1]); } else { $args[0] = array_merge(array_values($driverPaths), $args[0]); } $mappingDriverDef->setArguments($args); + } elseif ($driverType === 'attribute') { + $mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [ + array_values($driverPaths), + ]); + } elseif ($driverType === 'annotation') { + $mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [ + new Reference($this->getObjectManagerElementName('metadata.annotation_reader')), + array_values($driverPaths), + ]); } else { $mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [ array_values($driverPaths), @@ -695,12 +704,13 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder $def = $container ->setDefinition($connectionId, new ChildDefinition('doctrine.dbal.connection')) ->setPublic(true) - ->setArguments(array_merge( - [$options, new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name))], - // event manager must only be passed for DBAL < 4 - method_exists(Connection::class, 'getEventManager') ? [new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name))] : [], - [$connection['mapping_types']], - )); + ->setArguments([ + $options, + new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)), + // event manager is only supported on DBAL < 4 + method_exists(Connection::class, 'getEventManager') ? new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)) : null, + $connection['mapping_types'], + ]); $container ->registerAliasForArgument($connectionId, Connection::class, sprintf('%s.connection', $name)) diff --git a/tests/ConnectionFactoryTest.php b/tests/ConnectionFactoryTest.php index 82b6e18c..2ae4a051 100644 --- a/tests/ConnectionFactoryTest.php +++ b/tests/ConnectionFactoryTest.php @@ -10,11 +10,9 @@ use Doctrine\DBAL\Driver; use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory; use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; -use InvalidArgumentException; use PHPUnit\Framework\Attributes\IgnoreDeprecations; use function array_intersect_key; -use function method_exists; class ConnectionFactoryTest extends TestCase { @@ -167,34 +165,6 @@ public function testDbnameSuffixForReplicas(): void $this->assertSame('primary_test', $parsedParams['primary']['dbname']); $this->assertSame('replica_test', $parsedParams['replica']['replica1']['dbname']); } - - public function testItThrowsWhenPassingMappingTypesTwice(): void - { - $this->expectException(InvalidArgumentException::class); - - (new ConnectionFactory())->createConnection(['driver' => 'pdo_sqlite'], null, [], []); - } - - #[IgnoreDeprecations] - public function testPassingMappingTypesAsFourthArgumentIsDeprecatedWithDbal4(): void - { - if (method_exists(Connection::class, 'getEventManager')) { - $this->markTestSkipped('DBAL 3 does not trigger the deprecation.'); - } - - $this->expectDeprecationWithIdentifier('https://github.com/doctrine/DoctrineBundle/pull/1976'); - (new ConnectionFactory())->createConnection(['driver' => 'pdo_sqlite'], null, null, []); - } - - public function testPassingMappingTypesAsFourthArgumentIsFineWithDbal3(): void - { - if (! method_exists(Connection::class, 'getEventManager')) { - $this->markTestSkipped('DBAL 4 triggers the deprecation.'); - } - - $this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/DoctrineBundle/pull/1976'); - (new ConnectionFactory())->createConnection(['driver' => 'pdo_sqlite'], null, null, []); - } } class FakeConnection extends Connection diff --git a/tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php b/tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php index c93351d1..a40b7616 100644 --- a/tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php +++ b/tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php @@ -349,17 +349,24 @@ public function testLoadSimpleSingleConnection(): void $definition = $container->getDefinition('doctrine.dbal.default_connection'); - $this->assertDICConstructorArguments($definition, $this->getFactoryArguments([ - 'dbname' => 'db', - 'host' => 'localhost', - 'port' => null, - 'user' => 'root', - 'password' => null, - 'driver' => 'pdo_mysql', - 'driverOptions' => [], - 'defaultTableOptions' => [], - 'idle_connection_ttl' => 600, - ])); + $this->assertDICConstructorArguments($definition, [ + [ + 'dbname' => 'db', + 'host' => 'localhost', + 'port' => null, + 'user' => 'root', + 'password' => null, + 'driver' => 'pdo_mysql', + 'driverOptions' => [], + 'defaultTableOptions' => [], + 'idle_connection_ttl' => 600, + ], + new Reference('doctrine.dbal.default_connection.configuration'), + method_exists(Connection::class, 'getEventManager') + ? new Reference('doctrine.dbal.default_connection.event_manager') + : null, + [], + ]); $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); @@ -383,9 +390,8 @@ public function testLoadSimpleSingleConnectionWithoutDbName(): void $container = $this->loadContainer('orm_service_simple_single_entity_manager_without_dbname'); - $this->assertDICConstructorArguments( - $container->getDefinition('doctrine.dbal.default_connection'), - $this->getFactoryArguments([ + $this->assertDICConstructorArguments($container->getDefinition('doctrine.dbal.default_connection'), [ + [ 'host' => 'localhost', 'port' => null, 'user' => 'root', @@ -394,8 +400,13 @@ public function testLoadSimpleSingleConnectionWithoutDbName(): void 'driverOptions' => [], 'defaultTableOptions' => [], 'idle_connection_ttl' => 600, - ]), - ); + ], + new Reference('doctrine.dbal.default_connection.configuration'), + method_exists(Connection::class, 'getEventManager') + ? new Reference('doctrine.dbal.default_connection.event_manager') + : null, + [], + ]); $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); @@ -417,18 +428,25 @@ public function testLoadSingleConnection(): void $definition = $container->getDefinition('doctrine.dbal.default_connection'); - $this->assertDICConstructorArguments($definition, $this->getFactoryArguments([ - 'host' => 'localhost', - 'driver' => 'pdo_sqlite', - 'driverOptions' => [], - 'user' => 'sqlite_user', - 'port' => null, - 'password' => 'sqlite_s3cr3t', - 'dbname' => 'sqlite_db', - 'memory' => true, - 'defaultTableOptions' => [], - 'idle_connection_ttl' => 600, - ])); + $this->assertDICConstructorArguments($definition, [ + [ + 'host' => 'localhost', + 'driver' => 'pdo_sqlite', + 'driverOptions' => [], + 'user' => 'sqlite_user', + 'port' => null, + 'password' => 'sqlite_s3cr3t', + 'dbname' => 'sqlite_db', + 'memory' => true, + 'defaultTableOptions' => [], + 'idle_connection_ttl' => 600, + ], + new Reference('doctrine.dbal.default_connection.configuration'), + method_exists(Connection::class, 'getEventManager') + ? new Reference('doctrine.dbal.default_connection.event_manager') + : null, + [], + ]); $definition = $container->getDefinition('doctrine.orm.default_entity_manager'); $this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass()); @@ -1752,26 +1770,6 @@ private function compileContainer(ContainerBuilder $container): void $passConfig->addPass(new CacheCompatibilityPass()); $container->compile(); } - - /** - * @param array $params - * - * @return list The expected arguments to the connection factory - */ - private function getFactoryArguments(array $params): array - { - $args = [ - $params, - new Reference('doctrine.dbal.default_connection.configuration'), - ]; - if (method_exists(Connection::class, 'getEventManager')) { - $args[] = new Reference('doctrine.dbal.default_connection.event_manager'); - } - - $args[] = []; - - return $args; - } } class DummySchemaAssetsFilter