|
4 | 4 |
|
5 | 5 | namespace Yiisoft\Db\Pgsql\Tests; |
6 | 6 |
|
| 7 | +use PHPUnit\Framework\Attributes\DataProvider; |
7 | 8 | use PHPUnit\Framework\TestCase; |
8 | 9 | use Yiisoft\Db\Pgsql\Data\ArrayParser; |
9 | 10 |
|
10 | 11 | /** |
11 | 12 | * @group pgsql |
12 | | - * |
13 | | - * @psalm-suppress PropertyNotSetInConstructor |
14 | 13 | */ |
15 | 14 | final class ArrayParserTest extends TestCase |
16 | 15 | { |
17 | | - public function testParser(): void |
| 16 | + public static function parserProvider(): iterable |
18 | 17 | { |
19 | | - $arrayParse = new ArrayParser(); |
20 | | - |
21 | | - $this->assertSame([0 => null, 1 => null], $arrayParse->parse('{NULL,NULL}')); |
22 | | - $this->assertSame([], $arrayParse->parse('{}')); |
23 | | - $this->assertSame([0 => null, 1 => null], $arrayParse->parse('{,}')); |
24 | | - $this->assertSame([0 => '1', 1 => '2', 2 => '3'], $arrayParse->parse('{1,2,3}')); |
25 | | - $this->assertSame([0 => '1', 1 => '-2', 2 => null, 3 => '42'], $arrayParse->parse('{1,-2,NULL,42}')); |
26 | | - $this->assertSame([[0 => 'text'], [0 => null], [0 => '1']], $arrayParse->parse('{{text},{NULL},{1}}')); |
27 | | - $this->assertSame([0 => ''], $arrayParse->parse('{""}')); |
28 | | - $this->assertSame( |
29 | | - [0 => '[",","null",true,"false","f"]'], |
30 | | - $arrayParse->parse('{"[\",\",\"null\",true,\"false\",\"f\"]"}'), |
31 | | - ); |
32 | | - |
| 18 | + yield [[], '{}']; |
| 19 | + yield [[''], '{""}']; |
| 20 | + yield [[null, null], '{NULL,NULL}']; |
| 21 | + yield [[null, null], '{,}']; |
| 22 | + yield [ |
| 23 | + ["a\nb"], |
| 24 | + "{\"a\nb\"}", |
| 25 | + ]; |
| 26 | + yield [ |
| 27 | + ['1', '2', '3'], |
| 28 | + '{1,2,3}', |
| 29 | + ]; |
| 30 | + yield [ |
| 31 | + ['1', '-2', null, '42'], |
| 32 | + '{1,-2,NULL,42}', |
| 33 | + ]; |
| 34 | + yield [ |
| 35 | + [['text'], [null], ['1']], |
| 36 | + '{{text},{NULL},{1}}', |
| 37 | + ]; |
| 38 | + yield [ |
| 39 | + [',', '}', '"', '\\', '"\\,}', 'NULL', 't', 'f'], |
| 40 | + '{",","}","\\"","\\\\","\\"\\\\,}","NULL",t,f}', |
| 41 | + ]; |
| 42 | + yield [ |
| 43 | + ['[",","null",true,"false","f"]'], |
| 44 | + '{"[\",\",\"null\",true,\"false\",\"f\"]"}', |
| 45 | + ]; |
| 46 | + // Multibyte strings |
| 47 | + yield [ |
| 48 | + ['我', '👍🏻', 'multibyte строка我👍🏻', 'נטשופ צרכנות'], |
| 49 | + '{我,👍🏻,"multibyte строка我👍🏻","נטשופ צרכנות"}', |
| 50 | + ]; |
33 | 51 | // Similar cases can be in default values |
34 | | - $this->assertSame(null, $arrayParse->parse("'{one,two}'::text[]")); |
| 52 | + yield [null, "'{one,two}'::text[]"]; |
| 53 | + } |
| 54 | + |
| 55 | + #[DataProvider('parserProvider')] |
| 56 | + public function testParser(?array $expected, string $value): void |
| 57 | + { |
| 58 | + $arrayParse = new ArrayParser(); |
| 59 | + $this->assertSame($expected, $arrayParse->parse($value)); |
35 | 60 | } |
36 | 61 | } |
0 commit comments