Completed
Push — master ( f7424d...b53e51 )
by Alejandro
07:43
created

JsonErrorResponseGeneratorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 3
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A noErrorStatusReturnsInternalServerError() 0 6 1
A errorStatusReturnsThatStatus() 0 10 1
1
<?php
2
namespace ShlinkioTest\Shlink\Rest\ErrorHandler;
3
4
use PHPUnit\Framework\TestCase;
5
use Shlinkio\Shlink\Rest\ErrorHandler\JsonErrorResponseGenerator;
6
use Zend\Diactoros\Response;
7
use Zend\Diactoros\ServerRequestFactory;
8
9
class JsonErrorResponseGeneratorTest extends TestCase
10
{
11
    /**
12
     * @var JsonErrorResponseGenerator
13
     */
14
    protected $errorHandler;
15
16
    public function setUp()
17
    {
18
        $this->errorHandler = new JsonErrorResponseGenerator();
19
    }
20
21
    /**
22
     * @test
23
     */
24
    public function noErrorStatusReturnsInternalServerError()
25
    {
26
        $response = $this->errorHandler->__invoke(null, ServerRequestFactory::fromGlobals(), new Response());
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Throwable>|object<Exception>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
        $this->assertInstanceOf(Response\JsonResponse::class, $response);
28
        $this->assertEquals(500, $response->getStatusCode());
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function errorStatusReturnsThatStatus()
35
    {
36
        $response = $this->errorHandler->__invoke(
37
            null,
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Throwable>|object<Exception>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
            ServerRequestFactory::fromGlobals(),
39
            (new Response())->withStatus(405)
40
        );
41
        $this->assertInstanceOf(Response\JsonResponse::class, $response);
42
        $this->assertEquals(405, $response->getStatusCode());
43
    }
44
}
45