Skip to content

Commit d991e4b

Browse files
authored
fix(DBAL): handle Dbal 4.x EnumType (#243)
1 parent c7ca4fd commit d991e4b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

DependencyInjection/Compiler/RegisterEnumTypePass.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\DependencyInjection\Compiler;
1414

15+
use Doctrine\DBAL\Types\EnumType;
16+
use Doctrine\DBAL\Types\Types;
1517
use Doctrine\Persistence\ManagerRegistry;
1618
use Fresh\DoctrineEnumBundle\Exception\InvalidArgumentException;
1719
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
@@ -39,8 +41,9 @@ public function process(ContainerBuilder $container): void
3941
foreach ($doctrine->getConnectionNames() as $connectionName) {
4042
$definition = $container->getDefinition($connectionName);
4143
$mappingTypes = (array) $definition->getArgument(3);
42-
if (!isset($mappingTypes['enum']) || 'string' !== $mappingTypes['enum']) {
43-
$mappingTypes['enum'] = 'string';
44+
$expectedType = class_exists(EnumType::class) ? Types::ENUM : 'string';
45+
if (!isset($mappingTypes['enum']) || $expectedType !== $mappingTypes['enum']) {
46+
$mappingTypes['enum'] = $expectedType;
4447
$definition->setArgument(3, $mappingTypes);
4548
}
4649
}

Tests/DependencyInjection/Compiler/RegisterEnumTypePassTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Fresh\DoctrineEnumBundle\Tests\DependencyInjection\Compiler;
1414

15+
use Doctrine\DBAL\Types\Types;
1516
use Doctrine\Persistence\ManagerRegistry;
1617
use Fresh\DoctrineEnumBundle\DependencyInjection\Compiler\RegisterEnumTypePass;
1718
use Fresh\DoctrineEnumBundle\Exception\InvalidArgumentException;
@@ -79,7 +80,7 @@ public function processSuccessful(): void
7980
$default
8081
->expects(self::once())
8182
->method('setArgument')
82-
->with(3, ['test' => '_test', 'enum' => 'string'])
83+
->with(3, ['test' => '_test', 'enum' => Types::ENUM])
8384
;
8485

8586
$custom1 = $this->createMock(Definition::class);
@@ -92,15 +93,15 @@ public function processSuccessful(): void
9293
$custom1
9394
->expects(self::once())
9495
->method('setArgument')
95-
->with(3, ['test' => '_test', 'enum' => 'string'])
96+
->with(3, ['test' => '_test', 'enum' => Types::ENUM])
9697
;
9798

9899
$custom2 = $this->createMock(Definition::class);
99100
$custom2
100101
->expects(self::once())
101102
->method('getArgument')
102103
->with(3)
103-
->willReturn(['test' => '_test', 'enum' => 'string'])
104+
->willReturn(['test' => '_test', 'enum' => Types::ENUM])
104105
;
105106
$custom2
106107
->expects(self::never())

0 commit comments

Comments
 (0)