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

testShouldLogSuppressedExceptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot\Tests\Middleware;
5
6
use PHPUnit\Framework\TestCase;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Log\LoggerInterface;
9
use RuntimeException;
10
use Shoot\Shoot\Middleware\LoggingMiddleware;
11
use Shoot\Shoot\Tests\Fixtures\ViewFactory;
12
use Shoot\Shoot\View;
13
14
final class LoggingMiddlewareTest extends TestCase
15
{
16
    /** @var callable */
17
    private $next;
18
19
    /** @var ServerRequestInterface */
20
    private $request;
21
22
    /**
23
     * @return void
24
     */
25
    protected function setUp()
26
    {
27
        $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...
28
        $this->next = function (View $view): View {
29
            return $view;
30
        };
31
    }
32
33
    /**
34
     * @return void
35
     */
36
    public function testShouldLogBasicDebugInformation()
37
    {
38
        $view = ViewFactory::create();
39
40
        $logger = $this->createMock(LoggerInterface::class);
41
        $logger
42
            ->expects($this->once())
43
            ->method('debug')
44
            ->with(
45
                $this->equalTo('item.twig'),
46
                $this->callback(function (array $context): bool {
47
                    $diff = array_diff(
48
                        array_keys($context),
49
                        ['presentation_model', 'presenter_name', 'time_taken', 'variables']
50
                    );
51
52
                    return count($diff) === 0;
53
                })
54
            );
55
56
        $middleware = new LoggingMiddleware($logger);
57
        $middleware->process($view, $this->request, $this->next);
58
    }
59
60
    /**
61
     * @return void
62
     */
63
    public function testShouldLogSuppressedExceptions()
64
    {
65
        $view = ViewFactory::create()->withSuppressedException(new RuntimeException());
66
67
        $logger = $this->createMock(LoggerInterface::class);
68
        $logger
69
            ->expects($this->once())
70
            ->method('warning')
71
            ->with(
72
                $this->equalTo('item.twig'),
73
                $this->arrayHasKey('exception')
74
            );
75
76
        $middleware = new LoggingMiddleware($logger);
77
        $middleware->process($view, $this->request, $this->next);
78
    }
79
}
80