packages/sql-semantics-mysql/tests/Unit/Lowering/Replication/SourceValueRuleTest.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\SourceValueRule;
11use SqlSemantics\Platform\MySql\Semantics;
12
13#[CoversClass(SourceValueRule::class)]
14#[Medium]
15final class SourceValueRuleTest extends TestCase
16{
17 public function testValueLowersStringsAndNumbers(): void
18 {
19 self::assertSame("CHANGE REPLICATION SOURCE TO SOURCE_USER = 'u', SOURCE_PORT = x'10'", (new Semantics())->analyze("change replication source to source_user = 'u', source_port = 0x10")->toString());
20 }
21
22 public function testServerIdsLowersTheIdentifiers(): void
23 {
24 self::assertSame('CHANGE REPLICATION SOURCE TO IGNORE_SERVER_IDS = (1, 2, 3)', (new Semantics())->analyze('change replication source to ignore_server_ids = (1, 2, 3)')->toString());
25 self::assertSame('CHANGE REPLICATION SOURCE TO IGNORE_SERVER_IDS = (2)', (new Semantics())->analyze('change replication source to ignore_server_ids = ( , 2)')->toString());
26 }
27
28 public function testPrivilegeChecksLowersAnAccount(): void
29 {
30 self::assertSame('CHANGE REPLICATION SOURCE TO PRIVILEGE_CHECKS_USER = u', (new Semantics())->analyze("change replication source to privilege_checks_user = 'u'")->toString());
31 }
32
33 public function testPrimaryKeyCheckLowersTheSetting(): void
34 {
35 self::assertSame('CHANGE REPLICATION SOURCE TO REQUIRE_TABLE_PRIMARY_KEY_CHECK = STREAM', (new Semantics())->analyze('change replication source to require_table_primary_key_check = stream')->toString());
36 }
37
38 public function testAnonymousGtidsLowersTheUuid(): void
39 {
40 $change = (new Semantics())->analyze("change replication source to assign_gtids_to_anonymous_transactions = '3E11FA47-71CA-11E1-9E33-C80AA9429562'");
41
42 self::assertSame("CHANGE REPLICATION SOURCE TO ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS = '3E11FA47-71CA-11E1-9E33-C80AA9429562'", $change->toString());
43 self::assertSame([], $change->facts->diagnostics);
44 }
45
46 public function testCipherSuitesLowersAString(): void
47 {
48 self::assertSame("CHANGE REPLICATION SOURCE TO SOURCE_TLS_CIPHERSUITES = 'x'", (new Semantics())->analyze("change replication source to source_tls_ciphersuites = 'x'")->toString());
49 }
50}
51