File: GroupKeywordTest.php

package info (click to toggle)
phpmyadmin-sql-parser 5.10.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,244 kB
  • sloc: php: 52,958; makefile: 13; sh: 8
file content (76 lines) | stat: -rw-r--r-- 2,156 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

declare(strict_types=1);

namespace PhpMyAdmin\SqlParser\Tests\Components;

use Generator;
use PhpMyAdmin\SqlParser\Components\Expression;
use PhpMyAdmin\SqlParser\Components\GroupKeyword;
use PhpMyAdmin\SqlParser\Tests\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

use function array_map;

class GroupKeywordTest extends TestCase
{
    /**
     * @return Generator<string, array{GroupKeyword|array<GroupKeyword>, string}>
     */
    public static function provideExpressions(): Generator
    {
        yield 'With no expression at all' => [[], ''];

        yield 'With single simple expression' => [
            self::makeComponentFrom('a'),
            'a',
        ];

        yield 'With multiple simple expressions' => [
            self::makeComponentsFrom('a', 'b', 'c'),
            'a, b, c',
        ];

        yield 'With single untrimmed expression' => [
            self::makeComponentFrom('  o  '),
            'o',
        ];

        yield 'With single untrimmed expression having several kinds of whitespaces' => [
            self::makeComponentFrom(" \n\r foo \t\v\x00  "),
            'foo',
        ];

        yield 'With multiple untrimmed expressions' => [
            self::makeComponentsFrom('  x', ' y ', 'z  '),
            'x, y, z',
        ];

        yield 'With multiple untrimmed expression having several kinds of whitespaces' => [
            self::makeComponentsFrom(" \n\r\t\v\x00foo", " \n\r\tbar\v\x00", "baz \n\r\t\v\x00"),
            'foo, bar, baz',
        ];
    }

    /**
     * @param GroupKeyword|array<GroupKeyword> $component
     */
    #[DataProvider('provideExpressions')]
    public function testBuild($component, string $expected): void
    {
        $this->assertSame($expected, GroupKeyword::build($component));
    }

    private static function makeComponentFrom(string $string): GroupKeyword
    {
        return new GroupKeyword(new Expression($string));
    }

    /**
     * @return array<GroupKeyword>
     */
    private static function makeComponentsFrom(string ...$string): array
    {
        return array_map([self::class, 'makeComponentFrom'], $string);
    }
}