ProblemDetailsTest::testCreatesFromThrowable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gorynych\Tests\Http\Dto;
6
7
use Gorynych\Http\Dto\ProblemDetails;
8
use Gorynych\Http\Exception\BadRequestHttpException;
9
use PHPUnit\Framework\TestCase;
10
use Symfony\Component\HttpFoundation\Response;
11
12
class ProblemDetailsTest extends TestCase
13
{
14
    /**
15
     * @dataProvider provideCases
16
     */
17
    public function testCreatesFromThrowable(\Throwable $throwable, string $expectedDetail, int $expectedStatus): void
18
    {
19
        $dto = ProblemDetails::fromThrowable($throwable);
20
21
        $this->assertSame($expectedDetail, $dto->detail);
22
        $this->assertSame($expectedStatus, $dto->status);
23
    }
24
25
    /**
26
     * @return \Generator<array>
27
     */
28
    public function provideCases(): \Generator
29
    {
30
        yield 'client http exception' => [
31
            new BadRequestHttpException('Bad request.'),
32
            'Bad request.',
33
            Response::HTTP_BAD_REQUEST,
34
        ];
35
36
        yield 'server exception' => [
37
            new \InvalidArgumentException(),
38
            'Internal server error.',
39
            Response::HTTP_INTERNAL_SERVER_ERROR
40
        ];
41
    }
42
}
43