Passed
Branch master (ca9f32)
by Alex
02:10
created

AgentTest::testRecordDatastoreSegment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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()
25
    {
26
        $this->agent = new Agent();
27
    }
28
29
    protected function tearDown()
30
    {
31
        $this->agent = null;
32
    }
33
34
    /**
35
     * @covers 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 Agent::addCustomParameter
46
     */
47
    public function testAddCustomParameter()
48
    {
49
        $this->assertExtensionMethod(__FUNCTION__, '4.4.5.35');
50
    }
51
52
    /**
53
     * @covers Agent::addCustomTracer
54
     */
55
    public function testAddCustomTracer()
56
    {
57
        $this->assertExtensionMethod(__FUNCTION__);
58
    }
59
60
    /**
61
     * @covers Agent::backgroundJob
62
     */
63
    public function testBackgroundJob()
64
    {
65
        $this->assertExtensionMethod(__FUNCTION__);
66
    }
67
68
    /**
69
     * @covers Agent::captureParams
70
     */
71
    public function testCaptureParams()
72
    {
73
        $this->assertExtensionMethod(__FUNCTION__);
74
    }
75
76
    /**
77
     * @covers Agent::customMetric
78
     */
79
    public function testCustomMetric()
80
    {
81
        $this->assertExtensionMethod(__FUNCTION__);
82
    }
83
84
    /**
85
     * @covers Agent::disableAutorum
86
     */
87
    public function testDisableAutorum()
88
    {
89
        $this->assertExtensionMethod(__FUNCTION__, '2.6.5.41');
90
    }
91
92
    /**
93
     * @covers Agent::endOfTransaction
94
     */
95
    public function testEndOfTransaction()
96
    {
97
        $this->assertExtensionMethod(__FUNCTION__);
98
    }
99
100
    /**
101
     * @covers Agent::endTransaction
102
     */
103
    public function testEndTransaction()
104
    {
105
        $this->assertExtensionMethod(__FUNCTION__, '3.0.5.95');
106
    }
107
108
    /**
109
     * @covers Agent::getBrowserTimingFooter
110
     */
111
    public function testGetBrowserTimingFooter()
112
    {
113
        $this->assertExtensionMethod(__FUNCTION__);
114
    }
115
116
    /**
117
     * @covers Agent::getBrowserTimingHeader
118
     */
119
    public function testGetBrowserTimingHeader()
120
    {
121
        $this->assertExtensionMethod(__FUNCTION__);
122
    }
123
124
    /**
125
     * @covers Agent::ignoreApdex
126
     */
127
    public function testIgnoreApdex()
128
    {
129
        $this->assertExtensionMethod(__FUNCTION__);
130
    }
131
132
    /**
133
     * @covers Agent::ignoreTransaction
134
     */
135
    public function testIgnoreTransaction()
136
    {
137
        $this->assertExtensionMethod(__FUNCTION__);
138
    }
139
140
    /**
141
     * @covers Agent::nameTransaction
142
     */
143
    public function testNameTransaction()
144
    {
145
        $this->assertExtensionMethod(__FUNCTION__);
146
    }
147
148
    /**
149
     * @covers Agent::noticeError
150
     */
151
    public function testNoticeError()
152
    {
153
        $this->assertExtensionMethod(__FUNCTION__, '2.6');
154
    }
155
156
    /**
157
     * @covers Agent::recordCustomEvent
158
     */
159
    public function testRecordCustomEvent()
160
    {
161
        $this->assertExtensionMethod(__FUNCTION__, '4.18.0.89');
162
    }
163
164
    /**
165
     * @covers Agent::recordDatastoreSegment
166
     */
167
    public function testRecordDatastoreSegment()
168
    {
169
        $this->assertExtensionMethod(__FUNCTION__, '7.5.0.199');
170
    }
171
172
    /**
173
     * @covers Agent::setAppname
174
     */
175
    public function testSetAppname()
176
    {
177
        $this->assertExtensionMethod(__FUNCTION__);
178
    }
179
180
    /**
181
     * @covers Agent::setUserAttributes
182
     */
183
    public function testSetUserAttributes()
184
    {
185
        $this->assertExtensionMethod(__FUNCTION__, '3.1.5.111');
186
    }
187
188
    /**
189
     * @covers Agent::startTransaction
190
     */
191
    public function testStartTransaction()
192
    {
193
        $this->assertExtensionMethod(__FUNCTION__, '3.0.5.95');
194
    }
195
196
    protected function parseMethodName($function)
197
    {
198
        return 'newrelic' . substr(strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $function)), 4);
199
    }
200
201
    protected function assertExtensionVersion($version, $method)
202
    {
203
        if (version_compare(phpversion('newrelic'), $version) < 1) {
204
            $this->markTestSkipped(sprintf(
205
                '`%s` requires `newrelic` version %s',
206
                $method,
207
                $version
208
            ));
209
        }
210
    }
211
212
    protected function assertExtensionMethod($function, $version = 0)
213
    {
214
        $method = $this->parseMethodName($function);
215
        $this->assertExtensionVersion($version, $method);
216
        $this->assertTrue(function_exists($method));
217
    }
218
}
219