packages/sql-semantics-sqlite/tests/Unit/Statement/Schema/Limit/DefaultNotConstantTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Schema\Limit;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name;
11use SqlSemantics\Platform\Sqlite\Semantics;
12use SqlSemantics\Platform\Sqlite\Statement\Schema\Limit\DefaultNotConstant;
13
14#[CoversClass(DefaultNotConstant::class)]
15#[Medium]
16final class DefaultNotConstantTest extends TestCase
17{
18 public function testMessageNamesTheColumn(): void
19 {
20 self::assertSame('The default value of column price is not constant.', (new DefaultNotConstant(new Name('price')))->message());
21 }
22
23 public function testMessageIsReportedForEachDefaultNotConstantOfADefinition(): void
24 {
25 $semantics = new Semantics();
26 $operation = $semantics->inspect('CREATE TABLE t (a DEFAULT ((SELECT 1)), b DEFAULT ("word"), c DEFAULT (random() + 1), d DEFAULT (CASE WHEN 1 THEN 2 END))', []);
27 $columns = array_map(static fn (object $diagnostic): ?string => $diagnostic instanceof DefaultNotConstant ? $diagnostic->column->value : null, $operation->facts->diagnostics);
28
29 self::assertSame(['a', 'b'], $columns);
30 }
31}
32