Skip to content

Commit

Permalink
fix: Allow enum param types: ArrayParameterType and ParameterType (#1408
Browse files Browse the repository at this point in the history
)

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 <me@derrabus.de>
  • Loading branch information
michalbundyra and derrabus committed Mar 6, 2024
1 parent ebb383e commit 954e0a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/Migrations/InlineParameterFormatter.php
Expand Up @@ -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(
Expand Down
11 changes: 10 additions & 1 deletion tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php
Expand Up @@ -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;
Expand All @@ -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',
];

Expand All @@ -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);
}
Expand Down

0 comments on commit 954e0a3

Please sign in to comment.