From a2899736604b89938436b1df2311a3c66175ecdc Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 17 May 2024 16:57:19 +0200 Subject: [PATCH] fix bigint handling with DBAL 4 --- .../Doctrine/PropertyInfo/DoctrineExtractor.php | 10 ++++++++-- .../Tests/PropertyInfo/DoctrineExtractorTest.php | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index a0ff5da8aaf22..02b29ae9942d9 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -130,6 +130,12 @@ public function getType(string $class, string $property, array $context = []): ? } $nullable = $metadata instanceof ClassMetadata && $metadata->isNullable($property); + + // DBAL 4 has a special fallback strategy for BINGINT (int -> string) + if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) { + return Type::collection(Type::int(), Type::string()); + } + $enumType = null; if (null !== $enumClass = self::getMappingValue($metadata->getFieldMapping($property), 'enumType') ?? null) { @@ -241,8 +247,8 @@ public function getTypes(string $class, string $property, array $context = []): // DBAL 4 has a special fallback strategy for BINGINT (int -> string) if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) { return [ - new Type(Type::BUILTIN_TYPE_INT, $nullable), - new Type(Type::BUILTIN_TYPE_STRING, $nullable), + new LegacyType(LegacyType::BUILTIN_TYPE_INT, $nullable), + new LegacyType(LegacyType::BUILTIN_TYPE_STRING, $nullable), ]; } diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php index d1baaa24c7f89..c0ab3e1c63783 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -156,7 +156,7 @@ public static function legacyTypesProvider(): array { // DBAL 4 has a special fallback strategy for BINGINT (int -> string) if (!method_exists(BigIntType::class, 'getName')) { - $expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_INT), new Type(LegacyType::BUILTIN_TYPE_STRING)]; + $expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_STRING)]; } else { $expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_STRING)]; } @@ -298,9 +298,16 @@ public function testExtract(string $property, ?Type $type) */ public static function typeProvider(): iterable { + // DBAL 4 has a special fallback strategy for BINGINT (int -> string) + if (!method_exists(BigIntType::class, 'getName')) { + $expectedBigIntType = Type::collection(Type::int(), Type::string()); + } else { + $expectedBigIntType = Type::string(); + } + yield ['id', Type::int()]; yield ['guid', Type::string()]; - yield ['bigint', Type::string()]; + yield ['bigint', $expectedBigIntType]; yield ['time', Type::object(\DateTime::class)]; yield ['timeImmutable', Type::object(\DateTimeImmutable::class)]; yield ['dateInterval', Type::object(\DateInterval::class)];