packages/sql-semantics-mysql/tests/Unit/Statement/Replication/Replica/StartReplicaTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Replication\Replica;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Statement\Operation;
11use SqlSemantics\Platform\MySql\Semantics;
12use SqlSemantics\Platform\MySql\Statement\Replication\Problem\RefusedSetting;
13use SqlSemantics\Platform\MySql\Statement\Replication\Problem\ReplicationError;
14use SqlSemantics\Platform\MySql\Statement\Replication\Replica\StartReplica;
15use SqlSemantics\Platform\MySql\Statement\Replication\Terminology;
16
17#[CoversClass(StartReplica::class)]
18#[Medium]
19final class StartReplicaTest extends TestCase
20{
21 public function testDeriveStatementReportsRefusedConditions(): void
22 {
23 $start = (new Semantics())->inspect("START REPLICA SQL_THREAD UNTIL SOURCE_LOG_FILE = 'f' USER = 'u'");
24
25 self::assertEquals([new RefusedSetting(ReplicationError::UntilCondition), new RefusedSetting(ReplicationError::ApplierWithCredentials)], $start->facts->diagnostics);
26 }
27
28 public function testDeriveStatementRejectsSlaveAfterItsRemoval(): void
29 {
30 $this->expectExceptionMessage('START SLAVE is not a statement of this release.');
31
32 new Operation((new Semantics('mysql-9.1.0'))->context([]), new StartReplica(Terminology::Legacy));
33 }
34
35 public function testRenderKeepsTheSpellingAndWritesEveryOption(): void
36 {
37 self::assertSame(
38 "START SLAVE IO_THREAD, SQL_THREAD UNTIL SOURCE_LOG_FILE = 'f', SOURCE_LOG_POS = 4 USER = 'u' PASSWORD = 'p' DEFAULT_AUTH = 'a' PLUGIN_DIR = 'd' FOR CHANNEL 'c'",
39 (new Semantics('mysql-8.0.44'))->inspect("start slave io_thread, sql_thread until master_log_file = 'f', master_log_pos = 4 user = 'u' password = 'p' default_auth = 'a' plugin_dir = 'd' for channel 'c'")->toString(),
40 );
41 }
42}
43