Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .doctrine-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-dev-stability.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 4 additions & 3 deletions .symfony.bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
17 changes: 0 additions & 17 deletions UPGRADE-2.17.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
46 changes: 5 additions & 41 deletions src/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -63,52 +61,18 @@ public function __construct(
/**
* Create a connection by name.
*
* @param mixed[] $params
* @param EventManager|array<string, string>|null $eventManagerOrMappingTypes
* @param array<string, string> $deprecatedMappingTypes
* @param mixed[] $params
* @param array<string, string> $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();
}
Expand Down
24 changes: 17 additions & 7 deletions src/DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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))
Expand Down
30 changes: 0 additions & 30 deletions tests/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
94 changes: 46 additions & 48 deletions tests/DependencyInjection/AbstractDoctrineExtensionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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',
Expand All @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -1752,26 +1770,6 @@ private function compileContainer(ContainerBuilder $container): void
$passConfig->addPass(new CacheCompatibilityPass());
$container->compile();
}

/**
* @param array<string, mixed> $params
*
* @return list<mixed> 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
Expand Down