ErrorWithViolationTest::testCreate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Unit\Model;
6
7
use Happyr\JsonApiResponseFactory\Model\ErrorWithViolation;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Component\Validator\ConstraintViolationInterface;
10
11
/**
12
 * @author Radoje Albijanic <[email protected]>
13
 */
14
class ErrorWithViolationTest extends TestCase
15
{
16
    public function testCreate(): void
17
    {
18
        $violation = $this->getMockBuilder(ConstraintViolationInterface::class)
19
            ->getMock();
20
        $violation->method('getPropertyPath')
21
            ->willReturn('someProperty');
22
        $violation->method('getMessage')
23
            ->willReturn('someMessage');
24
25
        $error = ErrorWithViolation::create($violation, 'someTitle');
26
27
        self::assertEquals(
28
            [
29
                'status' => 400,
30
                'title' => 'someTitle',
31
                'source' => [
32
                    'parameter' => 'someProperty',
33
                    'message' => 'someMessage',
34
                ],
35
            ],
36
            $error->getErrorData()
37
        );
38
    }
39
}
40