Passed
Push — master ( 4b20bd...439edc )
by Alexander
06:09
created

ErrorHandlerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
4
namespace Yiisoft\Yii\Web\Tests\ErrorHandler;
5
6
use PHPUnit\Framework\TestCase;
7
use Psr\Log\LoggerInterface;
8
use Yiisoft\Yii\Web\ErrorHandler\ErrorHandler;
9
use Yiisoft\Yii\Web\ErrorHandler\ThrowableRendererInterface;
10
11
class ErrorHandlerTest extends TestCase
12
{
13
    private ErrorHandler $errorHandler;
14
    private LoggerInterface $loggerMock;
15
    private ThrowableRendererInterface $throwableRendererMock;
16
17
    public function setUp(): void
18
    {
19
        parent::setUp();
20
        $this->loggerMock = $this->createMock(LoggerInterface::class);
21
        $this->throwableRendererMock = $this->createMock(ThrowableRendererInterface::class);
22
        $this->errorHandler = new ErrorHandler($this->loggerMock, $this->throwableRendererMock);
23
    }
24
25
    public function testHandleCaughtThrowableCallsDefaultRendererWhenNonePassed(): void
26
    {
27
        $throwable = new \RuntimeException();
28
29
        $this
30
            ->throwableRendererMock
31
            ->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Yiisoft\Yii\Web\ErrorHan...owableRendererInterface. ( Ignorable by Annotation )

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

31
            ->/** @scrutinizer ignore-call */ 
32
              expects($this->once())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
            ->method('renderVerbose')
33
            ->with($throwable);
34
35
36
        $this->errorHandler->handleCaughtThrowable($throwable);
37
    }
38
39
    public function testHandleCaughtThrowableCallsPassedRenderer(): void
40
    {
41
        $throwable = new \RuntimeException();
42
        $throwableRendererMock = $this->createMock(ThrowableRendererInterface::class);
43
44
        $this
45
            ->throwableRendererMock
46
            ->expects($this->never())
47
            ->method('renderVerbose')
48
            ->with($throwable);
49
50
        $throwableRendererMock
51
            ->expects($this->once())
52
            ->method('renderVerbose')
53
            ->with($throwable);
54
55
        $this->errorHandler->handleCaughtThrowable($throwable, $throwableRendererMock);
56
    }
57
58
    public function testHandleCaughtThrowableWithExposedDetailsCallsRenderVerbose(): void
59
    {
60
        $throwable = new \RuntimeException();
61
        $this
62
            ->throwableRendererMock
63
            ->expects($this->once())
64
            ->method('renderVerbose')
65
            ->with($throwable);
66
67
        $errorHandler = $this->errorHandler->withExposedDetails();
68
        $errorHandler->handleCaughtThrowable($throwable);
69
    }
70
71
    public function testHandleCaughtThrowableWithoutExposedDetailsCallsRender(): void
72
    {
73
        $throwable = new \RuntimeException();
74
        $this
75
            ->throwableRendererMock
76
            ->expects($this->once())
77
            ->method('render')
78
            ->with($throwable);
79
80
        $errorHandler = $this->errorHandler->withoutExposedDetails();
81
        $errorHandler->handleCaughtThrowable($throwable);
82
    }
83
}
84