Test Failed
Push — master ( d8d5ef...b9f7fc )
by mcfog
01:56
created

ConditionMiddlewareTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 72
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ __construct() 0 5 1
A hp$0 ➔ shouldRun() 0 7 1
A hp$1 ➔ __construct() 0 5 1
A hp$1 ➔ shouldRun() 0 7 1
B testFalsyCondition() 0 35 1
B testTruthyCondition() 0 33 1
1
<?php namespace Nimo\Tests;
2
3
/**
4
 * User: mcfog
5
 * Date: 15/9/13
6
 */
7
8
use Interop\Http\Server\MiddlewareInterface;
9
use Interop\Http\Server\RequestHandlerInterface;
10
use Nimo\AbstractMiddleware;
11
use Nimo\Middlewares\AbstractConditionMiddleware;
12
use PHPUnit\Framework\Assert;
13
use Psr\Http\Message\ResponseInterface;
14
use Psr\Http\Message\ServerRequestInterface;
15
16
class ConditionMiddlewareTest extends NimoTestCase
17
{
18
    public function testFalsyCondition()
19
    {
20
        $inner = $this->prophesize(AbstractMiddleware::class);
21
        $inner->__call('main', [])->shouldNotBeCalled();
22
        $request = $this->getRequestMock();
23
        $response = $this->getResponseMock();
24
        $handler = $this->assertedHandler($request, $response);
0 ignored issues
show
Documentation introduced by
$request is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

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...
Documentation introduced by
$response is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

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
26
        $middleware = new class($inner->reveal(), $request, $handler) extends AbstractConditionMiddleware
27
        {
28
            protected $params;
29
30
            public function __construct(MiddlewareInterface $innerMiddleware, $request, $handler)
31
            {
32
                parent::__construct($innerMiddleware);
33
                $this->params = [$request, $handler];
34
            }
35
36
            public function shouldRun(ServerRequestInterface $request, RequestHandlerInterface $handler): bool
37
            {
38
                [$request, $handler] = $this->params;
39
                Assert::assertSame($request, $this->request);
40
                Assert::assertSame($handler, $this->handler);
41
                return false;
42
            }
43
        };
44
45
46
        $returnValue = $middleware->process(
47
            $request,
0 ignored issues
show
Documentation introduced by
$request is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

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...
48
            $handler
49
        );
50
51
        $this->assertSame($response, $returnValue);
52
    }
53
54
    public function testTruthyCondition()
55
    {
56
        $answerRes = $this->getMockForAbstractClass(ResponseInterface::class);
57
        $request = $this->getRequestMock();
58
        $expectedHandler = $this->throwHandler();
59
        $inner = $this->assertedMiddleware($request, $expectedHandler, $answerRes);
0 ignored issues
show
Documentation introduced by
$request is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

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...
Documentation introduced by
$answerRes is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

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...
60
61
        $middleware = new class($inner, $request, $expectedHandler) extends AbstractConditionMiddleware
62
        {
63
            protected $params;
64
65
            public function __construct(MiddlewareInterface $innerMiddleware, $request, $handler)
66
            {
67
                parent::__construct($innerMiddleware);
68
                $this->params = [$request, $handler];
69
            }
70
71
            public function shouldRun(ServerRequestInterface $request, RequestHandlerInterface $handler): bool
72
            {
73
                [$request, $handler] = $this->params;
74
                Assert::assertSame($request, $this->request);
75
                Assert::assertSame($handler, $this->handler);
76
                return true;
77
            }
78
        };
79
80
        $returnValue = $middleware->process(
81
            $request,
0 ignored issues
show
Documentation introduced by
$request is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

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...
82
            $expectedHandler
83
        );
84
85
        $this->assertSame($answerRes, $returnValue);
86
    }
87
}
88