packages/sql-semantics-mysql/tests/Unit/Rules/Query/Having/GroupedRowTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Query\Having;
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\GrammarRelease;
12use SqlSemantics\Platform\MySql\Model\Contract\ParameterStyle;
13use SqlSemantics\Platform\MySql\Model\Rendering\Output;
14use SqlSemantics\Platform\MySql\Platform;
15use SqlSemantics\Platform\MySql\Rendering\Codec;
16use SqlSemantics\Platform\MySql\Rules\Query\Having\GroupedRow;
17
18#[CoversClass(GroupedRow::class)]
19#[Small]
20final class GroupedRowTest extends TestCase
21{
22 public function testDeriveRelationAnswersARowWithoutColumns(): void
23 {
24 $platform = new Platform();
25 $derivation = new Derivation($platform->context($platform->profile(null, null, ParameterStyle::Native), null, [], false));
26 $row = new GroupedRow([], [], true);
27 $fact = $row->deriveRelation($derivation, $derivation->environment());
28
29 self::assertSame([], $fact->shape->slots);
30 self::assertTrue($fact->shape->complete());
31 self::assertNull($fact->table);
32 self::assertTrue($row->grouped);
33 self::assertSame([], $row->undecided);
34 }
35
36 public function testRenderWritesNothing(): void
37 {
38 $out = new Output(new Codec(GrammarRelease::MySql847));
39 (new GroupedRow([], [], false))->render($out);
40
41 self::assertSame([], $out->pieces());
42 }
43}
44