packages/sql-semantics-mysql/tests/Unit/Rules/Query/From/JoinedInputTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Query\From;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Resolution\VisibleRelation;
11use SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name;
12use SqlSemantics\Platform\MySql\Model\Statement\Reference\Missing\SessionState;
13use SqlSemantics\Platform\MySql\Model\Statement\Shape\OutputSlot;
14use SqlSemantics\Platform\MySql\Model\Statement\Shape\RowShape;
15use SqlSemantics\Platform\MySql\Model\Statement\Type\Known;
16use SqlSemantics\Platform\MySql\Model\Statement\Type\Nullability;
17use SqlSemantics\Platform\MySql\Rules\Query\From\JoinedInput;
18use SqlSemantics\Platform\MySql\Statement\Relation\Dual;
19use SqlSemantics\Platform\MySql\Statement\Type\Integral;
20use SqlSemantics\Platform\MySql\Statement\Type\Kind\IntegralKind;
21
22#[CoversClass(JoinedInput::class)]
23#[Small]
24final class JoinedInputTest extends TestCase
25{
26 public function testOfAnswersTheShapeTheStarSelects(): void
27 {
28 $slot = new OutputSlot(new Name('a'), new Known(new Integral(IntegralKind::Int)), Nullability::NotNull);
29 $input = JoinedInput::of([new VisibleRelation(new Dual(), new RowShape([$slot], [new SessionState('x')]))], [[0, 0]]);
30
31 self::assertSame([$slot], $input->fact->shape->slots);
32 self::assertFalse($input->fact->shape->complete());
33 }
34
35 public function testSlotAnswersTheSlotOfAnEntry(): void
36 {
37 $slot = new OutputSlot(new Name('a'), new Known(new Integral(IntegralKind::Int)), Nullability::NotNull);
38
39 self::assertSame($slot, JoinedInput::of([new VisibleRelation(new Dual(), new RowShape([$slot]))], [[0, 0]])->slot([0, 0]));
40 }
41
42 public function testCompleteTellsWhetherEveryColumnIsKnown(): void
43 {
44 self::assertTrue(JoinedInput::of([new VisibleRelation(new Dual(), new RowShape([]))], [])->complete());
45 self::assertFalse(JoinedInput::of([new VisibleRelation(new Dual(), new RowShape([], [new SessionState('x')]))], [])->complete());
46 }
47
48 public function testCompleteTreatsANameThatDependsOnInputsAsUndecided(): void
49 {
50 $unnamed = new OutputSlot(null, new Known(new Integral(IntegralKind::Int)), Nullability::NotNull, null, null, [new SessionState('character_set_client')]);
51
52 self::assertFalse(JoinedInput::of([new VisibleRelation(new Dual(), new RowShape([$unnamed]))], [[0, 0]])->complete());
53 }
54}
55