|
11 | 11 | use Doctrine\DBAL\ParameterType;
|
12 | 12 | use Doctrine\DBAL\Types\Types;
|
13 | 13 | use Doctrine\ORM\Query\ParameterTypeInferer;
|
| 14 | +use Doctrine\Tests\Models\Enums\AccessLevel; |
| 15 | +use Doctrine\Tests\Models\Enums\UserStatus; |
14 | 16 | use Doctrine\Tests\OrmTestCase;
|
| 17 | +use Generator; |
| 18 | + |
| 19 | +use const PHP_VERSION_ID; |
15 | 20 |
|
16 | 21 | class ParameterTypeInfererTest extends OrmTestCase
|
17 | 22 | {
|
18 |
| - /** @psalm-return list<array{mixed, int|string}> */ |
19 |
| - public function providerParameterTypeInferer(): array |
| 23 | + /** @psalm-return Generator<string, array{mixed, (int|string)}> */ |
| 24 | + public function providerParameterTypeInferer(): Generator |
20 | 25 | {
|
21 |
| - return [ |
22 |
| - [1, Types::INTEGER], |
23 |
| - ['bar', ParameterType::STRING], |
24 |
| - ['1', ParameterType::STRING], |
25 |
| - [new DateTime(), Types::DATETIME_MUTABLE], |
26 |
| - [new DateTimeImmutable(), Types::DATETIME_IMMUTABLE], |
27 |
| - [new DateInterval('P1D'), Types::DATEINTERVAL], |
28 |
| - [[2], Connection::PARAM_INT_ARRAY], |
29 |
| - [['foo'], Connection::PARAM_STR_ARRAY], |
30 |
| - [['1','2'], Connection::PARAM_STR_ARRAY], |
31 |
| - [[], Connection::PARAM_STR_ARRAY], |
32 |
| - [true, Types::BOOLEAN], |
33 |
| - ]; |
| 26 | + yield 'integer' => [1, Types::INTEGER]; |
| 27 | + yield 'string' => ['bar', ParameterType::STRING]; |
| 28 | + yield 'numeric_string' => ['1', ParameterType::STRING]; |
| 29 | + yield 'datetime_object' => [new DateTime(), Types::DATETIME_MUTABLE]; |
| 30 | + yield 'datetime_immutable_object' => [new DateTimeImmutable(), Types::DATETIME_IMMUTABLE]; |
| 31 | + yield 'date_interval_object' => [new DateInterval('P1D'), Types::DATEINTERVAL]; |
| 32 | + yield 'array_of_int' => [[2], Connection::PARAM_INT_ARRAY]; |
| 33 | + yield 'array_of_string' => [['foo'], Connection::PARAM_STR_ARRAY]; |
| 34 | + yield 'array_of_numeric_string' => [['1', '2'], Connection::PARAM_STR_ARRAY]; |
| 35 | + yield 'empty_array' => [[], Connection::PARAM_STR_ARRAY]; |
| 36 | + yield 'boolean' => [true, Types::BOOLEAN]; |
| 37 | + |
| 38 | + if (PHP_VERSION_ID >= 80100) { |
| 39 | + yield 'int_backed_enum' => [AccessLevel::Admin, Types::INTEGER]; |
| 40 | + yield 'string_backed_enum' => [UserStatus::Active, Types::STRING]; |
| 41 | + yield 'array_of_int_backed_enum' => [[AccessLevel::Admin], Connection::PARAM_INT_ARRAY]; |
| 42 | + yield 'array_of_string_backed_enum' => [[UserStatus::Active], Connection::PARAM_STR_ARRAY]; |
| 43 | + } |
34 | 44 | }
|
35 | 45 |
|
36 | 46 | /**
|
|
0 commit comments