packages/sql-semantics-mysql/tests/Unit/Statement/Alter/Column/DefaultSettingTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Alter\Column;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Model\Statement\Fact\Diagnostic;
11use SqlSemantics\Platform\MySql\Semantics;
12use SqlSemantics\Platform\MySql\Statement\Alter\Column\DefaultSetting;
13
14#[CoversClass(DefaultSetting::class)]
15#[Medium]
16final class DefaultSettingTest extends TestCase
17{
18 public function testDeriveCommandDerivesTheValueInTheChangedTable(): void
19 {
20 $semantics = new Semantics();
21 $table = $semantics->inspect('CREATE TABLE t (a INT, b INT)');
22 $alter = $semantics->inspect('ALTER TABLE t ALTER a SET DEFAULT (b + x)', [$table]);
23
24 self::assertSame(['Column x does not exist.'], array_map(static fn (Diagnostic $diagnostic): string => $diagnostic->message(), $alter->facts->diagnostics));
25 }
26
27 public function testRenderWritesEveryForm(): void
28 {
29 self::assertSame("ALTER TABLE t ALTER COLUMN a SET DEFAULT 'x', ALTER COLUMN b SET DEFAULT (1), ALTER COLUMN c DROP DEFAULT", (new Semantics())->inspect("ALTER TABLE t ALTER a SET DEFAULT 'x', ALTER b SET DEFAULT (1), ALTER c DROP DEFAULT")->toString());
30 }
31}
32