packages/sql-semantics-mysql/tests/Unit/Statement/Call/Window/FrameTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Call\Window;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Contract\ParameterStyle;
11use SqlSemantics\Platform\MySql\Model\Rendering\Lexical;
12use SqlSemantics\Platform\MySql\Model\Rendering\Output;
13use SqlSemantics\Platform\MySql\Platform;
14use SqlSemantics\Platform\MySql\Statement\Call\Window\Frame;
15use SqlSemantics\Platform\MySql\Statement\Call\Window\FrameBound;
16use SqlSemantics\Platform\MySql\Statement\Call\Window\FrameBoundKind;
17use SqlSemantics\Platform\MySql\Statement\Call\Window\FrameExclusion;
18use SqlSemantics\Platform\MySql\Statement\Call\Window\FrameUnit;
19use SqlSemantics\Platform\MySql\Statement\Literal\NumberLiteral;
20
21#[CoversClass(Frame::class)]
22#[Small]
23final class FrameTest extends TestCase
24{
25 public function testOffsetsAnswersTheOffsetsInOrder(): void
26 {
27 $start = new NumberLiteral('1');
28 $end = new NumberLiteral('2');
29 $frame = new Frame(FrameUnit::Rows, new FrameBound(FrameBoundKind::Preceding, $start), new FrameBound(FrameBoundKind::Following, $end));
30
31 self::assertSame([$start, $end], $frame->offsets());
32 }
33
34 public function testRenderWritesTheBetweenFormAndTheExclusion(): void
35 {
36 $platform = new Platform();
37 $profile = $platform->profile('mysql-8.4.7', null, ParameterStyle::Native);
38 $out = new Output($platform->codec($profile));
39 (new Frame(FrameUnit::Range, new FrameBound(FrameBoundKind::CurrentRow), new FrameBound(FrameBoundKind::UnboundedFollowing), FrameExclusion::NoOthers))->render($out);
40
41 self::assertSame('RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS', (new Lexical())->join($out->pieces()));
42 }
43
44}
45