|
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\NewRelic; |
|
15
|
|
|
|
|
16
|
|
|
use Ekino\NewRelicBundle\NewRelic\Config; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
|
|
19
|
|
|
class ConfigTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testGeneric() |
|
22
|
|
|
{ |
|
23
|
|
|
$newRelic = new Config('Ekino', 'XXX'); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertSame('Ekino', $newRelic->getName()); |
|
26
|
|
|
$this->assertSame('XXX', $newRelic->getApiKey()); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertEmpty($newRelic->getCustomEvents()); |
|
29
|
|
|
$this->assertEmpty($newRelic->getCustomMetrics()); |
|
30
|
|
|
$this->assertEmpty($newRelic->getCustomParameters()); |
|
31
|
|
|
|
|
32
|
|
|
$newRelic->addCustomEvent('WidgetSale', ['color' => 'red', 'weight' => 12.5]); |
|
33
|
|
|
$newRelic->addCustomEvent('WidgetSale', ['color' => 'blue', 'weight' => 12.5]); |
|
34
|
|
|
|
|
35
|
|
|
$expected = [ |
|
36
|
|
|
'WidgetSale' => [ |
|
37
|
|
|
[ |
|
38
|
|
|
'color' => 'red', |
|
39
|
|
|
'weight' => 12.5, |
|
40
|
|
|
], |
|
41
|
|
|
[ |
|
42
|
|
|
'color' => 'blue', |
|
43
|
|
|
'weight' => 12.5, |
|
44
|
|
|
], |
|
45
|
|
|
], |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
$this->assertSame($expected, $newRelic->getCustomEvents()); |
|
49
|
|
|
|
|
50
|
|
|
$newRelic->addCustomMetric('foo', 4.2); |
|
51
|
|
|
$newRelic->addCustomMetric('asd', 1); |
|
52
|
|
|
|
|
53
|
|
|
$expected = [ |
|
54
|
|
|
'foo' => 4.2, |
|
55
|
|
|
'asd' => 1.0, |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
$this->assertSame($expected, $newRelic->getCustomMetrics()); |
|
59
|
|
|
|
|
60
|
|
|
$newRelic->addCustomParameter('param1', 1); |
|
61
|
|
|
|
|
62
|
|
|
$expected = [ |
|
63
|
|
|
'param1' => 1, |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
$this->assertSame($expected, $newRelic->getCustomParameters()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testDefaults() |
|
70
|
|
|
{ |
|
71
|
|
|
$newRelic = new Config('', ''); |
|
72
|
|
|
|
|
73
|
|
|
$this->assertNotNull($newRelic->getName()); |
|
74
|
|
|
$this->assertSame(\ini_get('newrelic.appname') ?: '', $newRelic->getName()); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertNotNull($newRelic->getLicenseKey()); |
|
77
|
|
|
$this->assertSame(\ini_get('newrelic.license') ?: '', $newRelic->getLicenseKey()); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|