Passed
Push — master ( 1ccf8a...1e427b )
by Daniel
02:19
created

ResponseBuilderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 43
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testBuildErrorResponseReturnsData() 0 23 1
A setUp() 0 3 1
A testBuildResponseReturnsResponse() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Usox\JsonSchemaApi\Response;
6
7
use Exception;
8
use Mockery;
9
use Mockery\Adapter\Phpunit\MockeryTestCase;
10
use Ramsey\Uuid\UuidInterface;
11
12
class ResponseBuilderTest extends MockeryTestCase
13
{
14
    /** @var ResponseBuilder|null */
15
    private ResponseBuilder $subject;
16
    
17
    public function setUp(): void
18
    {
19
        $this->subject = new ResponseBuilder();
20
    }
21
    
22
    public function testBuildErrorResponseReturnsData(): void
23
    {
24
        $message = 'some-error';
25
        $code = 666;
26
        $uuidValue = 'some-uuid';
27
        $error = new Exception($message, $code);
28
        
29
        $uuid = Mockery::mock(UuidInterface::class);
30
        
31
        $uuid->shouldReceive('toString')
32
            ->withNoArgs()
33
            ->once()
34
            ->andReturn($uuidValue);
35
        
36
        $this->assertSame(
37
            [
38
                'error' => [
39
                    'message' => $message,
40
                    'code' => $code,
41
                    'id' => $uuidValue
42
                ]
43
            ],
44
            $this->subject->buildErrorResponse($error, $uuid)
0 ignored issues
show
Bug introduced by
$uuid of type Mockery\LegacyMockInterface|Mockery\MockInterface is incompatible with the type Ramsey\Uuid\UuidInterface expected by parameter $uuid of Usox\JsonSchemaApi\Respo...r::buildErrorResponse(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
            $this->subject->buildErrorResponse($error, /** @scrutinizer ignore-type */ $uuid)
Loading history...
45
        );
46
    }
47
    
48
    public function testBuildResponseReturnsResponse(): void
49
    {
50
        $data = ['some-data'];
51
        
52
        $this->assertSame(
53
            ['data' => $data],
54
            $this->subject->buildResponse($data)
55
        );
56
    }
57
}
58