1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Ekino New Relic bundle. |
7
|
|
|
* |
8
|
|
|
* (c) Ekino - Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Ekino\NewRelicBundle\Tests\Listener; |
15
|
|
|
|
16
|
|
|
use Ekino\NewRelicBundle\Exception\DeprecationException; |
17
|
|
|
use Ekino\NewRelicBundle\Listener\DeprecationListener; |
18
|
|
|
use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
20
|
|
|
|
21
|
|
|
class DeprecationListenerTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function testDeprecationIsReported() |
24
|
|
|
{ |
25
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
26
|
|
|
$interactor->expects($this->once())->method('noticeThrowable')->with( |
27
|
|
|
$this->isInstanceOf(DeprecationException::class) |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$listener = new DeprecationListener($interactor); |
31
|
|
|
|
32
|
|
|
\set_error_handler(function () { return false; }); |
33
|
|
|
try { |
34
|
|
|
$listener->register(); |
35
|
|
|
@\trigger_error('This is a deprecation', E_USER_DEPRECATED); |
36
|
|
|
} finally { |
37
|
|
|
$listener->unregister(); |
38
|
|
|
\restore_error_handler(); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testDeprecationIsReportedRegardlessErrorReporting() |
43
|
|
|
{ |
44
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
45
|
|
|
$interactor->expects($this->once())->method('noticeThrowable'); |
46
|
|
|
|
47
|
|
|
$listener = new DeprecationListener($interactor); |
48
|
|
|
|
49
|
|
|
\set_error_handler(function () { return false; }); |
50
|
|
|
$e = \error_reporting(0); |
51
|
|
|
try { |
52
|
|
|
$listener->register(); |
53
|
|
|
@\trigger_error('This is a deprecation', E_USER_DEPRECATED); |
54
|
|
|
} finally { |
55
|
|
|
$listener->unregister(); |
56
|
|
|
\error_reporting($e); |
57
|
|
|
\restore_error_handler(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testOtherErrorAreIgnored() |
62
|
|
|
{ |
63
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
64
|
|
|
$interactor->expects($this->never())->method('noticeThrowable'); |
65
|
|
|
|
66
|
|
|
$listener = new DeprecationListener($interactor); |
67
|
|
|
|
68
|
|
|
\set_error_handler(function () { return false; }); |
69
|
|
|
try { |
70
|
|
|
$listener->register(); |
71
|
|
|
@\trigger_error('This is a notice', E_USER_NOTICE); |
72
|
|
|
} finally { |
73
|
|
|
$listener->unregister(); |
74
|
|
|
\restore_error_handler(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testInitialHandlerIsCalled() |
79
|
|
|
{ |
80
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
81
|
|
|
$interactor->expects($this->once())->method('noticeThrowable'); |
82
|
|
|
|
83
|
|
|
$handler = $this->createPartialMock(DummyHandler::class, ['__invoke']); |
84
|
|
|
$handler->expects($this->once())->method('__invoke'); |
85
|
|
|
|
86
|
|
|
$listener = new DeprecationListener($interactor); |
87
|
|
|
|
88
|
|
|
\set_error_handler($handler); |
89
|
|
|
try { |
90
|
|
|
$listener->register(); |
91
|
|
|
@\trigger_error('This is a deprecation', E_USER_DEPRECATED); |
92
|
|
|
} finally { |
93
|
|
|
$listener->unregister(); |
94
|
|
|
\restore_error_handler(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testUnregisterRemovesHandler() |
99
|
|
|
{ |
100
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
101
|
|
|
$interactor->expects($this->never())->method('noticeThrowable'); |
102
|
|
|
|
103
|
|
|
$listener = new DeprecationListener($interactor); |
104
|
|
|
|
105
|
|
|
\set_error_handler(function () { return false; }); |
106
|
|
|
try { |
107
|
|
|
$listener->register(); |
108
|
|
|
$listener->unregister(); |
109
|
|
|
@\trigger_error('This is a deprecation', E_USER_DEPRECATED); |
110
|
|
|
} finally { |
111
|
|
|
\restore_error_handler(); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testUnregisterRestorePreviousHandler() |
116
|
|
|
{ |
117
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
118
|
|
|
|
119
|
|
|
$handler = $this->createPartialMock(DummyHandler::class, ['__invoke']); |
120
|
|
|
$handler->expects($this->once())->method('__invoke'); |
121
|
|
|
|
122
|
|
|
$listener = new DeprecationListener($interactor); |
123
|
|
|
|
124
|
|
|
\set_error_handler($handler); |
125
|
|
|
try { |
126
|
|
|
$listener->register(); |
127
|
|
|
$listener->unregister(); |
128
|
|
|
@\trigger_error('This is a deprecation', E_USER_DEPRECATED); |
129
|
|
|
} finally { |
130
|
|
|
\restore_error_handler(); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
class DummyHandler |
136
|
|
|
{ |
137
|
|
|
public function __invoke() |
138
|
|
|
{ |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
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