packages/sql-semantics-mysql/tests/Unit/Lowering/Replication/LogRuleTest.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 SqlSemantics\Platform\MySql\Lowering\Replication\LogRule;
11use SqlSemantics\Platform\MySql\Semantics;
12
13#[CoversClass(LogRule::class)]
14#[Medium]
15final class LogRuleTest extends TestCase
16{
17    public function testPurgeLowersBothForms(): void
18    {
19        self::assertSame("PURGE BINARY LOGS TO 'f'", (new Semantics())->analyze("purge binary logs to 'f'")->toString());
20        self::assertSame('PURGE BINARY LOGS BEFORE NOW()', (new Semantics('mysql-8.0.44'))->analyze('purge master logs before now()')->toString());
21    }
22
23    public function testBinlogLowersTheEvents(): void
24    {
25        self::assertSame("BINLOG 'e'", (new Semantics())->analyze("binlog 'e'")->toString());
26    }
27
28    public function testGroupLowersStartAndStop(): void
29    {
30        self::assertSame('STOP GROUP_REPLICATION', (new Semantics())->analyze('stop group_replication')->toString());
31        self::assertSame('START GROUP_REPLICATION', (new Semantics())->analyze('start group_replication')->toString());
32    }
33
34    public function testStartLowersTheOptionsInOrder(): void
35    {
36        self::assertSame("START GROUP_REPLICATION PASSWORD = 'p', USER = 'u', USER = 'v'", (new Semantics())->analyze("start group_replication password = 'p', user = 'u', user = 'v'")->toString());
37    }
38
39    public function testOptionLowersEachCredential(): void
40    {
41        self::assertSame("START GROUP_REPLICATION DEFAULT_AUTH = 'a'", (new Semantics('mysql-8.0.44'))->analyze("start group_replication default_auth = 'a'")->toString());
42    }
43}
44