packages/sql-semantics-mysql/tests/Unit/Statement/Replication/Source/SourceOptionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Replication\Source;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Semantics;
11use SqlSemantics\Platform\MySql\Statement\Literal\Numeral;
12use SqlSemantics\Platform\MySql\Statement\Replication\Source\SourceOption;
13use SqlSemantics\Platform\MySql\Statement\Replication\Source\SourceOptionKind;
14use SqlSemantics\Platform\MySql\Statement\Replication\Terminology;
15
16#[CoversClass(SourceOption::class)]
17#[Medium]
18final class SourceOptionTest extends TestCase
19{
20    public function testRenderWritesEveryValueKind(): void
21    {
22        $sql = "change replication source to privilege_checks_user = 'a'@'b', require_table_primary_key_check = generate, assign_gtids_to_anonymous_transactions = local, source_tls_ciphersuites = null, source_heartbeat_period = 1.5";
23
24        self::assertSame(
25            'CHANGE REPLICATION SOURCE TO PRIVILEGE_CHECKS_USER = a@b, REQUIRE_TABLE_PRIMARY_KEY_CHECK = GENERATE, ASSIGN_GTIDS_TO_ANONYMOUS_TRANSACTIONS = LOCAL, SOURCE_TLS_CIPHERSUITES = NULL, SOURCE_HEARTBEAT_PERIOD = 1.5',
26            (new Semantics())->analyze($sql)->toString(),
27        );
28    }
29
30    public function testValueRejectsAValueOutsideTheDomain(): void
31    {
32        $this->expectExceptionMessage('The value of SOURCE_HOST is outside the domain of the option.');
33
34        new SourceOption(Terminology::Current, SourceOptionKind::Host, new Numeral('1'));
35    }
36}
37