Passed
Push — master ( 64c6db...94fe0c )
by Harry
01:43
created

EnvConfigurationTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 63
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testPort() 0 6 1
A testHost() 0 6 1
A testTagsAppended() 0 9 1
A testTags() 0 7 1
A testLargePortWillThrowAnException() 0 4 1
A tearDown() 0 5 1
A testStringPortWillThrowAnException() 0 4 1
1
<?php
2
/**
3
 * This file is part of graze/dog-statsd
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/dog-statsd/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/dog-statsd
12
 */
13
14
namespace Graze\DogStatsD\Test\Unit;
15
16
use Graze\DogStatsD\Test\TestCase;
17
18
class EnvConfigurationTest extends TestCase
19
{
20
    public function tearDown()
21
    {
22
        putenv('DD_AGENT_HOST=');
23
        putenv('DD_DOGSTATSD_PORT=');
24
        putenv('DD_ENTITY_ID=');
25
    }
26
27
    public function testHost()
28
    {
29
        putenv('DD_AGENT_HOST=127.0.0.1');
30
        $this->client->configure();
31
32
        $this->assertEquals('127.0.0.1', $this->client->getHost());
33
    }
34
35
    public function testPort()
36
    {
37
        putenv('DD_DOGSTATSD_PORT=12434');
38
        $this->client->configure();
39
40
        $this->assertEquals(12434, $this->client->getPort());
41
    }
42
43
    /**
44
     * @expectedException \Graze\DogStatsD\Exception\ConfigurationException
45
     * @expectedExceptionMessage Option: Port is invalid or is out of range
46
     */
47
    public function testLargePortWillThrowAnException()
48
    {
49
        putenv('DD_DOGSTATSD_PORT=65536');
50
        $this->client->configure();
51
    }
52
53
    /**
54
     * @expectedException \Graze\DogStatsD\Exception\ConfigurationException
55
     * @expectedExceptionMessage Option: Port is invalid or is out of range
56
     */
57
    public function testStringPortWillThrowAnException()
58
    {
59
        putenv('DD_DOGSTATSD_PORT=not-integer');
60
        $this->client->configure();
61
    }
62
63
    public function testTags()
64
    {
65
        putenv('DD_ENTITY_ID=f87dsf7dsf9s7d9f8');
66
        $this->client->configure();
67
68
        $this->client->gauge('test_metric', 456);
69
        $this->assertEquals('test_metric:456|g|#dd.internal.entity_id:f87dsf7dsf9s7d9f8', $this->client->getLastMessage());
70
    }
71
72
    public function testTagsAppended()
73
    {
74
        putenv('DD_ENTITY_ID=f87dsf7dsf9s7d9f8');
75
        $this->client->configure([
76
            'tags' => ['key' => 'value'],
77
        ]);
78
79
        $this->client->gauge('test_metric', 456);
80
        $this->assertEquals('test_metric:456|g|#key:value,dd.internal.entity_id:f87dsf7dsf9s7d9f8', $this->client->getLastMessage());
81
    }
82
}
83