Skip to content

Commit

Permalink
Merge branch '3.7.x' into 3.8.x
Browse files Browse the repository at this point in the history
* 3.7.x:
  fix: Allow enum param types: ArrayParameterType and ParameterType (#1408)
  • Loading branch information
derrabus committed Mar 6, 2024
2 parents 0a09b85 + 954e0a3 commit 44c5a96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/InlineParameterFormatter.php
Original file line number Diff line number Diff line change
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/InlineParameterFormatterTest.php
Original file line number Diff line number Diff line change
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 44c5a96

Please sign in to comment.