From 954e0a314c2f0eb9fb418210445111747de254a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Wed, 6 Mar 2024 13:41:11 +0000 Subject: [PATCH] fix: Allow enum param types: ArrayParameterType and ParameterType (#1408) Fixes #1407 A bit lame fix, but it looks like we did not really use other int types before anyway With this change we can use DBAL v4 new enum types: `ArrayParameterType` and `ParameterType`. Co-authored-by: Alexander M. Turek --- lib/Doctrine/Migrations/InlineParameterFormatter.php | 2 +- .../Migrations/Tests/InlineParameterFormatterTest.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/Migrations/InlineParameterFormatter.php b/lib/Doctrine/Migrations/InlineParameterFormatter.php index 9aa6fc782..741a5ca3d 100644 --- a/lib/Doctrine/Migrations/InlineParameterFormatter.php +++ b/lib/Doctrine/Migrations/InlineParameterFormatter.php @@ -53,7 +53,7 @@ public function formatParameters(array $params, array $types): string return sprintf('with parameters (%s)', implode(', ', $formattedParameters)); } - private function formatParameter(mixed $value, string|int $type): string|int|bool|float|null + private function formatParameter(mixed $value, mixed $type): string|int|bool|float|null { if (is_string($type) && Type::hasType($type)) { return Type::getType($type)->convertToDatabaseValue( diff --git a/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php b/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php index 07a45d565..642c223fc 100644 --- a/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php +++ b/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php @@ -4,12 +4,16 @@ namespace Doctrine\Migrations\Tests; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Types; use Doctrine\Migrations\InlineParameterFormatter; use PHPUnit\Framework\TestCase; +use function class_exists; + class InlineParameterFormatterTest extends TestCase { private Connection $connection; @@ -35,6 +39,8 @@ public function testFormatParameters(): void 11 => true, 12 => false, 13 => [1, true, false, 'string value'], + 14 => 'string value', + 15 => [1, 2, 3], 'named' => 'string value', ]; @@ -54,11 +60,14 @@ public function testFormatParameters(): void 'unknown', 'unknown', 'unknown', + ParameterType::STRING, + // @phpstan-ignore-next-line + class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY, ]; $result = $this->parameterFormatter->formatParameters($params, $types); - $expected = 'with parameters ([string value], [1], [], [1], [1.5], [1,1,,string value], [], [], [string value], [1], [1.5], [true], [false], [1, true, false, string value], :named => [string value])'; + $expected = 'with parameters ([string value], [1], [], [1], [1.5], [1,1,,string value], [], [], [string value], [1], [1.5], [true], [false], [1, true, false, string value], [string value], [1, 2, 3], :named => [string value])'; self::assertSame($expected, $result); }