44
55class ConnectionTest extends TestCase
66{
7-
87 /**
98 * Non-integer ports are not acceptable
109 * @expectedException League\StatsD\Exception\ConnectionException
@@ -23,10 +22,39 @@ public function testTimeoutSettingIsUsedWhenCreatingSocketIfProvided()
2322 'host ' => 'localhost ' ,
2423 'timeout ' => 123
2524 ));
26-
2725 $ this ->assertAttributeSame (123 , 'timeout ' , $ this ->client );
2826 }
2927
28+ public function testCanBeConfiguredNotToThrowConnectionExceptions ()
29+ {
30+ $ this ->client ->configure (array (
31+ 'host ' => 'hostdoesnotexiststalleverlol.stupidtld ' ,
32+ 'throwConnectionExceptions ' => false
33+ ));
34+ $ handlerInvoked = false ;
35+
36+ $ testCase = $ this ;
37+
38+ set_error_handler (
39+ function ($ errno , $ errstr , $ errfile , $ errline , $ errcontext ) use ($ testCase , &$ handlerInvoked ) {
40+ $ handlerInvoked = true ;
41+
42+ $ testCase ->assertSame (E_USER_WARNING , $ errno );
43+ $ testCase ->assertSame (
44+ 'StatsD server connection failed (udp://hostdoesnotexiststalleverlol.stupidtld:8125) ' ,
45+ $ errstr
46+ );
47+ $ testCase ->assertSame (realpath (__DIR__ . '/../src/Client.php ' ), $ errfile );
48+ },
49+ E_USER_WARNING
50+ );
51+
52+ $ this ->client ->increment ('test ' );
53+ restore_error_handler ();
54+
55+ $ this ->assertTrue ($ handlerInvoked );
56+ }
57+
3058 public function testTimeoutDefaultsToPhpIniDefaultSocketTimeout ()
3159 {
3260 $ this ->assertAttributeSame (ini_get ('default_socket_timeout ' ), 'timeout ' , $ this ->client );
0 commit comments