File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Onramplab \LaravelLogEnhancement \Tests \Unit \Handlers ;
4+
5+ use Onramplab \LaravelLogEnhancement \Tests \TestCase ;
6+ use Onramplab \LaravelLogEnhancement \Handlers \DatadogHandler ;
7+ use ReflectionClass ;
8+ use ReflectionProperty ;
9+
10+ class DatadogHandlerTest extends TestCase
11+ {
12+ /**
13+ * @test
14+ */
15+ public function construct_should_init ()
16+ {
17+ $ handler = new DatadogHandler (
18+ 'my-api-key ' ,
19+ 'us5 ' ,
20+ [
21+ 'source ' => 'laravel ' ,
22+ 'service ' => 'my-service ' ,
23+ 'hostname ' => 'my-host ' ,
24+ 'tags ' => 'env:local ' ,
25+ ]
26+ );
27+
28+ $ properties = $ this ->getPrivateProperties ($ handler );
29+
30+ $ this ->assertEquals ('my-api-key ' , $ properties ['key ' ]);
31+ $ this ->assertEquals ('us5.datadoghq.com ' , $ properties ['apiHost ' ]);
32+ $ this ->assertEquals ('laravel ' , $ properties ['attributes ' ]['source ' ]);
33+ $ this ->assertEquals ('my-service ' , $ properties ['attributes ' ]['service ' ]);
34+ $ this ->assertEquals ('my-host ' , $ properties ['attributes ' ]['hostname ' ]);
35+ $ this ->assertEquals ('env:local ' , $ properties ['attributes ' ]['tags ' ]);
36+ }
37+
38+ private function getPrivateProperties ($ object )
39+ {
40+ $ reflection = new ReflectionClass ($ object );
41+ $ properties = [];
42+
43+ foreach ($ reflection ->getProperties (ReflectionProperty::IS_PRIVATE ) as $ property ) {
44+ $ property ->setAccessible (true );
45+ $ properties [$ property ->getName ()] = $ property ->getValue ($ object );
46+ }
47+
48+ return $ properties ;
49+ }
50+ }
You can’t perform that action at this time.
0 commit comments