packages/requirements/tests/Unit/Input/InvalidInputExceptionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Input;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use Requirements\Input\InvalidInputException;
11use RuntimeException;
12
13#[CoversClass(InvalidInputException::class)]
14#[Small]
15final class InvalidInputExceptionTest extends TestCase
16{
17    /**
18     * @throws InvalidInputException
19     */
20    public function testIsCaughtAsRuntimeExceptionWithItsMessage(): void
21    {
22        $this->expectException(RuntimeException::class);
23        $this->expectExceptionMessage('definition.yaml: unknown field.');
24        throw new InvalidInputException('definition.yaml: unknown field.');
25    }
26
27    public function testKeepsThePreviousException(): void
28    {
29        $previous = new RuntimeException('cause');
30        $error = new InvalidInputException('wrapped', 0, $previous);
31        self::assertSame($previous, $error->getPrevious());
32        self::assertSame('wrapped', $error->getMessage());
33    }
34}
35