packages/sql-semantics-postgres/tests/Unit/Statement/Invocation/Xml/XmlPassingTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Invocation\Xml;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\PostgreSql\Model\Construction\Derivation;
11use SqlSemantics\Platform\PostgreSql\Model\Contract\GrammarRelease;
12use SqlSemantics\Platform\PostgreSql\Model\Contract\LanguageProfile;
13use SqlSemantics\Platform\PostgreSql\Model\Rendering\Lexical;
14use SqlSemantics\Platform\PostgreSql\Model\Rendering\Output;
15use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
16use SqlSemantics\Platform\PostgreSql\Platform;
17use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
18use SqlSemantics\Platform\PostgreSql\Statement\Expression\BinaryOperation;
19use SqlSemantics\Platform\PostgreSql\Statement\Invocation\Xml\XmlPassing;
20use SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant;
21use SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant;
22use SqlSemantics\Platform\PostgreSql\Statement\Literal\StringConstant;
23use SqlSemantics\Platform\PostgreSql\Statement\Name\OperatorName;
24
25#[CoversClass(XmlPassing::class)]
26#[Small]
27final class XmlPassingTest extends TestCase
28{
29 public function testRejectsADocumentThatIsNotPrimary(): void
30 {
31 $this->expectExceptionMessage('The document passed is a primary expression; group it.');
32 new XmlPassing(new BinaryOperation(new OperatorName(new Name('=')), new Constant(new IntegerConstant('1')), new Constant(new IntegerConstant('1'))));
33 }
34
35 public function testDeriveClauseDerivesTheDocument(): void
36 {
37 $document = new Constant(new StringConstant('<a/>'));
38 $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
39 (new XmlPassing($document))->deriveClause($derivation, $derivation->environment());
40 self::assertTrue($derivation->facts()->covers($document));
41 }
42
43 public function testRenderWritesPassing(): void
44 {
45 $passing = new XmlPassing(new Constant(new StringConstant('<a/>')));
46 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
47 $passing->render($out);
48 self::assertSame('PASSING \'<a/>\'', (new Lexical())->join($out->pieces()));
49 }
50}
51