File tree Expand file tree Collapse file tree 4 files changed +38
-3
lines changed Expand file tree Collapse file tree 4 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 112
112
"dev:test:unit:teardown" : " echo 'Tore down for unit tests...'" ,
113
113
"dev:test:integration" : [
114
114
" @dev:test:integration:setup" ,
115
- " echo 'No integration tests to run' " ,
115
+ " phpunit --colors=always --testdox --testsuite=integration " ,
116
116
" @dev:test:integration:teardown"
117
117
],
118
118
"dev:test:integration:debug" : " phpunit --colors=always --testdox -d xdebug.profiler_enable=on" ,
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ public static function register(): void
42
42
self ::$ instance = new OpenTelemetryHook ();
43
43
}
44
44
45
- if (self ::$ registeredHook ) {
45
+ if (self ::$ registeredHook && self :: isRegisteredInHooks () ) {
46
46
return ;
47
47
}
48
48
@@ -88,4 +88,21 @@ public function supportsFlagValueType(string $flagValueType): bool
88
88
{
89
89
return true ;
90
90
}
91
+
92
+ /**
93
+ * Hooks can be cleared by other means so we can't simply memoize whether a registration has occurred
94
+ *
95
+ * However if no registration has yet happened then we can absolutely determine that the hook will
96
+ * not be registered yet.
97
+ */
98
+ private static function isRegisteredInHooks (): bool
99
+ {
100
+ foreach (OpenFeatureAPI::getInstance ()->getHooks () as $ hook ) {
101
+ if ($ hook instanceof OpenTelemetryHook) {
102
+ return true ;
103
+ }
104
+ }
105
+
106
+ return false ;
107
+ }
91
108
}
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
// automatically registers the OTel hook for OpenFeature
4
- OpenFeature \Hooks \OpenTelemetry \OpenTelemetryHook::register ();
6
+ OpenFeature \Hooks \OpenTelemetry \OpenTelemetryHook::register ();
Original file line number Diff line number Diff line change 11
11
12
12
class OpenTelemetryHookTest extends TestCase
13
13
{
14
+ public function testIsRegisteredAutomatically (): void
15
+ {
16
+ // Given
17
+ $ api = OpenFeatureAPI::getInstance ();
18
+ $ api ->clearHooks ();
19
+
20
+ // When
21
+ // simulates the composer autoload
22
+ require_once __DIR__ . '/../../src/_autoload.php ' ;
23
+
24
+ // Then
25
+ $ this ->assertNotEmpty ($ api ->getHooks ());
26
+ $ this ->assertInstanceOf (Hook::class, $ api ->getHooks ()[0 ]);
27
+ }
28
+
14
29
public function testCanBeRegistered (): void
15
30
{
16
31
// Given
17
32
$ api = OpenFeatureAPI::getInstance ();
33
+ $ api ->clearHooks ();
18
34
19
35
// When
20
36
OpenTelemetryHook::register ();
You can’t perform that action at this time.
0 commit comments