1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graze\DogStatsD\Test\Unit; |
4
|
|
|
|
5
|
|
|
use Graze\DogStatsD\Test\TestCase; |
6
|
|
|
|
7
|
|
|
class ConnectionTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Non-integer ports are not acceptable |
11
|
|
|
* |
12
|
|
|
* @expectedException \Graze\DogStatsD\Exception\ConnectionException |
13
|
|
|
*/ |
14
|
|
|
public function testInvalidHost() |
15
|
|
|
{ |
16
|
|
|
$this->client->configure(array( |
17
|
|
|
'host' => 'hostdoesnotexiststalleverlol.stupidtld', |
18
|
|
|
)); |
19
|
|
|
$this->client->increment('test'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testTimeoutSettingIsUsedWhenCreatingSocketIfProvided() |
23
|
|
|
{ |
24
|
|
|
$this->client->configure(array( |
25
|
|
|
'host' => 'localhost', |
26
|
|
|
'timeout' => 123, |
27
|
|
|
)); |
28
|
|
|
$this->assertAttributeSame(123, 'timeout', $this->client); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testCanBeConfiguredNotToThrowConnectionExceptions() |
32
|
|
|
{ |
33
|
|
|
$this->client->configure(array( |
34
|
|
|
'host' => 'hostdoesnotexiststalleverlol.stupidtld', |
35
|
|
|
'throwExceptions' => false, |
36
|
|
|
)); |
37
|
|
|
$handlerInvoked = false; |
38
|
|
|
|
39
|
|
|
$testCase = $this; |
40
|
|
|
|
41
|
|
|
set_error_handler( |
42
|
|
|
function ($errno, $errstr, $errfile, $errline, $errcontext) use ($testCase, &$handlerInvoked) { |
|
|
|
|
43
|
|
|
$handlerInvoked = true; |
44
|
|
|
|
45
|
|
|
$testCase->assertSame(E_USER_WARNING, $errno); |
46
|
|
|
$testCase->assertSame( |
47
|
|
|
'StatsD server connection failed (udp://hostdoesnotexiststalleverlol.stupidtld:8125)', |
48
|
|
|
$errstr |
49
|
|
|
); |
50
|
|
|
$testCase->assertSame(realpath(__DIR__ . '/../../src/Client.php'), $errfile); |
51
|
|
|
}, |
52
|
|
|
E_USER_WARNING |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$this->client->increment('test'); |
56
|
|
|
restore_error_handler(); |
57
|
|
|
|
58
|
|
|
$this->assertTrue($handlerInvoked); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testTimeoutDefaultsToPhpIniDefaultSocketTimeout() |
62
|
|
|
{ |
63
|
|
|
$this->assertAttributeEquals(ini_get('default_socket_timeout'), 'timeout', $this->client); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.