Skip to content

Commit 7205b33

Browse files
authored
mapping types are always the last argument (#249)
1 parent 4c85da1 commit 7205b33

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

DependencyInjection/Compiler/RegisterEnumTypePass.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ public function process(ContainerBuilder $container): void
4141
/* @see \Doctrine\Bundle\DoctrineBundle\ConnectionFactory::createConnection */
4242
foreach ($doctrine->getConnectionNames() as $connectionName) {
4343
$definition = $container->getDefinition($connectionName);
44-
$mappingTypes = (array) $definition->getArgument(3);
44+
$lastArgument = count($definition->getArguments()) - 1;
45+
$mappingTypes = (array) $definition->getArgument($lastArgument);
4546
$expectedType = class_exists(EnumType::class) ? Types::ENUM : 'string';
4647
if (!isset($mappingTypes['enum']) || $expectedType !== $mappingTypes['enum']) {
4748
$mappingTypes['enum'] = $expectedType;
48-
$definition->setArgument(3, $mappingTypes);
49+
$definition->setArgument($lastArgument, $mappingTypes);
4950
}
5051
}
5152
}

Tests/DependencyInjection/Compiler/RegisterEnumTypePassTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\DependencyInjection\ContainerBuilder;
2424
use Symfony\Component\DependencyInjection\ContainerInterface;
2525
use Symfony\Component\DependencyInjection\Definition;
26+
use Symfony\Component\DependencyInjection\Reference;
2627

2728
/**
2829
* RegisterEnumTypePassTest.
@@ -72,6 +73,16 @@ public function processSuccessful(): void
7273
;
7374

7475
$default = $this->createMock(Definition::class);
76+
$default
77+
->expects(self::once())
78+
->method('getArguments')
79+
->willReturn([
80+
['url' => 'mysql:\\\\'],
81+
new Reference('doctrine.dbal.default_connection.configuration'),
82+
null,
83+
[],
84+
])
85+
;
7586
$default
7687
->expects(self::once())
7788
->method('getArgument')
@@ -85,6 +96,16 @@ public function processSuccessful(): void
8596
;
8697

8798
$custom1 = $this->createMock(Definition::class);
99+
$custom1
100+
->expects(self::once())
101+
->method('getArguments')
102+
->willReturn([
103+
['url' => 'mysql:\\\\'],
104+
new Reference('doctrine.dbal.custom1_connection.configuration'),
105+
null,
106+
[],
107+
])
108+
;
88109
$custom1
89110
->expects(self::once())
90111
->method('getArgument')
@@ -98,6 +119,16 @@ public function processSuccessful(): void
98119
;
99120

100121
$custom2 = $this->createMock(Definition::class);
122+
$custom2
123+
->expects(self::once())
124+
->method('getArguments')
125+
->willReturn([
126+
['url' => 'mysql:\\\\'],
127+
new Reference('doctrine.dbal.custom2_connection.configuration'),
128+
null,
129+
[],
130+
])
131+
;
101132
$custom2
102133
->expects(self::once())
103134
->method('getArgument')

0 commit comments

Comments
 (0)