packages/sql-semantics-mysql/tests/Unit/Statement/Call/ClockCallTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Call;
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\Model\Statement\Type\Nullability;
16use SqlSemantics\Platform\MySql\Platform;
17use SqlSemantics\Platform\MySql\Statement\Call\Clock;
18use SqlSemantics\Platform\MySql\Statement\Call\ClockCall;
19use SqlSemantics\Platform\MySql\Statement\Literal\Numeral;
20
21#[CoversClass(ClockCall::class)]
22#[Small]
23final class ClockCallTest extends TestCase
24{
25 public function testDeriveScalarAnswersATemporalTypeThatIsNeverNull(): 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 ClockCall(Clock::CurrentTime, new Numeral('2')), $derivation->environment());
31
32 self::assertEquals(new Known(new \SqlSemantics\Platform\MySql\Statement\Type\Temporal(\SqlSemantics\Platform\MySql\Statement\Type\Kind\TemporalKind::Time, '2')), $fact->type);
33 self::assertSame(Nullability::NotNull, $fact->nullability);
34 }
35
36 public function testRenderWritesEmptyParenthesesWithoutAPrecision(): void
37 {
38 $platform = new Platform();
39 $profile = $platform->profile('mysql-8.4.7', null, ParameterStyle::Native);
40 $out = new Output($platform->codec($profile));
41 (new ClockCall(Clock::Now))->render($out);
42
43 self::assertSame('NOW()', (new Lexical())->join($out->pieces()));
44 }
45}
46