Passed
Push — master ( b0c833...45ab73 )
by Victor
54s
created

tests/Unit/PipelineTest.php (1 issue)

Labels
Severity
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
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);
0 ignored issues
show
$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

58
        $view = ViewFactory::createWithCallback(/** @scrutinizer ignore-type */ $callback);
Loading history...
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