Passed
Push — master ( 1849ae...73997f )
by Felipe
01:57
created

AbstractMiddlewareTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 13 1
A testImplementsPsrServerMiddleware() 0 3 1
A testProcessMethodReturnResponse() 0 4 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of coisa/http.
4
 *
5
 * (c) Felipe Sayão Lobato Abreu <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace CoiSA\Http\Test\Handler;
12
13
use PHPUnit\Framework\TestCase;
14
use Prophecy\Argument;
15
use Prophecy\Prophecy\ObjectProphecy;
16
use Psr\Http\Message\ResponseInterface;
17
use Psr\Http\Message\ServerRequestInterface;
18
use Psr\Http\Server\MiddlewareInterface;
19
use Psr\Http\Server\RequestHandlerInterface;
20
21
/**
22
 * Class AbstractMiddlewareTest
23
 *
24
 * @package CoiSA\Http\Test\Handler
25
 */
26
abstract class AbstractMiddlewareTest extends TestCase
27
{
28
    /** @var ObjectProphecy|RequestHandlerInterface */
29
    protected $handler;
30
31
    /** @var ObjectProphecy|RequestHandlerInterface */
32
    protected $nextHandler;
33
34
    /** @var ObjectProphecy|ServerRequestInterface */
35
    protected $serverRequest;
36
37
    /** @var ObjectProphecy|ResponseInterface */
38
    protected $response;
39
40
    /** @var ObjectProphecy|ResponseInterface */
41
    protected $nextResponse;
42
43
    /** @var MiddlewareInterface */
44
    protected $middleware;
45
46
    public function setUp(): void
47
    {
48
        $this->handler       = $this->prophesize(RequestHandlerInterface::class);
49
        $this->nextHandler   = $this->prophesize(RequestHandlerInterface::class);
50
        $this->serverRequest = $this->prophesize(ServerRequestInterface::class);
51
        $this->response      = $this->prophesize(ResponseInterface::class);
52
        $this->nextResponse  = $this->prophesize(ResponseInterface::class);
53
54
        $this->handler->handle($this->serverRequest->reveal())->will([$this->response, 'reveal']);
55
        $this->nextHandler->handle($this->serverRequest->reveal())->will([$this->nextResponse, 'reveal']);
56
57
        $this->response->withStatus(Argument::type('int'))->will([$this->response, 'reveal']);
58
        $this->nextResponse->withStatus(Argument::type('int'))->will([$this->nextResponse, 'reveal']);
59
    }
60
61
    public function testImplementsPsrServerMiddleware(): void
62
    {
63
        $this->assertInstanceOf(MiddlewareInterface::class, $this->middleware);
64
    }
65
66
    public function testProcessMethodReturnResponse(): void
67
    {
68
        $response = $this->middleware->process($this->serverRequest->reveal(), $this->handler->reveal());
69
        $this->assertInstanceOf(ResponseInterface::class, $response);
70
    }
71
}
72