packages/sql-semantics-postgres/tests/Unit/Statement/Invocation/Xml/XmlProcessingInstructionTest.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\Fact\ScalarFact;
16use SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name;
17use SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Known;
18use SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Nullability;
19use SqlSemantics\Platform\PostgreSql\Platform;
20use SqlSemantics\Platform\PostgreSql\Rendering\Codec;
21use SqlSemantics\Platform\PostgreSql\Statement\Invocation\Xml\XmlProcessingInstruction;
22use SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant;
23use SqlSemantics\Platform\PostgreSql\Statement\Literal\StringConstant;
24use SqlSemantics\Platform\PostgreSql\Statement\Type\Descriptor\Builtin;
25
26#[CoversClass(XmlProcessingInstruction::class)]
27#[Small]
28final class XmlProcessingInstructionTest extends TestCase
29{
30 public function testOutputNameIsXmlpi(): void
31 {
32 self::assertSame('xmlpi', (new XmlProcessingInstruction(new Name('php')))->outputName()->value);
33 }
34
35 public function testDeriveScalarIsNotNullWithoutContent(): void
36 {
37 $derivation = new Derivation((new Platform())->context(new LanguageProfile(GrammarRelease::PostgreSql172), null, [], true));
38 $fact = $derivation->scalar(new XmlProcessingInstruction(new Name('php')), $derivation->environment());
39 self::assertEquals(new ScalarFact(new Known(Builtin::Xml), Nullability::NotNull), $fact);
40 }
41
42 public function testRenderWritesTheContent(): void
43 {
44 $pi = new XmlProcessingInstruction(new Name('php'), new Constant(new StringConstant('echo')));
45 $out = new Output(new Codec(GrammarRelease::PostgreSql172));
46 $pi->render($out);
47 self::assertSame('XMLPI(NAME php, \'echo\')', (new Lexical())->join($out->pieces()));
48 }
49}
50