packages/sql-semantics-sqlite/tests/Unit/Statement/Schema/Reference/ReferenceActionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Schema\Reference;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\Sqlite\Model\Rendering\Lexical;
11use SqlSemantics\Platform\Sqlite\Model\Rendering\Output;
12use SqlSemantics\Platform\Sqlite\Rendering\Codec;
13use SqlSemantics\Platform\Sqlite\Statement\Schema\Reference\ReferenceAction;
14use SqlSemantics\Platform\Sqlite\Statement\Schema\Reference\ReferenceEvent;
15use SqlSemantics\Platform\Sqlite\Statement\Schema\Reference\ReferenceReaction;
16
17#[CoversClass(ReferenceAction::class)]
18#[Small]
19final class ReferenceActionTest extends TestCase
20{
21    public function testRenderWritesTheEventAndTheReaction(): void
22    {
23        $out = new Output(new Codec());
24        (new ReferenceAction(ReferenceEvent::Delete, ReferenceReaction::SetNull))->render($out);
25
26        self::assertSame('ON DELETE SET NULL', (new Lexical())->join($out->pieces()));
27    }
28
29    public function testRenderWritesAnInsertEventTheGrammarAccepts(): void
30    {
31        $out = new Output(new Codec());
32        (new ReferenceAction(ReferenceEvent::Insert, ReferenceReaction::NoAction))->render($out);
33
34        self::assertSame('ON INSERT NO ACTION', (new Lexical())->join($out->pieces()));
35    }
36}
37