Completed
Pull Request — master (#13)
by Harry
02:43
created

testLargePortWillThrowAnException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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\Exception\ConfigurationException;
17
use Graze\DogStatsD\Test\TestCase;
18
19
class ConfigurationTest extends TestCase
20
{
21
    public function testHost()
22
    {
23
        $this->client->configure([
24
            'host' => '127.0.0.1',
25
        ]);
26
        $this->assertEquals('127.0.0.1', $this->client->getHost());
27
    }
28
29
    /**
30
     * @expectedException \Graze\DogStatsD\Exception\ConfigurationException
31
     * @expectedExceptionMessage Option: host is expected to be: 'string', was: 'integer'
32
     */
33
    public function testHostInvalidTypeWillThrowAnException()
34
    {
35
        $this->client->configure([
36
            'host' => 12434,
37
        ]);
38
    }
39
40
    /**
41
     * @expectedException \Graze\DogStatsD\Exception\ConfigurationException
42
     * @expectedExceptionMessage Option: Port is out of range
43
     */
44
    public function testLargePortWillThrowAnException()
45
    {
46
        $this->client->configure([
47
            'port' => 65536,
48
        ]);
49
    }
50
51
    /**
52
     * @expectedException \Graze\DogStatsD\Exception\ConfigurationException
53
     * @expectedExceptionMessage Option: port is expected to be: 'integer', was: 'string'
54
     */
55
    public function testStringPortWillThrowAnException()
56
    {
57
        $this->client->configure([
58
            'port' => 'not-integer',
59
        ]);
60
    }
61
62
    public function testDefaultPort()
63
    {
64
        $this->assertEquals($this->client->getPort(), 8125);
65
    }
66
67
    public function testValidPort()
68
    {
69
        $this->client->configure([
70
            'port' => 1234,
71
        ]);
72
        $this->assertEquals($this->client->getPort(), 1234);
73
    }
74
75
    /**
76
     * @expectedException \Graze\DogStatsD\Exception\ConfigurationException
77
     * @expectedExceptionMessage Option: namespace is expected to be: 'string', was: 'integer'
78
     */
79
    public function testInvalidNamespace()
80
    {
81
        $this->client->configure([
82
            'namespace' => 12345,
83
        ]);
84
    }
85
86
    /**
87
     * @expectedException \Graze\DogStatsD\Exception\ConfigurationException
88
     * @expectedExceptionMessage Option: dataDog is expected to be: 'boolean', was: 'string'
89
     */
90
    public function testInvalidDataDogThrowAnException()
91
    {
92
        $this->client->configure([
93
            'dataDog' => 'invalid',
94
        ]);
95
    }
96
97
    /**
98
     * @expectedException \Graze\DogStatsD\Exception\ConfigurationException
99
     * @expectedExceptionMessage Option: tags is expected to be: 'array', was: 'string'
100
     */
101
    public function testInvalidTagsThrowsAnException()
102
    {
103
        $this->client->configure([
104
            'tags' => 'tag,tag2',
105
        ]);
106
    }
107
108
    /**
109
     * @expectedException \Graze\DogStatsD\Exception\ConfigurationException
110
     * @expectedExceptionMessage Option: onError 'somethingelse' is not one of: [error,exception,ignore]
111
     */
112
    public function testInvalidOnErrorThrowsAnException()
113
    {
114
        $this->client->configure([
115
            'onError' => 'somethingelse',
116
        ]);
117
    }
118
119
    public function testOnErrorConfiguration()
120
    {
121
        // exception is default
122
        $this->assertAttributeEquals('exception', 'onError', $this->client);
123
124
        $this->client->configure(['onError' => 'error']);
125
        $this->assertAttributeEquals('error', 'onError', $this->client);
126
127
        $this->client->configure(['onError' => 'exception']);
128
        $this->assertAttributeEquals('exception', 'onError', $this->client);
129
130
        $this->client->configure(['onError' => 'ignore']);
131
        $this->assertAttributeEquals('ignore', 'onError', $this->client);
132
    }
133
}
134