packages/sql-semantics-mysql/tests/Unit/Statement/Call/Window/FrameBoundTest.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\Model\Statement\Identifier\Name;
14use SqlSemantics\Platform\MySql\Platform;
15use SqlSemantics\Platform\MySql\Statement\Call\Window\FrameBound;
16use SqlSemantics\Platform\MySql\Statement\Call\Window\FrameBoundKind;
17use SqlSemantics\Platform\MySql\Statement\Expression\IntervalUnit;
18use SqlSemantics\Platform\MySql\Statement\Literal\Parameter;
19use SqlSemantics\Platform\MySql\Statement\Name\ColumnUse;
20
21#[CoversClass(FrameBound::class)]
22#[Small]
23final class FrameBoundTest extends TestCase
24{
25 public function testRenderWritesTheOffsetAndTheKind(): void
26 {
27 $platform = new Platform();
28 $profile = $platform->profile('mysql-8.4.7', null, ParameterStyle::Native);
29 $interval = new Output($platform->codec($profile));
30 (new FrameBound(FrameBoundKind::Following, new ColumnUse(new Name('a')), IntervalUnit::Day))->render($interval);
31 $parameter = new Output($platform->codec($profile));
32 (new FrameBound(FrameBoundKind::Preceding, new Parameter('?')))->render($parameter);
33
34 self::assertSame('INTERVAL a DAY FOLLOWING', (new Lexical())->join($interval->pieces()));
35 self::assertSame('? PRECEDING', (new Lexical())->join($parameter->pieces()));
36 }
37
38}
39