Skip to content

Commit cd5d4da

Browse files
authored
Merge pull request #2095 from doctrine/2.17.x-merge-up-into-2.18.x_LXv6IL5P
Merge release 2.17.2 into 2.18.x
2 parents 2b52637 + 2543589 commit cd5d4da

File tree

9 files changed

+82
-150
lines changed

9 files changed

+82
-150
lines changed

.doctrine-project.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@
1010
"slug": "latest",
1111
"upcoming": true
1212
},
13+
{
14+
"name": "2.18",
15+
"branchName": "2.18.x",
16+
"slug": "2.18",
17+
"upcoming": true
18+
},
1319
{
1420
"name": "2.17",
1521
"branchName": "2.17.x",
1622
"slug": "2.17",
17-
"upcoming": true
23+
"current": true
1824
},
1925
{
2026
"name": "2.16",
2127
"slug": "2.16",
22-
"current": true
28+
"maintained": false
2329
},
2430
{
2531
"name": "2.15",

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
with:
9090
php-version: "${{ matrix.php-version }}"
9191
coverage: "pcov"
92-
ini-values: "zend.assertions=1"
92+
ini-file: "development"
9393
extensions: "pdo_sqlite"
9494
tools: "flex"
9595

.github/workflows/test-dev-stability.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: "shivammathur/setup-php@v2"
3636
with:
3737
php-version: "${{ matrix.php-version }}"
38-
ini-values: "zend.assertions=1"
38+
ini-file: "development"
3939
extensions: "pdo_sqlite"
4040
tools: "flex"
4141

.symfony.bundle.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ branches:
1212
- "2.15.x"
1313
- "2.16.x"
1414
- "2.17.x"
15+
- "2.18.x"
1516
maintained_branches:
16-
- "2.16.x"
1717
- "2.17.x"
18+
- "2.18.x"
1819
doc_dir: "docs/en/"
19-
current_branch: "2.16.x"
20-
dev_branch: "2.17.x"
20+
current_branch: "2.17.x"
21+
dev_branch: "2.18.x"

UPGRADE-2.17.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,3 @@ deprecated. You should stop using it as soon as you upgrade to Doctrine DBAL 4.
2626

2727
This option is a no-op when using `doctrine/dbal` 4 and has been conditionally
2828
deprecated. You should stop using it as soon as you upgrade to Doctrine DBAL 4.
29-
30-
ConnectionFactory::createConnection() signature change
31-
------------------------------------------------------
32-
33-
The signature of `ConnectionFactory::createConnection()` will change with
34-
version 3.0 of the bundle.
35-
36-
As soon as you upgrade to Doctrine DBAL 4, you should use stop passing an event
37-
manager argument.
38-
39-
```diff
40-
- $connectionFactory->createConnection($params, $config, $eventManager, $mappingTypes)
41-
+ $connectionFactory->createConnection($params, $config, $mappingTypes)
42-
```
43-
44-
As a small breaking change, it is no longer fully possible to use named
45-
arguments with that method until 3.0.

src/ConnectionFactory.php

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
use function array_merge;
2626
use function class_exists;
27-
use function func_num_args;
28-
use function is_array;
2927
use function is_subclass_of;
3028
use function method_exists;
3129

@@ -63,52 +61,18 @@ public function __construct(
6361
/**
6462
* Create a connection by name.
6563
*
66-
* @param mixed[] $params
67-
* @param EventManager|array<string, string>|null $eventManagerOrMappingTypes
68-
* @param array<string, string> $deprecatedMappingTypes
64+
* @param mixed[] $params
65+
* @param array<string, string> $mappingTypes
6966
* @phpstan-param Params $params
7067
*
7168
* @return Connection
72-
*
73-
* @no-named-arguments
7469
*/
75-
public function createConnection(
76-
array $params,
77-
Configuration|null $config = null,
78-
EventManager|array|null $eventManagerOrMappingTypes = [],
79-
array $deprecatedMappingTypes = [],
80-
) {
81-
if (! method_exists(Connection::class, 'getEventManager') && $eventManagerOrMappingTypes instanceof EventManager) {
70+
public function createConnection(array $params, Configuration|null $config = null, EventManager|null $eventManager = null, array $mappingTypes = [])
71+
{
72+
if (! method_exists(Connection::class, 'getEventManager') && $eventManager !== null) {
8273
throw new InvalidArgumentException('Passing an EventManager instance is not supported with DBAL > 3');
8374
}
8475

85-
if (is_array($eventManagerOrMappingTypes) && func_num_args() === 4) {
86-
throw new InvalidArgumentException('Passing mapping types both as 3rd and 4th argument makes no sense.');
87-
}
88-
89-
if ($eventManagerOrMappingTypes instanceof EventManager) {
90-
// DBAL 3
91-
$eventManager = $eventManagerOrMappingTypes;
92-
$mappingTypes = $deprecatedMappingTypes;
93-
} elseif (is_array($eventManagerOrMappingTypes)) {
94-
// Future signature
95-
$eventManager = null;
96-
$mappingTypes = $eventManagerOrMappingTypes;
97-
} else {
98-
// Legacy signature
99-
if (! method_exists(Connection::class, 'getEventManager')) {
100-
Deprecation::trigger(
101-
'doctrine/doctrine-bundle',
102-
'https://github.com/doctrine/DoctrineBundle/pull/1976',
103-
'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.',
104-
__METHOD__,
105-
);
106-
}
107-
108-
$eventManager = null;
109-
$mappingTypes = $deprecatedMappingTypes;
110-
}
111-
11276
if (! $this->initialized) {
11377
$this->initializeTypes();
11478
}

src/DependencyInjection/DoctrineExtension.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,22 @@ protected function registerMappingDrivers(array $objectManager, ContainerBuilder
302302
if ($container->hasDefinition($mappingService)) {
303303
$mappingDriverDef = $container->getDefinition($mappingService);
304304
$args = $mappingDriverDef->getArguments();
305-
if ($driverType === 'attribute') {
305+
if ($driverType === 'annotation') {
306306
$args[1] = array_merge(array_values($driverPaths), $args[1]);
307307
} else {
308308
$args[0] = array_merge(array_values($driverPaths), $args[0]);
309309
}
310310

311311
$mappingDriverDef->setArguments($args);
312+
} elseif ($driverType === 'attribute') {
313+
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
314+
array_values($driverPaths),
315+
]);
316+
} elseif ($driverType === 'annotation') {
317+
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
318+
new Reference($this->getObjectManagerElementName('metadata.annotation_reader')),
319+
array_values($driverPaths),
320+
]);
312321
} else {
313322
$mappingDriverDef = new Definition($this->getMetadataDriverClass($driverType), [
314323
array_values($driverPaths),
@@ -695,12 +704,13 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder
695704
$def = $container
696705
->setDefinition($connectionId, new ChildDefinition('doctrine.dbal.connection'))
697706
->setPublic(true)
698-
->setArguments(array_merge(
699-
[$options, new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name))],
700-
// event manager must only be passed for DBAL < 4
701-
method_exists(Connection::class, 'getEventManager') ? [new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name))] : [],
702-
[$connection['mapping_types']],
703-
));
707+
->setArguments([
708+
$options,
709+
new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)),
710+
// event manager is only supported on DBAL < 4
711+
method_exists(Connection::class, 'getEventManager') ? new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name)) : null,
712+
$connection['mapping_types'],
713+
]);
704714

