packages/sql-semantics-mysql/tests/Unit/Statement/Call/Temporal/GetFormatTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Call\Temporal;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Construction\Derivation;
11use SqlSemantics\Platform\MySql\Model\Contract\ParameterStyle;
12use SqlSemantics\Platform\MySql\Model\Rendering\Lexical;
13use SqlSemantics\Platform\MySql\Model\Rendering\Output;
14use SqlSemantics\Platform\MySql\Model\Statement\Type\Known;
15use SqlSemantics\Platform\MySql\Platform;
16use SqlSemantics\Platform\MySql\Rules\Call\TypeClass;
17use SqlSemantics\Platform\MySql\Statement\Call\Temporal\GetFormat;
18use SqlSemantics\Platform\MySql\Statement\Call\Temporal\TemporalFormat;
19use SqlSemantics\Platform\MySql\Statement\Literal\StringLiteral;
20
21#[CoversClass(GetFormat::class)]
22#[Small]
23final class GetFormatTest extends TestCase
24{
25 public function testDeriveScalarAnswersAString(): void
26 {
27 $platform = new Platform();
28 $profile = $platform->profile('mysql-8.4.7', null, ParameterStyle::Native);
29 $derivation = new Derivation($platform->context($profile, null, [], false));
30 $fact = $derivation->scalar(new GetFormat(TemporalFormat::Time, new StringLiteral(['x'])), $derivation->environment());
31
32 self::assertEquals(new Known(TypeClass::Character->descriptor()), $fact->type);
33 }
34
35 public function testRenderWritesTheKind(): void
36 {
37 $platform = new Platform();
38 $profile = $platform->profile('mysql-8.4.7', null, ParameterStyle::Native);
39 $out = new Output($platform->codec($profile));
40 (new GetFormat(TemporalFormat::Timestamp, new StringLiteral(['x'])))->render($out);
41
42 self::assertSame("GET_FORMAT(TIMESTAMP, 'x')", (new Lexical())->join($out->pieces()));
43 }
44}
45