33
44use HelloFresh \Stats ;
55use HelloFresh \Stats \Bucket ;
6+ use League \StatsD \Client ;
7+ use League \StatsD \Exception \ConfigurationException ;
68use PHPUnit \Framework \TestCase ;
9+ use PHPUnit_Framework_MockObject_MockObject ;
10+ use ReflectionClass ;
11+
12+ class ExposedClientStatsD extends StatsD
13+ {
14+ public function getClient ()
15+ {
16+ return $ this ->client ;
17+ }
18+ }
719
820class StatsDTest extends TestCase
921{
@@ -17,7 +29,7 @@ public function testBuildOptions()
1729 ->disableOriginalConstructor ()
1830 ->getMock ();
1931
20- $ reflection = new \ ReflectionClass ($ statsClient );
32+ $ reflection = new ReflectionClass ($ statsClient );
2133 $ methodBuildOptions = $ reflection ->getMethod ('buildOptions ' );
2234 $ methodBuildOptions ->setAccessible (true );
2335 $ this ->assertEquals (
@@ -32,6 +44,30 @@ public function testBuildOptions()
3244 );
3345 }
3446
47+ /**
48+ * @throws ConfigurationException
49+ */
50+ public function testDefaultClientInstance ()
51+ {
52+ $ dns = 'statsd://stats.local:1234/prefix.ns?timeout=2.5&error=0 ' ;
53+ $ statsD = new ExposedClientStatsD ($ dns );
54+ $ instantiatedClient = $ statsD ->getClient ();
55+
56+ $ this ->assertInstanceOf (Client::class, $ instantiatedClient );
57+ }
58+
59+ /**
60+ * @throws ConfigurationException
61+ */
62+ public function testOptionalClientInstance ()
63+ {
64+ $ dns = 'statsd://stats.local:1234/prefix.ns?timeout=2.5&error=0 ' ;
65+ $ statsD = new ExposedClientStatsD ($ dns , Stats \StatsD \SilentClient::class);
66+ $ instantiatedClient = $ statsD ->getClient ();
67+
68+ $ this ->assertInstanceOf (Stats \StatsD \SilentClient::class, $ instantiatedClient );
69+ }
70+
3571 public function testInstances ()
3672 {
3773 if (!class_exists ('\League\StatsD\Client ' )) {
@@ -50,12 +86,12 @@ public function testHTTPRequestSection()
5086
5187 $ section = uniqid ('section ' , true );
5288
53- /** @var \ PHPUnit_Framework_MockObject_MockObject|\League\StatsD\ Client $statsd */
89+ /** @var PHPUnit_Framework_MockObject_MockObject|Client $statsd */
5490 $ statsd = $ this ->getMockBuilder ('\League\StatsD\Client ' )->setMethods (['gauge ' ])->getMock ();
5591
5692 $ statsClient = new StatsD ($ statsd );
5793
58- $ reflection = new \ ReflectionClass ($ statsClient );
94+ $ reflection = new ReflectionClass ($ statsClient );
5995 $ reflectionProperty = $ reflection ->getProperty ('httpRequestSection ' );
6096 $ reflectionProperty ->setAccessible (true );
6197
0 commit comments