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

PipelineTest::testWithContextShouldClearContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests;
5
6
use PHPUnit\Framework\TestCase;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Shoot\Shoot\MiddlewareInterface;
9
use Shoot\Shoot\MissingRequestException;
10
use Shoot\Shoot\Pipeline;
11
use Shoot\Shoot\Tests\Fixtures\ViewFactory;
12
use stdClass;
13
14
final class PipelineTest extends TestCase
15
{
16
    /** @var ServerRequestInterface */
17
    private $request;
18
19
    /**
20
     * @return void
21
     */
22
    protected function setUp()
23
    {
24
        $this->request = $this->createMock(ServerRequestInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Psr\Ht...equestInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Psr\Http\Message\ServerRequestInterface of property $request.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
25
    }
26
27
    /**
28
     * @return void
29
     */
30
    public function testShouldCallMiddleware()
31
    {
32
        $view = ViewFactory::create();
33
34
        $middleware = $this->createMock(MiddlewareInterface::class);
35
        $middleware
36
            ->expects($this->once())
37
            ->method('process')
38
            ->willReturn($view);
39
40
        $pipeline = new Pipeline([$middleware]);
41
42
        $pipeline->withRequest($this->request, function () use ($pipeline, $view) {
43
            $pipeline->process($view);
44
        });
45
    }
46
47
    /**
48
     * @return void
49
     */
50
    public function testShouldRenderView()
51
    {
52
        $pipeline = new Pipeline();
53
54
        $callback = $this
55
            ->getMockBuilder(stdClass::class)
56
            ->setMethods(['__invoke'])
57
            ->getMock();
58
59
        $callback
60
            ->expects($this->once())
61
            ->method('__invoke');
62
63
        $view = ViewFactory::createWithCallback($callback);
0 ignored issues
show
Bug introduced by
$callback of type PHPUnit\Framework\MockObject\MockObject is incompatible with the type callable expected by parameter $callback of Shoot\Shoot\Tests\Fixtur...y::createWithCallback(). ( Ignorable by Annotation )

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

63
        $view = ViewFactory::createWithCallback(/** @scrutinizer ignore-type */ $callback);
Loading history...
64
65
        $pipeline->withRequest($this->request, function () use ($pipeline, $view) {
66
            $pipeline->process($view);
67
        });
68
    }
69
70
    /**
71
     * @return void
72
     */
73
    public function testShouldThrowIfNoRequestWasSet()
74
    {
75
        $pipeline = new Pipeline();
76
        $view = ViewFactory::create();
77
78
        $this->expectException(MissingRequestException::class);
79
80
        $pipeline->process($view);
81
    }
82
}
83