packages/sql-semantics-mysql/tests/Unit/Statement/Table/Key/KeyPartTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Table\Key;
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\Key\ColumnPart;
15use SqlSemantics\Platform\MySql\Statement\Table\Key\ExpressionPart;
16use SqlSemantics\Platform\MySql\Statement\Table\Key\KeyPart;
17
18#[CoversNothing]
19#[Small]
20final class KeyPartTest extends TestCase
21{
22    public function testImplementationsDeclareTheInterface(): void
23    {
24        self::assertContains(KeyPart::class, class_implements(ColumnPart::class));
25    }
26
27    public function testDeriveKeyPartIsDeclaredByTheInterface(): void
28    {
29        $platform = new Platform();
30        $derivation = new Derivation($platform->context($platform->profile('mysql-8.4.7', null, ParameterStyle::Native), null, [], true));
31        $literal = new BooleanLiteral(true);
32        $part = new ExpressionPart($literal);
33        $part->deriveKeyPart($derivation, $derivation->environment());
34
35        self::assertTrue($derivation->facts()->covers($literal));
36    }
37}
38