packages/sql-semantics-mysql/tests/Unit/Statement/Server/Transaction/Xa/XaEndTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Server\Transaction\Xa;
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\Literal\Numeral;
13use SqlSemantics\Platform\MySql\Statement\Literal\Text;
14use SqlSemantics\Platform\MySql\Statement\Server\Transaction\Xa\XaEnd;
15use SqlSemantics\Platform\MySql\Statement\Server\Transaction\Xa\Xid;
16
17#[CoversClass(XaEnd::class)]
18#[Medium]
19final class XaEndTest extends TestCase
20{
21    public function testRenderWritesTheOption(): void
22    {
23        self::assertSame("XA END 'g' SUSPEND", (new Semantics())->analyze("xa end 'g' suspend")->toString());
24    }
25
26    public function testRenderWritesForMigrateOf56(): void
27    {
28        self::assertSame("XA END 'g' SUSPEND FOR MIGRATE", (new Semantics('mysql-5.6.51'))->analyze("xa end 'g' suspend for migrate")->toString());
29    }
30
31    public function testDeriveStatementHasNoFacts(): void
32    {
33        $operation = (new Semantics())->analyze("XA END 'g'");
34
35        self::assertSame([], $operation->facts->diagnostics);
36        self::assertNull($operation->facts->output);
37    }
38
39    public function testDeriveStatementRefusesAFormatAboveTheSignedRangeAfterMySql56(): void
40    {
41        $statement = new XaEnd(new Xid(new Text('a'), new Text('b'), new Numeral('9223372036854775808')));
42        $accepted = new Operation((new Semantics('mysql-5.6.51'))->context([]), $statement);
43
44        self::assertSame($statement, $accepted->statement);
45        $this->expectExceptionMessage('A format identifier is at most 9223372036854775807 from MySQL 5.7 on.');
46
47        new Operation((new Semantics())->context([]), new XaEnd(new Xid(new Text('a'), new Text('b'), new Numeral('9223372036854775808'))));
48    }
49}
50