| 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: throwExceptions is expected to be: 'boolean', was: 'string' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     public function testInvalidThrowAnException() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $this->client->configure([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             'throwExceptions' => 'fish', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @expectedException \Graze\DogStatsD\Exception\ConfigurationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @expectedExceptionMessage Option: dataDog is expected to be: 'boolean', was: 'string' | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |     public function testInvalidDataDogThrowAnException() | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |         $this->client->configure([ | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |             'dataDog' => 'invalid', | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |         ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @expectedException \Graze\DogStatsD\Exception\ConfigurationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @expectedExceptionMessage Option: tags is expected to be: 'array', was: 'string' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     public function testInvalidTagsThrowsAnException() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $this->client->configure([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |             'tags' => 'tag,tag2', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 118 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 119 |  |  |  |