packages/sql-semantics-mysql/tests/Unit/Statement/Table/ColumnSpecificationTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Table;
6
7use PHPUnit\Framework\Attributes\CoversNothing;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Construction\Derivation;
11use SqlSemantics\Platform\MySql\Model\Contract\ParameterStyle;
12use SqlSemantics\Platform\MySql\Platform;
13use SqlSemantics\Platform\MySql\Statement\Literal\BooleanLiteral;
14use SqlSemantics\Platform\MySql\Statement\Table\Column\DefaultLiteral;
15use SqlSemantics\Platform\MySql\Statement\Table\Column\OrdinaryColumn;
16use SqlSemantics\Platform\MySql\Statement\Table\ColumnSpecification;
17use SqlSemantics\Platform\MySql\Statement\Type\Integral;
18use SqlSemantics\Platform\MySql\Statement\Type\Kind\IntegralKind;
19
20#[CoversNothing]
21#[Small]
22final class ColumnSpecificationTest extends TestCase
23{
24 public function testImplementationsDeclareTheInterface(): void
25 {
26 self::assertContains(ColumnSpecification::class, class_implements(OrdinaryColumn::class));
27 }
28
29 public function testDataTypeIsDeclaredByTheInterface(): void
30 {
31 self::assertSame('INT', (new OrdinaryColumn(new Integral(IntegralKind::Int)))->dataType()->name());
32 }
33
34 public function testColumnAttributesIsDeclaredByTheInterface(): void
35 {
36 self::assertSame([], (new OrdinaryColumn(new Integral(IntegralKind::Int)))->columnAttributes());
37 }
38
39 public function testDeriveSpecificationIsDeclaredByTheInterface(): void
40 {
41 $platform = new Platform();
42 $derivation = new Derivation($platform->context($platform->profile('mysql-8.4.7', null, ParameterStyle::Native), null, [], true));
43 $literal = new BooleanLiteral(true);
44 $specification = new OrdinaryColumn(new Integral(IntegralKind::Int), [new DefaultLiteral($literal)]);
45 $specification->deriveSpecification($derivation, $derivation->environment());
46
47 self::assertTrue($derivation->facts()->covers($literal));
48 }
49}
50