DummyError::getErrorData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
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\AbstractError;
8
use Happyr\JsonApiResponseFactory\Model\MultipleError;
9
use Nyholm\NSA;
10
use PHPUnit\Framework\TestCase;
11
12
/**
13
 * @author Radoje Albijanic <[email protected]>
14
 */
15
class MultipleErrorTest extends TestCase
16
{
17
    public function testAddError(): void
18
    {
19
        $error = new DummyError();
20
        $multipleError = new MultipleError(400, []);
21
        $multipleError->addError($error);
22
23
        self::assertEquals([$error], NSA::getProperty($multipleError, 'errors'));
24
    }
25
26
    public function testGetPayload(): void
27
    {
28
        $error = new MultipleError(400, [new DummyError()]);
29
        self::assertEquals(
30
            [
31
                'errors' => [
32
                    ['someKey' => 'someValue'],
33
                ],
34
            ],
35
            $error->getPayload()
36
        );
37
    }
38
39
    public function testGetHttpStatusCode(): void
40
    {
41
        $error = new MultipleError(400, []);
42
        self::assertEquals(400, $error->getHttpStatusCode());
43
    }
44
}
45
46
class DummyError extends AbstractError
47
{
48
    public function __construct()
49
    {
50
        parent::__construct('someTitle', 400);
51
    }
52
53
    public function getErrorData(): array
54
    {
55
        return ['someKey' => 'someValue'];
56
    }
57
}
58