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($this->isInstanceOf(DeprecationException::class)); |
27
|
|
|
|
28
|
|
|
$listener = new DeprecationListener($interactor); |
29
|
|
|
|
30
|
|
|
\set_error_handler(function () { return false; }); |
31
|
|
|
try { |
32
|
|
|
$listener->register(); |
33
|
|
|
@\trigger_error('This is a deprecation', E_USER_DEPRECATED); |
34
|
|
|
} finally { |
35
|
|
|
$listener->unregister(); |
36
|
|
|
\restore_error_handler(); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testDeprecationIsReportedRegardlessErrorReporting() |
41
|
|
|
{ |
42
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
43
|
|
|
$interactor->expects($this->once())->method('noticeThrowable'); |
44
|
|
|
|
45
|
|
|
$listener = new DeprecationListener($interactor); |
46
|
|
|
|
47
|
|
|
\set_error_handler(function () { return false; }); |
48
|
|
|
$e = \error_reporting(0); |
49
|
|
|
try { |
50
|
|
|
$listener->register(); |
51
|
|
|
@\trigger_error('This is a deprecation', E_USER_DEPRECATED); |
52
|
|
|
} finally { |
53
|
|
|
$listener->unregister(); |
54
|
|
|
\error_reporting($e); |
55
|
|
|
\restore_error_handler(); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testOtherErrorAreIgnored() |
60
|
|
|
{ |
61
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
62
|
|
|
$interactor->expects($this->never())->method('noticeThrowable'); |
63
|
|
|
|
64
|
|
|
$listener = new DeprecationListener($interactor); |
65
|
|
|
|
66
|
|
|
\set_error_handler(function () { return false; }); |
67
|
|
|
try { |
68
|
|
|
$listener->register(); |
69
|
|
|
@\trigger_error('This is a notice', E_USER_NOTICE); |
70
|
|
|
} finally { |
71
|
|
|
$listener->unregister(); |
72
|
|
|
\restore_error_handler(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testInitialHandlerIsCalled() |
77
|
|
|
{ |
78
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
79
|
|
|
$interactor->expects($this->once())->method('noticeThrowable'); |
80
|
|
|
|
81
|
|
|
$handler = $this->createPartialMock(\stdClass::class, ['__invoke']); |
82
|
|
|
$handler->expects($this->once())->method('__invoke'); |
83
|
|
|
|
84
|
|
|
$listener = new DeprecationListener($interactor); |
85
|
|
|
|
86
|
|
|
\set_error_handler($handler); |
87
|
|
|
try { |
88
|
|
|
$listener->register(); |
89
|
|
|
@\trigger_error('This is a deprecation', E_USER_DEPRECATED); |
90
|
|
|
} finally { |
91
|
|
|
$listener->unregister(); |
92
|
|
|
\restore_error_handler(); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testUnregisterRemovesHandler() |
97
|
|
|
{ |
98
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
99
|
|
|
$interactor->expects($this->never())->method('noticeThrowable'); |
100
|
|
|
|
101
|
|
|
$listener = new DeprecationListener($interactor); |
102
|
|
|
|
103
|
|
|
\set_error_handler(function () { return false; }); |
104
|
|
|
try { |
105
|
|
|
$listener->register(); |
106
|
|
|
$listener->unregister(); |
107
|
|
|
@\trigger_error('This is a deprecation', E_USER_DEPRECATED); |
108
|
|
|
} finally { |
109
|
|
|
\restore_error_handler(); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testUnregisterRestorePreviousHandler() |
114
|
|
|
{ |
115
|
|
|
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
116
|
|
|
|
117
|
|
|
$handler = $this->createPartialMock(\stdClass::class, ['__invoke']); |
118
|
|
|
$handler->expects($this->once())->method('__invoke'); |
119
|
|
|
|
120
|
|
|
$listener = new DeprecationListener($interactor); |
121
|
|
|
|
122
|
|
|
\set_error_handler($handler); |
123
|
|
|
try { |
124
|
|
|
$listener->register(); |
125
|
|
|
$listener->unregister(); |
126
|
|
|
@\trigger_error('This is a deprecation', E_USER_DEPRECATED); |
127
|
|
|
} finally { |
128
|
|
|
\restore_error_handler(); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
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