PipelineTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 28
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testShouldThrowIfNoRequestWasSet() 0 8 1
A setUp() 0 5 1
A testShouldRenderView() 0 18 1
A testShouldCallMiddleware() 0 14 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests\Unit;
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
    protected function setUp(): void
21
    {
22
        $this->request = $this->createMock(ServerRequestInterface::class);
23
24
        parent::setUp();
25
    }
26
27
    public function testShouldCallMiddleware(): void
28
    {
29
        $view = ViewFactory::create();
30
31
        $middleware = $this->createMock(MiddlewareInterface::class);
32
        $middleware
33
            ->expects($this->once())
34
            ->method('process')
35
            ->willReturn($view);
36
37
        $pipeline = new Pipeline([$middleware]);
38
39
        $pipeline->withRequest($this->request, function () use ($pipeline, $view) {
40
            $pipeline->process($view);
41
        });
42
    }
43
44
    public function testShouldRenderView(): void
45
    {
46
        $pipeline = new Pipeline();
47
48
        /** @var callable|MockObject $callback */
49
        $callback = $this
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

49
        $callback = /** @scrutinizer ignore-deprecated */ $this

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
50
            ->getMockBuilder(stdClass::class)
51
            ->setMethods(['__invoke'])
52
            ->getMock();
53
54
        $callback
55
            ->expects($this->once())
56
            ->method('__invoke');
57
58
        $view = ViewFactory::createWithCallback($callback);
59
60
        $pipeline->withRequest($this->request, function () use ($pipeline, $view) {
61
            $pipeline->process($view);
62
        });
63
    }
64
65
    public function testShouldThrowIfNoRequestWasSet(): void
66
    {
67
        $pipeline = new Pipeline();
68
        $view = ViewFactory::create();
69
70
        $this->expectException(MissingRequestException::class);
71
72
        $pipeline->process($view);
73
    }
74
}
75