packages/sql-semantics-sqlite/tests/Unit/Rules/ClosedListTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name;
11use SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\QualifiedName;
12use SqlSemantics\Platform\Sqlite\Rules\ClosedList;
13use SqlSemantics\Platform\Sqlite\Statement\Query\ResultColumn;
14use SqlSemantics\Platform\Sqlite\Statement\Query\Star;
15use SqlSemantics\Platform\Sqlite\Statement\Query\TableStar;
16
17#[CoversClass(ClosedList::class)]
18#[Small]
19final class ClosedListTest extends TestCase
20{
21 public function testOfAnswersTheItemsInOrderWhenEachIsOfAnAdmittedClass(): void
22 {
23 $star = new Star();
24 $table = new TableStar(new Name('t'));
25 $list = (new ClosedList())->of([$star, $table], [Star::class, TableStar::class], 'Result columns.');
26
27 self::assertSame([$star, $table], $list);
28 }
29
30 public function testOfAcceptsAnEmptyListWithoutAMinimum(): void
31 {
32 self::assertSame([], (new ClosedList())->of([], [Star::class], 'Result columns.'));
33 }
34
35 public function testOfAcceptsAListThatReachesTheMinimum(): void
36 {
37 $star = new Star();
38
39 self::assertSame([$star], (new ClosedList())->of([$star], [Star::class, ResultColumn::class], 'Result columns.', 1));
40 }
41
42 public function testOfAdmitsAnItemByAnyOfTheClasses(): void
43 {
44 $name = new Name('a');
45 $qualified = new QualifiedName(new Name('t'));
46
47 self::assertSame([$name, $qualified], (new ClosedList())->of([$name, $qualified], [QualifiedName::class, Name::class], 'Names.'));
48 }
49}
50