packages/deriver/tests/Unit/Exception/ParserExceptionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Exception;
6
7use Deriver\Exception\ParserException;
8use PhpParser\Error;
9use PHPUnit\Framework\Attributes\CoversClass;
10use PHPUnit\Framework\Attributes\Small;
11use PHPUnit\Framework\TestCase;
12
13#[CoversClass(ParserException::class)]
14#[Small]
15final class ParserExceptionTest extends TestCase
16{
17    public function testRetainsTheOriginalErrorAndSourceLocation(): void
18    {
19        $previous = new Error('Unexpected token');
20        $error = new ParserException('Unexpected token', 'app.php', 3, $previous);
21        self::assertSame('app.php', $error->path);
22        self::assertSame(3, $error->sourceLine);
23        self::assertSame('app.php:3: Unexpected token', $error->getMessage());
24        self::assertSame($previous, $error->getPrevious());
25    }
26}
27