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); |
|
|
|
|
27
|
|
|
$this->throwableRendererMock = $this->createMock(ThrowableRendererInterface::class); |
|
|
|
|
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()) |
|
|
|
|
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
|
|
|
|
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..