ConfigTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 33
c 3
b 0
f 0
dl 0
loc 62
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGeneric() 0 47 1
A testDefaults() 0 11 3
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;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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