Passed
Pull Request — master (#11)
by Victor
01:49
created

ShootMiddlewareTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 21
dl 0
loc 38
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testHttpRequestShouldBeSetOnPipeline() 0 33 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests\Unit\Http;
5
6
use PHPUnit\Framework\MockObject\MockObject;
7
use PHPUnit\Framework\TestCase;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use Shoot\Shoot\Http\ShootMiddleware;
12
use Shoot\Shoot\MiddlewareInterface;
13
use Shoot\Shoot\Pipeline;
14
use Shoot\Shoot\Tests\Fixtures\ViewFactory;
15
16
final class ShootMiddlewareTest extends TestCase
17
{
18
    /**
19
     * @return void
20
     */
21
    public function testHttpRequestShouldBeSetOnPipeline()
22
    {
23
        /** @var ServerRequestInterface|MockObject $request */
24
        $request = $this->createMock(ServerRequestInterface::class);
25
26
        /** @var ResponseInterface|MockObject $response */
27
        $response = $this->createMock(ResponseInterface::class);
28
29
        $view = ViewFactory::create();
30
31
        $middleware = $this->createMock(MiddlewareInterface::class);
32
        $middleware
33
            ->expects($this->once())
34
            ->method('process')
35
            ->with($this->equalTo($view), $this->equalTo($request))
36
            ->willReturn($view);
37
38
        $pipeline = new Pipeline([$middleware]);
39
40
        /** @var RequestHandlerInterface|MockObject $handler */
41
        $handler = $this->createMock(RequestHandlerInterface::class);
42
        $handler
43
            ->expects($this->once())
44
            ->method('handle')
45
            ->with($this->equalTo($request))
46
            ->will($this->returnCallback(function () use ($pipeline, $view, $response) {
47
                $pipeline->process($view);
48
49
                return $response;
50
            }));
51
52
        $httpMiddleware = new ShootMiddleware($pipeline);
53
        $httpMiddleware->process($request, $handler);
54
    }
55
}
56