|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\SqlParser\Tests\Components; |
|
6
|
|
|
|
|
7
|
|
|
use Generator; |
|
8
|
|
|
use PhpMyAdmin\SqlParser\Components\Expression; |
|
9
|
|
|
use PhpMyAdmin\SqlParser\Components\GroupKeyword; |
|
10
|
|
|
use PhpMyAdmin\SqlParser\Tests\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
use function array_map; |
|
13
|
|
|
|
|
14
|
|
|
class GroupKeywordTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @return Generator<string, array{GroupKeyword|array<GroupKeyword>, string}> |
|
18
|
|
|
*/ |
|
19
|
|
|
public function provideExpressions(): Generator |
|
20
|
|
|
{ |
|
21
|
|
|
yield 'With no expression at all' => [[], '']; |
|
22
|
|
|
|
|
23
|
|
|
yield 'With single simple expression' => [ |
|
24
|
|
|
self::makeComponentFrom('a'), |
|
25
|
|
|
'a', |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
yield 'With multiple simple expressions' => [ |
|
29
|
|
|
self::makeComponentsFrom('a', 'b', 'c'), |
|
30
|
|
|
'a, b, c', |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
yield 'With single untrimmed expression' => [ |
|
34
|
|
|
self::makeComponentFrom(' o '), |
|
35
|
|
|
'o', |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
yield 'With single untrimmed expression having several kinds of whitespaces' => [ |
|
39
|
|
|
self::makeComponentFrom(" \n\r foo \t\v\x00 "), |
|
40
|
|
|
'foo', |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
yield 'With multiple untrimmed expressions' => [ |
|
44
|
|
|
self::makeComponentsFrom(' x', ' y ', 'z '), |
|
45
|
|
|
'x, y, z', |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
yield 'With multiple untrimmed expression having several kinds of whitespaces' => [ |
|
49
|
|
|
self::makeComponentsFrom(" \n\r\t\v\x00foo", " \n\r\tbar\v\x00", "baz \n\r\t\v\x00"), |
|
50
|
|
|
'foo, bar, baz', |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param GroupKeyword|array<GroupKeyword> $component |
|
56
|
|
|
* |
|
57
|
|
|
* @dataProvider provideExpressions |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testBuild($component, string $expected): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->assertSame($expected, GroupKeyword::build($component)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
private static function makeComponentFrom(string $string): GroupKeyword |
|
65
|
|
|
{ |
|
66
|
|
|
return new GroupKeyword(new Expression($string)); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return array<GroupKeyword> |
|
71
|
|
|
*/ |
|
72
|
|
|
private static function makeComponentsFrom(string ...$string): array |
|
73
|
|
|
{ |
|
74
|
|
|
return array_map([self::class, 'makeComponentFrom'], $string); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|