packages/sql-semantics-postgres/tests/Unit/Lowering/Catalog/TextSearchRuleTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Lowering\Catalog;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Lowering\Catalog\TextSearchRule::class)]
12#[Medium]
13final class TextSearchRuleTest extends TestCase
14{
15    public function testStatementLowersAConfigurationChange(): void
16    {
17        self::assertSame('ALTER TEXT SEARCH CONFIGURATION c ALTER MAPPING FOR a REPLACE b WITH c', (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('ALTER TEXT SEARCH CONFIGURATION c ALTER MAPPING FOR a REPLACE b WITH c')->toString());
18    }
19
20    public function testWithAcceptsTheMandatoryWith(): void
21    {
22        $lowering = new \SqlSemantics\Platform\PostgreSql\Lowering\Lowering((new \SqlSemantics\Platform\PostgreSql\Platform())->productions(new \SqlSemantics\Platform\PostgreSql\Model\Contract\LanguageProfile(\SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease::PostgreSql172)), new \SqlSemantics\Platform\PostgreSql\Model\Lowering\Leaves(), \SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease::PostgreSql172);
23        $tree = (new \SqlParser\PostgreSql\PostgreSqlParser('pg-17.2'))->parse('ALTER TEXT SEARCH CONFIGURATION c ADD MAPPING FOR a WITH b');
24        $rule = new \SqlSemantics\Platform\PostgreSql\Lowering\Catalog\TextSearchRule($lowering);
25        $rule->with($lowering->productions->form($tree->find('AlterTSConfigurationStmt')[0]));
26        self::assertCount(1, $tree->find('any_with'));
27    }
28}
29