|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the PHP New Relic package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Alex Soban <[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 SobanVuex\NewRelic\Tests; |
|
13
|
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use SobanVuex\NewRelic\Agent; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @requires extension newrelic |
|
19
|
|
|
*/ |
|
20
|
|
|
final class AgentTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
protected $agent; |
|
23
|
|
|
|
|
24
|
|
|
protected function setUp(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->agent = new Agent(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected function tearDown(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->agent = null; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @covers \SobanVuex\NewRelic\Agent::isLoaded |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testIsLoaded() |
|
38
|
|
|
{ |
|
39
|
|
|
$expected = extension_loaded('newrelic'); |
|
40
|
|
|
$actual = $this->agent->isLoaded(); |
|
41
|
|
|
$this->assertEquals($expected, $actual); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @covers \SobanVuex\NewRelic\Agent::acceptDistributedTracePayload |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testAcceptDistributedTracePayload() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->assertExtensionMethod(__FUNCTION__, '8.4'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @covers \SobanVuex\NewRelic\Agent::aptDistributedTracePayloadHttpsafe |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testAptDistributedTracePayloadHttpsafe() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->assertExtensionMethod(__FUNCTION__, '8.4'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @covers \SobanVuex\NewRelic\Agent::addCustomParameter |
|
62
|
|
|
*/ |
|
63
|
|
|
public function testAddCustomParameter() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->assertExtensionMethod(__FUNCTION__, '4.4.5.35'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @covers \SobanVuex\NewRelic\Agent::addCustomTracer |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testAddCustomTracer() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @covers \SobanVuex\NewRelic\Agent::backgroundJob |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testBackgroundJob() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @covers \SobanVuex\NewRelic\Agent::captureParams |
|
86
|
|
|
*/ |
|
87
|
|
|
public function testCaptureParams() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @covers \SobanVuex\NewRelic\Agent::createDistributedTracePayload |
|
94
|
|
|
*/ |
|
95
|
|
|
public function testCreateDistributedTracePayload() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @covers \SobanVuex\NewRelic\Agent::customMetric |
|
102
|
|
|
*/ |
|
103
|
|
|
public function testCustomMetric() |
|
104
|
|
|
{ |
|
105
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @covers \SobanVuex\NewRelic\Agent::disableAutorum |
|
110
|
|
|
*/ |
|
111
|
|
|
public function testDisableAutorum() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->assertExtensionMethod(__FUNCTION__, '2.6.5.41'); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @covers \SobanVuex\NewRelic\Agent::endOfTransaction |
|
118
|
|
|
*/ |
|
119
|
|
|
public function testEndOfTransaction() |
|
120
|
|
|
{ |
|
121
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @covers \SobanVuex\NewRelic\Agent::endTransaction |
|
126
|
|
|
*/ |
|
127
|
|
|
public function testEndTransaction() |
|
128
|
|
|
{ |
|
129
|
|
|
$this->assertExtensionMethod(__FUNCTION__, '3.0.5.95'); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @covers \SobanVuex\NewRelic\Agent::getBrowserTimingFooter |
|
134
|
|
|
*/ |
|
135
|
|
|
public function testGetBrowserTimingFooter() |
|
136
|
|
|
{ |
|
137
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @covers \SobanVuex\NewRelic\Agent::getBrowserTimingHeader |
|
142
|
|
|
*/ |
|
143
|
|
|
public function testGetBrowserTimingHeader() |
|
144
|
|
|
{ |
|
145
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @covers \SobanVuex\NewRelic\Agent::ignoreApdex |
|
150
|
|
|
*/ |
|
151
|
|
|
public function testIgnoreApdex() |
|
152
|
|
|
{ |
|
153
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @covers \SobanVuex\NewRelic\Agent::ignoreTransaction |
|
158
|
|
|
*/ |
|
159
|
|
|
public function testIgnoreTransaction() |
|
160
|
|
|
{ |
|
161
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @covers \SobanVuex\NewRelic\Agent::nameTransaction |
|
166
|
|
|
*/ |
|
167
|
|
|
public function testNameTransaction() |
|
168
|
|
|
{ |
|
169
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @covers \SobanVuex\NewRelic\Agent::noticeError |
|
174
|
|
|
*/ |
|
175
|
|
|
public function testNoticeError() |
|
176
|
|
|
{ |
|
177
|
|
|
$this->assertExtensionMethod(__FUNCTION__, '2.6'); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @covers \SobanVuex\NewRelic\Agent::recordCustomEvent |
|
182
|
|
|
*/ |
|
183
|
|
|
public function testRecordCustomEvent() |
|
184
|
|
|
{ |
|
185
|
|
|
$this->assertExtensionMethod(__FUNCTION__, '4.18.0.89'); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @covers \SobanVuex\NewRelic\Agent::recordDatastoreSegment |
|
190
|
|
|
*/ |
|
191
|
|
|
public function testRecordDatastoreSegment() |
|
192
|
|
|
{ |
|
193
|
|
|
$this->assertExtensionMethod(__FUNCTION__, '7.5.0.199'); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @covers \SobanVuex\NewRelic\Agent::setAppname |
|
198
|
|
|
*/ |
|
199
|
|
|
public function testSetAppname() |
|
200
|
|
|
{ |
|
201
|
|
|
$this->assertExtensionMethod(__FUNCTION__); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @covers \SobanVuex\NewRelic\Agent::setUserAttributes |
|
206
|
|
|
*/ |
|
207
|
|
|
public function testSetUserAttributes() |
|
208
|
|
|
{ |
|
209
|
|
|
$this->assertExtensionMethod(__FUNCTION__, '3.1.5.111'); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @covers \SobanVuex\NewRelic\Agent::startTransaction |
|
214
|
|
|
*/ |
|
215
|
|
|
public function testStartTransaction() |
|
216
|
|
|
{ |
|
217
|
|
|
$this->assertExtensionMethod(__FUNCTION__, '3.0.5.95'); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
protected function parseMethodName($function) |
|
221
|
|
|
{ |
|
222
|
|
|
return 'newrelic' . substr(strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $function)), 4); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
protected function assertExtensionVersion($version, $method) |
|
226
|
|
|
{ |
|
227
|
|
|
if (version_compare(phpversion('newrelic'), $version) < 1) { |
|
228
|
|
|
$this->markTestSkipped(sprintf( |
|
229
|
|
|
'`%s` requires `newrelic` version %s', |
|
230
|
|
|
$method, |
|
231
|
|
|
$version |
|
232
|
|
|
)); |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
protected function assertExtensionMethod($function, $version = 0) |
|
237
|
|
|
{ |
|
238
|
|
|
$method = $this->parseMethodName($function); |
|
239
|
|
|
$this->assertExtensionVersion($version, $method); |
|
240
|
|
|
$this->assertTrue(function_exists($method)); |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|