Passed
Pull Request — master (#255)
by Alexander
14:13
created

testHandleCaughtThrowableCallsDefaultRendererWhenNonePassed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 12
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
    /** @var ErrorHandler  */
14
    private $errorHandler;
15
16
    /** @var LoggerInterface  */
17
    private $loggerMock;
18
19
    /** @var ThrowableRendererInterface  */
20
    private $throwableRendererMock;
21
22
    public function setUp(): void
23
    {
24
        parent::setUp();
25
        $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...
26
        $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...
27
        $this->errorHandler = new ErrorHandler($this->loggerMock, $this->throwableRendererMock);
28
    }
29
30
    public function testHandleCaughtThrowableCallsDefaultRendererWhenNonePassed(): void
31
    {
32
        $throwable = new \RuntimeException();
33
34
        $this
35
            ->throwableRendererMock
36
            ->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

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