packages/sql-semantics-mysql/tests/Unit/Lowering/Replication/ReplicationRulesTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Lowering\Replication;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlParser\Parser\Node;
11use SqlSemantics\Platform\MySql\Lowering\Lowering;
12use SqlSemantics\Platform\MySql\Lowering\Replication\ReplicationRules;
13use SqlSemantics\Platform\MySql\Model\Contract\ParameterStyle;
14use SqlSemantics\Platform\MySql\Model\Lowering\Leaves;
15use SqlSemantics\Platform\MySql\Platform;
16use SqlSemantics\Platform\MySql\Semantics;
17
18#[CoversClass(ReplicationRules::class)]
19#[Medium]
20final class ReplicationRulesTest extends TestCase
21{
22    public function testStatementHandsEveryStatementToItsRule(): void
23    {
24        self::assertSame('BINLOG \'x\'', (new Semantics())->analyze("binlog 'x'")->toString());
25        self::assertSame('STOP GROUP_REPLICATION', (new Semantics())->analyze('stop group_replication')->toString());
26    }
27
28    public function testStatementReportsANodeOfAnotherRule(): void
29    {
30        $platform = new Platform();
31        $profile = $platform->profile(null, null, ParameterStyle::Native);
32        $rules = new ReplicationRules(new Lowering($platform->productions($profile), new Leaves(), $profile));
33
34        $this->expectExceptionMessage('The grammar release has no production rule#0.');
35
36        $rules->statement(new Node('rule', 0, []));
37    }
38
39    public function testChannelLowersTheName(): void
40    {
41        self::assertSame("STOP REPLICA FOR CHANNEL 'c'", (new Semantics())->analyze("stop replica for channel 'c'")->toString());
42    }
43
44    public function testTerminologyAnswersTheWrittenSpelling(): void
45    {
46        self::assertSame('STOP SLAVE', (new Semantics('mysql-8.3.0'))->analyze('stop slave')->toString());
47        self::assertSame('STOP REPLICA', (new Semantics('mysql-8.3.0'))->analyze('stop replica')->toString());
48    }
49}
50