Passed
Pull Request — master (#255)
by
unknown
11:51
created

testHandleCaughtThrowableWithoutExposedDetailsCallsRender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 8
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
4
namespace Yiisoft\Yii\Web\Tests\ErrorHandler;
5
6
7
use PHPUnit\Framework\TestCase;
8
use Psr\Log\LoggerInterface;
9
use Yiisoft\Yii\Web\ErrorHandler\ErrorHandler;
10
use Yiisoft\Yii\Web\ErrorHandler\ThrowableRendererInterface;
11
12
class ErrorHandlerTest extends TestCase
13
{
14
    /** @var ErrorHandler  */
15
    private $errorHandler;
16
17
    /** @var LoggerInterface  */
18
    private $loggerMock;
19
20
    /** @var ThrowableRendererInterface  */
21
    private $throwableRendererMock;
22
23
    public function setUp(): void
24
    {
25
        parent::setUp();
26
        $this->loggerMock = $this->createMock(LoggerInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Psr\Log\LoggerInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Psr\Log\LoggerInterface of property $loggerMock.

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...
27
        $this->throwableRendererMock = $this->createMock(ThrowableRendererInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Yiisof...ndererInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Yiisoft\Yii\Web\ErrorHan...owableRendererInterface of property $throwableRendererMock.

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->errorHandler = new ErrorHandler($this->loggerMock, $this->throwableRendererMock);
29
    }
30
31
    public function testHandleCaughtThrowableCallsDefaultRendererWhenNonePassed(): void
32
    {
33
        $throwable = new \RuntimeException();
34
35
        $this
36
            ->throwableRendererMock
37
            ->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

37
            ->/** @scrutinizer ignore-call */ 
38
              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...
38
            ->method('renderVerbose')
39
            ->with($throwable);
40
41
42
        $this->errorHandler->handleCaughtThrowable($throwable);
43
    }
44
45
    public function testHandleCaughtThrowableCallsPassedRenderer(): void
46
    {
47
        $throwable = new \RuntimeException();
48
        $throwableRendererMock = $this->createMock(ThrowableRendererInterface::class);
49
50
        $this
51
            ->throwableRendererMock
52
            ->expects($this->never())
53
            ->method('renderVerbose')
54
            ->with($throwable);
55
56
        $throwableRendererMock
57
            ->expects($this->once())
58
            ->method('renderVerbose')
59
            ->with($throwable);
60
61
        $this->errorHandler->handleCaughtThrowable($throwable, $throwableRendererMock);
62
    }
63
64
    public function testHandleCaughtThrowableWithExposedDetailsCallsRenderVerbose(): void
65
    {
66
        $throwable = new \RuntimeException();
67
        $this
68
            ->throwableRendererMock
69
            ->expects($this->once())
70
            ->method('renderVerbose')
71
            ->with($throwable);
72
73
        $errorHandler = $this->errorHandler->withExposedDetails();
74
        $errorHandler->handleCaughtThrowable($throwable);
75
    }
76
77
    public function testHandleCaughtThrowableWithoutExposedDetailsCallsRender(): void
78
    {
79
        $throwable = new \RuntimeException();
80
        $this
81
            ->throwableRendererMock
82
            ->expects($this->once())
83
            ->method('render')
84
            ->with($throwable);
85
86
        $errorHandler = $this->errorHandler->withoutExposedDetails();
87
        $errorHandler->handleCaughtThrowable($throwable);
88
    }
89
}
90