Skip to content

Commit

Permalink
Leverage new ArrayParameterType constants (doctrine#10352)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Dec 30, 2022
1 parent b31afda commit 57f2569
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"ext-ctype": "*",
"doctrine/collections": "^2.1",
"doctrine/common": "^3.3",
"doctrine/dbal": "^3.5",
"doctrine/dbal": "^3.6@dev",
"doctrine/deprecations": "^0.5.3 || ^1",
"doctrine/event-manager": "^1.2 || ^2",
"doctrine/inflector": "^1.4 || ^2.0",
Expand Down
7 changes: 4 additions & 3 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Expr\Comparison;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\ParameterType;
Expand Down Expand Up @@ -1885,9 +1886,9 @@ private function getArrayBindingType(ParameterType|int|string $type): int
}

return match ($type) {
ParameterType::STRING => Connection::PARAM_STR_ARRAY,
ParameterType::INTEGER => Connection::PARAM_INT_ARRAY,
ParameterType::ASCII => Connection::PARAM_ASCII_STR_ARRAY,
ParameterType::STRING => ArrayParameterType::STRING,
ParameterType::INTEGER => ArrayParameterType::INTEGER,
ParameterType::ASCII => ArrayParameterType::ASCII,
};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Query/ParameterTypeInferer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use DateInterval;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Types\Types;

Expand Down Expand Up @@ -64,8 +64,8 @@ public static function inferType(mixed $value): ParameterType|int|string
}

return is_int($firstValue)
? Connection::PARAM_INT_ARRAY
: Connection::PARAM_STR_ARRAY;
? ArrayParameterType::INTEGER
: ArrayParameterType::STRING;
}

return ParameterType::STRING;
Expand Down
16 changes: 8 additions & 8 deletions tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use DateInterval;
use DateTime;
use DateTimeImmutable;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\ParameterTypeInferer;
Expand All @@ -18,7 +18,7 @@

class ParameterTypeInfererTest extends OrmTestCase
{
/** @psalm-return Generator<string, array{mixed, (int|string)}> */
/** @psalm-return Generator<string, array{mixed, (ParameterType|int|string)}> */
public function providerParameterTypeInferer(): Generator
{
yield 'integer' => [1, Types::INTEGER];
Expand All @@ -27,15 +27,15 @@ public function providerParameterTypeInferer(): Generator
yield 'datetime_object' => [new DateTime(), Types::DATETIME_MUTABLE];
yield 'datetime_immutable_object' => [new DateTimeImmutable(), Types::DATETIME_IMMUTABLE];
yield 'date_interval_object' => [new DateInterval('P1D'), Types::DATEINTERVAL];
yield 'array_of_int' => [[2], Connection::PARAM_INT_ARRAY];
yield 'array_of_string' => [['foo'], Connection::PARAM_STR_ARRAY];
yield 'array_of_numeric_string' => [['1', '2'], Connection::PARAM_STR_ARRAY];
yield 'empty_array' => [[], Connection::PARAM_STR_ARRAY];
yield 'array_of_int' => [[2], ArrayParameterType::INTEGER];
yield 'array_of_string' => [['foo'], ArrayParameterType::STRING];
yield 'array_of_numeric_string' => [['1', '2'], ArrayParameterType::STRING];
yield 'empty_array' => [[], ArrayParameterType::STRING];
yield 'boolean' => [true, Types::BOOLEAN];
yield 'int_backed_enum' => [AccessLevel::Admin, Types::INTEGER];
yield 'string_backed_enum' => [UserStatus::Active, Types::STRING];
yield 'array_of_int_backed_enum' => [[AccessLevel::Admin], Connection::PARAM_INT_ARRAY];
yield 'array_of_string_backed_enum' => [[UserStatus::Active], Connection::PARAM_STR_ARRAY];
yield 'array_of_int_backed_enum' => [[AccessLevel::Admin], ArrayParameterType::INTEGER];
yield 'array_of_string_backed_enum' => [[UserStatus::Active], ArrayParameterType::STRING];
}

/** @dataProvider providerParameterTypeInferer */
Expand Down

0 comments on commit 57f2569

Please sign in to comment.