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

PipelineTest::testShouldRenderView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 18
rs 9.9
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests;
5
6
use PHPUnit\Framework\MockObject\MockObject;
7
use PHPUnit\Framework\TestCase;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Shoot\Shoot\MiddlewareInterface;
10
use Shoot\Shoot\MissingRequestException;
11
use Shoot\Shoot\Pipeline;
12
use Shoot\Shoot\Tests\Fixtures\ViewFactory;
13
use stdClass;
14
15
final class PipelineTest extends TestCase
16
{
17
    /** @var ServerRequestInterface|MockObject */
18
    private $request;
19
20
    /**
21
     * @return void
22
     */
23
    protected function setUp()
24
    {
25
        $this->request = $this->createMock(ServerRequestInterface::class);
26
    }
27
28
    /**
29
     * @return void
30
     */
31
    public function testShouldCallMiddleware()
32
    {
33
        $view = ViewFactory::create();
34
35
        $middleware = $this->createMock(MiddlewareInterface::class);
36
        $middleware
37
            ->expects($this->once())
38
            ->method('process')
39
            ->willReturn($view);
40
41
        $pipeline = new Pipeline([$middleware]);
42
43
        $pipeline->withRequest($this->request, function () use ($pipeline, $view) {
44
            $pipeline->process($view);
45
        });
46
    }
47
48
    /**
49
     * @return void
50
     */
51
    public function testShouldRenderView()
52
    {
53
        $pipeline = new Pipeline();
54
55
        /** @var callable|MockObject $callback */
56
        $callback = $this
57
            ->getMockBuilder(stdClass::class)
58
            ->setMethods(['__invoke'])
59
            ->getMock();
60
61
        $callback
62
            ->expects($this->once())
63
            ->method('__invoke');
64
65
        $view = ViewFactory::createWithCallback($callback);
66
67
        $pipeline->withRequest($this->request, function () use ($pipeline, $view) {
68
            $pipeline->process($view);
69
        });
70
    }
71
72
    /**
73
     * @return void
74
     */
75
    public function testShouldThrowIfNoRequestWasSet()
76
    {
77
        $pipeline = new Pipeline();
78
        $view = ViewFactory::create();
79
80
        $this->expectException(MissingRequestException::class);
81
82
        $pipeline->process($view);
83
    }
84
}
85