packages/sql-semantics-sqlite/tests/Unit/Model/Validation/LeafEmbeddingTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Model\Validation;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\Sqlite\Model\Lowering\Leaves;
11use SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name;
12use SqlSemantics\Platform\Sqlite\Model\Validation\LeafEmbedding;
13use SqlSemantics\Platform\Sqlite\Model\Validation\ValueGraph;
14use SqlSemantics\Platform\Sqlite\Statement\Expression\ColumnUse;
15use SqlSemantics\Platform\Sqlite\Statement\Query\ResultColumn;
16use SqlSemantics\Platform\Sqlite\Statement\Query\Select;
17
18#[CoversClass(LeafEmbedding::class)]
19#[Small]
20final class LeafEmbeddingTest extends TestCase
21{
22 public function testDroppedIsNullWhenEveryLeafIsReachable(): void
23 {
24 $leaves = new Leaves();
25 $name = $leaves->record(new Name('a'));
26 $statement = new Select([new ResultColumn(new ColumnUse($name))]);
27
28 self::assertNull((new LeafEmbedding())->dropped($leaves, (new ValueGraph(['SqlSemantics\\']))->objects($statement)));
29 }
30
31 public function testDroppedAnswersTheFirstLeafTheStructureLost(): void
32 {
33 $leaves = new Leaves();
34 $kept = $leaves->record(new Name('a'));
35 $lost = $leaves->record(new Name('b'));
36 $statement = new Select([new ResultColumn(new ColumnUse($kept))]);
37
38 self::assertSame($lost, (new LeafEmbedding())->dropped($leaves, (new ValueGraph(['SqlSemantics\\']))->objects($statement)));
39 }
40
41 public function testDroppedComparesByIdentityAndNotByValue(): void
42 {
43 $leaves = new Leaves();
44 $recorded = $leaves->record(new Name('a'));
45 $statement = new Select([new ResultColumn(new ColumnUse(new Name('a')))]);
46
47 self::assertSame($recorded, (new LeafEmbedding())->dropped($leaves, (new ValueGraph(['SqlSemantics\\']))->objects($statement)));
48 }
49}
50