ProblemDetailsTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A provideCases() 0 12 1
A testCreatesFromThrowable() 0 6 1
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