From 1f3310d24f6db0aaf19f72ad1c0da4caba9a09e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Wed, 6 Mar 2024 12:19:07 +0000 Subject: [PATCH 1/6] fix: Allow new param types 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`. Bumping version of DBAL to 3.6 as before that `ArrayParameterType` did not exist. --- composer.json | 2 +- lib/Doctrine/Migrations/InlineParameterFormatter.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d533f3fb7..0ed7c3cd5 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "require": { "php": "^8.1", "composer-runtime-api": "^2", - "doctrine/dbal": "^3.5.1 || ^4", + "doctrine/dbal": "^3.6 || ^4", "doctrine/deprecations": "^0.5.3 || ^1", "doctrine/event-manager": "^1.2 || ^2.0", "psr/log": "^1.1.3 || ^2 || ^3", diff --git a/lib/Doctrine/Migrations/InlineParameterFormatter.php b/lib/Doctrine/Migrations/InlineParameterFormatter.php index 9aa6fc782..3e41f3c5f 100644 --- a/lib/Doctrine/Migrations/InlineParameterFormatter.php +++ b/lib/Doctrine/Migrations/InlineParameterFormatter.php @@ -4,7 +4,9 @@ namespace Doctrine\Migrations; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Type; use function array_map; @@ -53,7 +55,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, string|int|ArrayParameterType|ParameterType $type): string|int|bool|float|null { if (is_string($type) && Type::hasType($type)) { return Type::getType($type)->convertToDatabaseValue( From d3286bd57d6f9de87b613f6d52856d7630f60cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Wed, 6 Mar 2024 13:14:39 +0000 Subject: [PATCH 2/6] use mixed, add tests --- lib/Doctrine/Migrations/InlineParameterFormatter.php | 4 +--- .../Migrations/Tests/InlineParameterFormatterTest.php | 8 +++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/Migrations/InlineParameterFormatter.php b/lib/Doctrine/Migrations/InlineParameterFormatter.php index 3e41f3c5f..741a5ca3d 100644 --- a/lib/Doctrine/Migrations/InlineParameterFormatter.php +++ b/lib/Doctrine/Migrations/InlineParameterFormatter.php @@ -4,9 +4,7 @@ namespace Doctrine\Migrations; -use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Type; use function array_map; @@ -55,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|ArrayParameterType|ParameterType $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..8ecb9af18 100644 --- a/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php +++ b/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php @@ -4,7 +4,9 @@ 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; @@ -35,6 +37,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 +58,13 @@ public function testFormatParameters(): void 'unknown', 'unknown', 'unknown', + ParameterType::STRING, + ArrayParameterType::INTEGER, ]; $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); } From 98c157fabb89f43b4d4a6f36ac9c5dbc9e9bb3fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Wed, 6 Mar 2024 13:22:17 +0000 Subject: [PATCH 3/6] Update tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php Co-authored-by: Alexander M. Turek --- .../Doctrine/Migrations/Tests/InlineParameterFormatterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php b/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php index 8ecb9af18..f6daa821b 100644 --- a/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php +++ b/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php @@ -59,7 +59,7 @@ public function testFormatParameters(): void 'unknown', 'unknown', ParameterType::STRING, - ArrayParameterType::INTEGER, + class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY, ]; $result = $this->parameterFormatter->formatParameters($params, $types); From a58bc0af8fc5968088b34ae1b0be9fbfd3c0760c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Wed, 6 Mar 2024 13:22:45 +0000 Subject: [PATCH 4/6] revert dependencies bump --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0ed7c3cd5..d533f3fb7 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "require": { "php": "^8.1", "composer-runtime-api": "^2", - "doctrine/dbal": "^3.6 || ^4", + "doctrine/dbal": "^3.5.1 || ^4", "doctrine/deprecations": "^0.5.3 || ^1", "doctrine/event-manager": "^1.2 || ^2.0", "psr/log": "^1.1.3 || ^2 || ^3", From 43c8f70e3c6d104d8edf184ee7b358689e015a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Wed, 6 Mar 2024 13:24:00 +0000 Subject: [PATCH 5/6] phpcs --- .../Doctrine/Migrations/Tests/InlineParameterFormatterTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php b/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php index f6daa821b..e4c75ceb2 100644 --- a/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php +++ b/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php @@ -12,6 +12,8 @@ use Doctrine\Migrations\InlineParameterFormatter; use PHPUnit\Framework\TestCase; +use function class_exists; + class InlineParameterFormatterTest extends TestCase { private Connection $connection; From 1f2b25807677bb72d7ab2622cd5dee4b545ac2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bundyra?= Date: Wed, 6 Mar 2024 13:29:11 +0000 Subject: [PATCH 6/6] phpstan-ignore-next-line --- tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php b/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php index e4c75ceb2..642c223fc 100644 --- a/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php +++ b/tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php @@ -61,6 +61,7 @@ public function testFormatParameters(): void 'unknown', 'unknown', ParameterType::STRING, + // @phpstan-ignore-next-line class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY, ];