705715
$container
706716
->registerAliasForArgument($connectionId, Connection::class, sprintf('%s.connection', $name))

tests/ConnectionFactoryTest.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
use Doctrine\DBAL\Driver;
1111
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
1212
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
13-
use InvalidArgumentException;
1413
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1514

1615
use function array_intersect_key;
17-
use function method_exists;
1816

1917
class ConnectionFactoryTest extends TestCase
2018
{
@@ -167,34 +165,6 @@ public function testDbnameSuffixForReplicas(): void
167165
$this->assertSame('primary_test', $parsedParams['primary']['dbname']);
168166
$this->assertSame('replica_test', $parsedParams['replica']['replica1']['dbname']);
169167
}
170-
171-
public function testItThrowsWhenPassingMappingTypesTwice(): void
172-
{
173-
$this->expectException(InvalidArgumentException::class);
174-
175-
(new ConnectionFactory())->createConnection(['driver' => 'pdo_sqlite'], null, [], []);
176-
}
177-
178-
#[IgnoreDeprecations]
179-
public function testPassingMappingTypesAsFourthArgumentIsDeprecatedWithDbal4(): void
180-
{
181-
if (method_exists(Connection::class, 'getEventManager')) {
182-
$this->markTestSkipped('DBAL 3 does not trigger the deprecation.');
183-
}
184-
185-
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/DoctrineBundle/pull/1976');
186-
(new ConnectionFactory())->createConnection(['driver' => 'pdo_sqlite'], null, null, []);
187-
}
188-
189-
public function testPassingMappingTypesAsFourthArgumentIsFineWithDbal3(): void
190-
{
191-
if (! method_exists(Connection::class, 'getEventManager')) {
192-
$this->markTestSkipped('DBAL 4 triggers the deprecation.');
193-
}
194-
195-
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/DoctrineBundle/pull/1976');
196-
(new ConnectionFactory())->createConnection(['driver' => 'pdo_sqlite'], null, null, []);
197-
}
198168
}
199169

200170
class FakeConnection extends Connection

tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,24 @@ public function testLoadSimpleSingleConnection(): void
349349

350350
$definition = $container->getDefinition('doctrine.dbal.default_connection');
351351

