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 invalid or 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 invalid or is out of range |
54
|
|
|
*/ |
55
|
|
|
public function testStringPortWillThrowAnException() |
56
|
|
|
{ |
57
|
|
|
$this->client->configure([ |
58
|
|
|
'port' => 'not-integer', |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testValidStringPort() |
63
|
|
|
{ |
64
|
|
|
$this->client->configure([ |
65
|
|
|
'port' => '1234', |
66
|
|
|
]); |
67
|
|
|
$this->assertEquals(1234, $this->client->getPort()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testDefaultPort() |
71
|
|
|
{ |
72
|
|
|
$this->assertEquals(8125, $this->client->getPort()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testValidPort() |
76
|
|
|
{ |
77
|
|
|
$this->client->configure([ |
78
|
|
|
'port' => 1234, |
79
|
|
|
]); |
80
|
|
|
$this->assertEquals(1234, $this->client->getPort()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @expectedException \Graze\DogStatsD\Exception\ConfigurationException |
85
|
|
|
* @expectedExceptionMessage Option: namespace is expected to be: 'string', was: 'integer' |
86
|
|
|
*/ |
87
|
|
|
public function testInvalidNamespace() |
88
|
|
|
{ |
89
|
|
|
$this->client->configure([ |
90
|
|
|
'namespace' => 12345, |
91
|
|
|
]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @expectedException \Graze\DogStatsD\Exception\ConfigurationException |
96
|
|
|
* @expectedExceptionMessage Option: dataDog is expected to be: 'boolean', was: 'string' |
97
|
|
|
*/ |
98
|
|
|
public function testInvalidDataDogThrowAnException() |
99
|
|
|
{ |
100
|
|
|
$this->client->configure([ |
101
|
|
|
'dataDog' => 'invalid', |
102
|
|
|
]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @expectedException \Graze\DogStatsD\Exception\ConfigurationException |
107
|
|
|
* @expectedExceptionMessage Option: tags is expected to be: 'array', was: 'string' |
108
|
|
|
*/ |
109
|
|
|
public function testInvalidTagsThrowsAnException() |
110
|
|
|
{ |
111
|
|
|
$this->client->configure([ |
112
|
|
|
'tags' => 'tag,tag2', |
113
|
|
|
]); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @expectedException \Graze\DogStatsD\Exception\ConfigurationException |
118
|
|
|
* @expectedExceptionMessage Option: onError 'somethingelse' is not one of: [error,exception,ignore] |
119
|
|
|
*/ |
120
|
|
|
public function testInvalidOnErrorThrowsAnException() |
121
|
|
|
{ |
122
|
|
|
$this->client->configure([ |
123
|
|
|
'onError' => 'somethingelse', |
124
|
|
|
]); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function testOnErrorConfiguration() |
128
|
|
|
{ |
129
|
|
|
// exception is default |
130
|
|
|
$this->assertAttributeEquals('exception', 'onError', $this->client); |
131
|
|
|
|
132
|
|
|
$this->client->configure(['onError' => 'error']); |
133
|
|
|
$this->assertAttributeEquals('error', 'onError', $this->client); |
134
|
|
|
|
135
|
|
|
$this->client->configure(['onError' => 'exception']); |
136
|
|
|
$this->assertAttributeEquals('exception', 'onError', $this->client); |
137
|
|
|
|
138
|
|
|
$this->client->configure(['onError' => 'ignore']); |
139
|
|
|
$this->assertAttributeEquals('ignore', 'onError', $this->client); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|