packages/sql-semantics-mysql/tests/Unit/Lowering/Leaf/AmbiguousKeywordsTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Lowering\Leaf;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Lowering\Leaf\AmbiguousKeywords;
11use SqlSemantics\Platform\MySql\Model\Lowering\Productions;
12
13#[CoversClass(AmbiguousKeywords::class)]
14#[Medium]
15final class AmbiguousKeywordsTest extends TestCase
16{
17    public function testSignaturesListEveryKeywordAsIdentifierProductionOfTheReleases(): void
18    {
19        $directory = dirname(__DIR__, 4) . '/resources/productions/';
20        $paths = glob($directory . 'mysql-*.php');
21        self::assertIsArray($paths);
22        $signatures = array_merge(...array_map(static fn (string $path): array => Productions::load($path)->all(), $paths));
23        $expected = array_values(array_unique(array_filter($signatures, static fn (string $signature): bool => str_starts_with($signature, 'ident_keywords_ambiguous_') || str_starts_with($signature, 'ident_keywords_ambiguous_'))));
24        $oldest = Productions::load($directory . 'mysql-8.0.44.php')->all();
25        $newest = Productions::load($directory . 'mysql-9.1.0.php')->all();
26
27        self::assertContains('ident_keywords_ambiguous_2_labels: BEGIN_SYM', AmbiguousKeywords::SIGNATURES);
28        self::assertSame([], array_values(array_diff($expected, AmbiguousKeywords::SIGNATURES)));
29        self::assertSame([], array_values(array_diff(AmbiguousKeywords::SIGNATURES, $expected)));
30        self::assertSame([], array_values(array_filter(AmbiguousKeywords::SIGNATURES, static fn (string $signature): bool => substr_count($signature, ' ') !== 1)));
31        self::assertContains('ident_keywords_ambiguous_2_labels: BEGIN_SYM', $oldest);
32        self::assertContains('ident_keywords_ambiguous_2_labels: BEGIN_SYM', $newest);
33    }
34}
35