Passed
Pull Request — master (#2)
by Victor
02:04
created

testHttpRequestShouldBeSetOnPipeline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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