1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Ekino New Relic bundle. |
5
|
|
|
* |
6
|
|
|
* (c) Ekino - Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ekino\Bundle\NewRelicBundle\Tests\Listener; |
13
|
|
|
|
14
|
|
|
use Ekino\Bundle\NewRelicBundle\Exception\DeprecationException; |
15
|
|
|
use Ekino\Bundle\NewRelicBundle\Listener\DeprecationListener; |
16
|
|
|
use Ekino\Bundle\NewRelicBundle\NewRelic\NewRelicInteractorInterface; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
18
|
|
|
|
19
|
|
|
class DeprecationListenerTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
public function testDeprecationIsReported() |
22
|
|
|
{ |
23
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
24
|
|
|
$interactor->expects($this->once())->method('noticeThrowable')->with($this->isInstanceOf(DeprecationException::class)); |
25
|
|
|
|
26
|
|
|
$listener = new DeprecationListener($interactor); |
27
|
|
|
|
28
|
|
|
set_error_handler(function () { return false; }); |
29
|
|
|
try { |
30
|
|
|
$listener->register(); |
31
|
|
|
@trigger_error('This is a deprecation', E_USER_DEPRECATED); |
32
|
|
|
} finally { |
33
|
|
|
$listener->unregister(); |
34
|
|
|
restore_error_handler(); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testDeprecationIsReportedRegardlessErrorReporting() |
39
|
|
|
{ |
40
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
41
|
|
|
$interactor->expects($this->once())->method('noticeThrowable'); |
42
|
|
|
|
43
|
|
|
$listener = new DeprecationListener($interactor); |
44
|
|
|
|
45
|
|
|
set_error_handler(function () { return false; }); |
46
|
|
|
$e = error_reporting(0); |
47
|
|
|
try { |
48
|
|
|
$listener->register(); |
49
|
|
|
@trigger_error('This is a deprecation', E_USER_DEPRECATED); |
50
|
|
|
} finally { |
51
|
|
|
$listener->unregister(); |
52
|
|
|
error_reporting($e); |
53
|
|
|
restore_error_handler(); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testOtherErrorAreIgnored() |
58
|
|
|
{ |
59
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
60
|
|
|
$interactor->expects($this->never())->method('noticeThrowable'); |
61
|
|
|
|
62
|
|
|
$listener = new DeprecationListener($interactor); |
63
|
|
|
|
64
|
|
|
set_error_handler(function () { return false; }); |
65
|
|
|
try { |
66
|
|
|
$listener->register(); |
67
|
|
|
@trigger_error('This is a notice', E_USER_NOTICE); |
68
|
|
|
} finally { |
69
|
|
|
$listener->unregister(); |
70
|
|
|
restore_error_handler(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testInitialHandlerIsCalled() |
75
|
|
|
{ |
76
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
77
|
|
|
$interactor->expects($this->once())->method('noticeThrowable'); |
78
|
|
|
|
79
|
|
|
$handler = $this->createPartialMock(\stdClass::class, ['__invoke']); |
80
|
|
|
$handler->expects($this->once())->method('__invoke'); |
81
|
|
|
|
82
|
|
|
$listener = new DeprecationListener($interactor); |
83
|
|
|
|
84
|
|
|
set_error_handler($handler); |
85
|
|
|
try { |
86
|
|
|
$listener->register(); |
87
|
|
|
@trigger_error('This is a deprecation', E_USER_DEPRECATED); |
88
|
|
|
} finally { |
89
|
|
|
$listener->unregister(); |
90
|
|
|
restore_error_handler(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testUnregisterRemovesHandler() |
95
|
|
|
{ |
96
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
97
|
|
|
$interactor->expects($this->never())->method('noticeThrowable'); |
98
|
|
|
|
99
|
|
|
$listener = new DeprecationListener($interactor); |
100
|
|
|
|
101
|
|
|
set_error_handler(function () { return false; }); |
102
|
|
|
try { |
103
|
|
|
$listener->register(); |
104
|
|
|
$listener->unregister(); |
105
|
|
|
@trigger_error('This is a deprecation', E_USER_DEPRECATED); |
106
|
|
|
} finally { |
107
|
|
|
restore_error_handler(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function testUnregisterRestorePreviousHandler() |
112
|
|
|
{ |
113
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
114
|
|
|
|
115
|
|
|
$handler = $this->createPartialMock(\stdClass::class, ['__invoke']); |
116
|
|
|
$handler->expects($this->once())->method('__invoke'); |
117
|
|
|
|
118
|
|
|
$listener = new DeprecationListener($interactor); |
119
|
|
|
|
120
|
|
|
set_error_handler($handler); |
121
|
|
|
try { |
122
|
|
|
$listener->register(); |
123
|
|
|
$listener->unregister(); |
124
|
|
|
@trigger_error('This is a deprecation', E_USER_DEPRECATED); |
125
|
|
|
} finally { |
126
|
|
|
restore_error_handler(); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths