packages/sql-semantics-postgres/tests/Unit/Statement/Manipulation/Cursor/FetchTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Manipulation\Cursor;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10
11#[CoversClass(\SqlSemantics\Platform\PostgreSql\Statement\Manipulation\Cursor\Fetch::class)]
12#[Medium]
13final class FetchTest extends TestCase
14{
15 public function testDeriveStatementRecordsTheRowsOfTheCursor(): void
16 {
17 $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics('pg-17.2');
18 $query = $semantics->analyze('FETCH NEXT c');
19 self::assertSame('the session state: the cursor c', $query->facts->output?->shape->missing[0]->describe());
20 }
21
22 public function testDeriveStatementRecordsNoRowsForMove(): void
23 {
24 $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics('pg-17.2');
25 $query = $semantics->analyze('MOVE LAST IN c');
26 self::assertNull($query->facts->output);
27 }
28
29 public function testRenderWritesTheMovementAndTheCount(): void
30 {
31 $semantics = new \SqlSemantics\Platform\PostgreSql\Semantics('pg-17.2');
32 $query = $semantics->analyze('FETCH RELATIVE 2 FROM c');
33 self::assertSame('FETCH RELATIVE 2 c', $query->toString());
34 }
35}
36