ShootMiddlewareTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 21
dl 0
loc 35
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
    public function testHttpRequestShouldBeSetOnPipeline(): void
19
    {
20
        /** @var ServerRequestInterface|MockObject $request */
21
        $request = $this->createMock(ServerRequestInterface::class);
22
23
        /** @var ResponseInterface|MockObject $response */
24
        $response = $this->createMock(ResponseInterface::class);
25
26
        $view = ViewFactory::create();
27
28
        $middleware = $this->createMock(MiddlewareInterface::class);
29
        $middleware
30
            ->expects($this->once())
31
            ->method('process')
32
            ->with($this->equalTo($view), $this->equalTo($request))
33
            ->willReturn($view);
34
35
        $pipeline = new Pipeline([$middleware]);
36
37
        /** @var RequestHandlerInterface|MockObject $handler */
38
        $handler = $this->createMock(RequestHandlerInterface::class);
39
        $handler
40
            ->expects($this->once())
41
            ->method('handle')
42
            ->with($this->equalTo($request))
43
            ->will($this->returnCallback(function () use ($pipeline, $view, $response) {
44
                $pipeline->process($view);
45
46
                return $response;
47
            }));
48
49
        $httpMiddleware = new ShootMiddleware($pipeline);
50
        $httpMiddleware->process($request, $handler);
51
    }
52
}
53