Completed
Push — master ( b9a9e3...539ccc )
by Gabriel
02:51
created

RouteResolverMiddlewareTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 6
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testProcess() 0 19 1
1
<?php
2
3
namespace Nip\Router\Tests\Middleware;
4
5
use Nip\Router\Middleware\RouteResolverMiddleware;
6
use Nip\Router\Router;
7
use Nip\Router\Tests\AbstractTest;
8
use Nip\Http\Response\Response;
9
use Nip\Http\ServerMiddleware\Dispatcher;
10
use Nip\Request;
11
12
/**
13
 * Class DebugbarMiddlewareTest
14
 * @package Nip\Router\Tests\Middleware
15
 */
16
class RouteResolverMiddlewareTest extends AbstractTest
17
{
18
19
    public function testProcess()
20
    {
21
        $router = new Router();
22
23
        $dispatcher = new Dispatcher(
24
            [
0 ignored issues
show
Documentation introduced by
array(new \Nip\Router\Mi...>setContent('test'); }) is of type array<integer,object<Nip..."1":"object<Closure>"}>, but the function expects a array<integer,object<Psr...r\MiddlewareInterface>>.

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...
25
                new RouteResolverMiddleware($router),
26
                function () {
27
                    return (new Response())->setContent('test');
28
                },
29
            ]
30
        );
31
32
        /** @var Response $response */
33
        $response = $dispatcher->dispatch(new Request());
34
35
        self::assertInstanceOf(Response::class, $response);
36
        self::assertSame('test', $response->getContent());
37
    }
38
}
39