Passed
Push — master ( bf6a9d...dfd885 )
by Tobias
02:21
created

ConfigTest::testGeneric()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 46
rs 9.1781
c 0
b 0
f 0
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');
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