Passed
Pull Request — master (#11)
by Victor
01:49
created

SuppressionMiddlewareTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 19
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testShouldCatchSuppressedExceptionAndAssignToView() 0 11 1
A setUp() 0 13 1
A testShouldIgnoreAllOtherExceptions() 0 9 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests\Unit\Middleware;
5
6
use Exception;
7
use PHPUnit\Framework\MockObject\MockObject;
8
use PHPUnit\Framework\TestCase;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Shoot\Shoot\Middleware\SuppressionMiddleware;
11
use Shoot\Shoot\MiddlewareInterface;
12
use Shoot\Shoot\SuppressedException;
13
use Shoot\Shoot\Tests\Fixtures\ViewFactory;
14
use Shoot\Shoot\View;
15
16
final class SuppressionMiddlewareTest extends TestCase
17
{
18
    /** @var MiddlewareInterface */
19
    private $middleware;
20
21
    /** @var callable */
22
    private $next;
23
24
    /** @var ServerRequestInterface|MockObject */
25
    private $request;
26
27
    /**
28
     * @return void
29
     */
30
    protected function setUp()
31
    {
32
        $this->middleware = new SuppressionMiddleware();
33
34
        $this->next = function (View $view): View {
35
            $view->render();
36
37
            return $view;
38
        };
39
40
        $this->request = $this->createMock(ServerRequestInterface::class);
41
42
        parent::setUp();
43
    }
44
45
    /**
46
     * @return void
47
     */
48
    public function testShouldCatchSuppressedExceptionAndAssignToView()
49
    {
50
        $view = ViewFactory::createWithCallback(function () {
51
            throw new SuppressedException(new Exception());
52
        });
53
54
        $this->assertFalse($view->hasSuppressedException());
55
56
        $view = $this->middleware->process($view, $this->request, $this->next);
57
58
        $this->assertTrue($view->hasSuppressedException());
59
    }
60
61
    /**
62
     * @return void
63
     */
64
    public function testShouldIgnoreAllOtherExceptions()
65
    {
66
        $view = ViewFactory::createWithCallback(function () {
67
            throw new Exception();
68
        });
69
70
        $this->expectException(Exception::class);
71
72
        $this->middleware->process($view, $this->request, $this->next);
73
    }
74
}
75