packages/sql-semantics-sqlite/tests/Unit/Model/Diagnostic/InvariantViolationTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Model\Diagnostic;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlParser\Parser\Node;
11use SqlSemantics\Platform\Sqlite\Model\Diagnostic\InvariantViolation;
12use SqlSemantics\Platform\Sqlite\Model\Lowering\Form;
13
14#[CoversClass(InvariantViolation::class)]
15#[Small]
16final class InvariantViolationTest extends TestCase
17{
18    public function testAFailedInternalCheckIsReported(): void
19    {
20        $this->expectExceptionMessage('The production has no terminal at position 0: expr: term');
21
22        (new Form(new Node('expr', 0, [new Node('term', 2, [])]), 'expr: term'))->token(0);
23    }
24
25    public function testTheMessageIsKept(): void
26    {
27        self::assertSame('Derivation left a node without facts.', (new InvariantViolation('Derivation left a node without facts.'))->getMessage());
28    }
29}
30