packages/sql-semantics-mysql/tests/Unit/Model/Diagnostic/SemanticExceptionTest.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 SqlSemantics\Platform\MySql\Model\Diagnostic\SemanticException;
11use SqlSemantics\Platform\MySql\Model\Statement\Fact\Diagnostic;
12
13#[CoversClass(SemanticException::class)]
14#[Small]
15final class SemanticExceptionTest extends TestCase
16{
17    public function testKeepsDiagnosticsInTheirReportOrder(): void
18    {
19        $first = self::createStub(Diagnostic::class);
20        $first->method('message')->willReturn('First problem.');
21        $second = self::createStub(Diagnostic::class);
22        $second->method('message')->willReturn('Second problem.');
23        $error = new SemanticException([$first, $second]);
24
25        self::assertSame([$first, $second], $error->diagnostics);
26        self::assertSame("First problem.\nSecond problem.", $error->getMessage());
27    }
28}
29