Skip to content

Commit 954e0a3

Browse files
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 <[email protected]>
1 parent ebb383e commit 954e0a3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/Doctrine/Migrations/InlineParameterFormatter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function formatParameters(array $params, array $types): string
5353
return sprintf('with parameters (%s)', implode(', ', $formattedParameters));
5454
}
5555

56-
private function formatParameter(mixed $value, string|int $type): string|int|bool|float|null
56+
private function formatParameter(mixed $value, mixed $type): string|int|bool|float|null
5757
{
5858
if (is_string($type) && Type::hasType($type)) {
5959
return Type::getType($type)->convertToDatabaseValue(

tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
namespace Doctrine\Migrations\Tests;
66

7+
use Doctrine\DBAL\ArrayParameterType;
78
use Doctrine\DBAL\Connection;
9+
use Doctrine\DBAL\ParameterType;
810
use Doctrine\DBAL\Platforms\AbstractPlatform;
911
use Doctrine\DBAL\Types\Types;
1012
use Doctrine\Migrations\InlineParameterFormatter;
1113
use PHPUnit\Framework\TestCase;
1214

15+
use function class_exists;
16+
1317
class InlineParameterFormatterTest extends TestCase
1418
{
1519
private Connection $connection;
@@ -35,6 +39,8 @@ public function testFormatParameters(): void
3539
11 => true,
3640
12 => false,
3741
13 => [1, true, false, 'string value'],
42+
14 => 'string value',
43+
15 => [1, 2, 3],
3844
'named' => 'string value',
3945
];
4046

@@ -54,11 +60,14 @@ public function testFormatParameters(): void
5460
'unknown',
5561
'unknown',
5662
'unknown',
63+
ParameterType::STRING,
64+
// @phpstan-ignore-next-line
65+
class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY,
5766
];
5867

5968
$result = $this->parameterFormatter->formatParameters($params, $types);
6069

61-
$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])';
70+
$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])';
6271

6372
self::assertSame($expected, $result);
6473
}

0 commit comments

Comments
 (0)