352-
$this->assertDICConstructorArguments($definition, $this->getFactoryArguments([
353-
'dbname' => 'db',
354-
'host' => 'localhost',
355-
'port' => null,
356-
'user' => 'root',
357-
'password' => null,
358-
'driver' => 'pdo_mysql',
359-
'driverOptions' => [],
360-
'defaultTableOptions' => [],
361-
'idle_connection_ttl' => 600,
362-
]));
352+
$this->assertDICConstructorArguments($definition, [
353+
[
354+
'dbname' => 'db',
355+
'host' => 'localhost',
356+
'port' => null,
357+
'user' => 'root',
358+
'password' => null,
359+
'driver' => 'pdo_mysql',
360+
'driverOptions' => [],
361+
'defaultTableOptions' => [],
362+
'idle_connection_ttl' => 600,
363+
],
364+
new Reference('doctrine.dbal.default_connection.configuration'),
365+
method_exists(Connection::class, 'getEventManager')
366+
? new Reference('doctrine.dbal.default_connection.event_manager')
367+
: null,
368+
[],
369+
]);
363370

364371
$definition = $container->getDefinition('doctrine.orm.default_entity_manager');
365372
$this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass());
@@ -383,9 +390,8 @@ public function testLoadSimpleSingleConnectionWithoutDbName(): void
383390

384391
$container = $this->loadContainer('orm_service_simple_single_entity_manager_without_dbname');
385392

386-
$this->assertDICConstructorArguments(
387-
$container->getDefinition('doctrine.dbal.default_connection'),
388-
$this->getFactoryArguments([
393+
$this->assertDICConstructorArguments($container->getDefinition('doctrine.dbal.default_connection'), [
394+
[
389395
'host' => 'localhost',
390396
'port' => null,
391397
'user' => 'root',
@@ -394,8 +400,13 @@ public function testLoadSimpleSingleConnectionWithoutDbName(): void
394400
'driverOptions' => [],
395401
'defaultTableOptions' => [],
396402
'idle_connection_ttl' => 600,
397-
]),
398-
);
403+
],
404+
new Reference('doctrine.dbal.default_connection.configuration'),
405+
method_exists(Connection::class, 'getEventManager')
406+
? new Reference('doctrine.dbal.default_connection.event_manager')
407+
: null,
408+
[],
409+
]);
399410

400411
$definition = $container->getDefinition('doctrine.orm.default_entity_manager');
401412
$this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass());
@@ -417,18 +428,25 @@ public function testLoadSingleConnection(): void
417428

418429
$definition = $container->getDefinition('doctrine.dbal.default_connection');
419430

420-
$this->assertDICConstructorArguments($definition, $this->getFactoryArguments([
421-
'host' => 'localhost',
422-
'driver' => 'pdo_sqlite',
423-
'driverOptions' => [],
424-
'user' => 'sqlite_user',
425-
'port' => null,
426-
'password' => 'sqlite_s3cr3t',
427-
'dbname' => 'sqlite_db',
428-
'memory' => true,
429-
'defaultTableOptions' => [],
430-
'idle_connection_ttl' => 600,
431-
]));
431+
$this->assertDICConstructorArguments($definition, [
432+
[
433+
'host' => 'localhost',
434+
'driver' => 'pdo_sqlite',
435+
'driverOptions' => [],
436+
'user' => 'sqlite_user',
437+
'port' => null,
438+
'password' => 'sqlite_s3cr3t',
439+
'dbname' => 'sqlite_db',
440+
'memory' => true,
441+
'defaultTableOptions' => [],
442+
'idle_connection_ttl' => 600,
443+
],
444+
new Reference('doctrine.dbal.default_connection.configuration'),
445+
method_exists(Connection::class, 'getEventManager')
446+
? new Reference('doctrine.dbal.default_connection.event_manager')
447+
: null,
448+
[],
449+
]);
432450

433451
$definition = $container->getDefinition('doctrine.orm.default_entity_manager');
434452
$this->assertEquals('%doctrine.orm.entity_manager.class%', $definition->getClass());
@@ -1752,26 +1770,6 @@ private function compileContainer(ContainerBuilder $container): void
17521770
$passConfig->addPass(new CacheCompatibilityPass());
17531771
$container->compile();
17541772
}
1755-
1756-
/**
1757-
* @param array<string, mixed> $params
1758-
*
1759-
* @return list<mixed> The expected arguments to the connection factory
1760-
*/
1761-
private function getFactoryArguments(array $params): array
1762-
{
1763-
$args = [
1764-
$params,
1765-
new Reference('doctrine.dbal.default_connection.configuration'),
1766-
];
1767-
if (method_exists(Connection::class, 'getEventManager')) {
1768-
$args[] = new Reference('doctrine.dbal.default_connection.event_manager');
1769-
}
1770-
1771-
$args[] = [];
1772-
1773-
return $args;
1774-
}
17751773
}
17761774

17771775
class DummySchemaAssetsFilter

0 commit comments

Comments
 (0)