33namespace Overtrue \LaravelOpenTelemetry \Tests \Hooks \Illuminate \Http ;
44
55use Mockery ;
6- use OpenTelemetry \API \Instrumentation \CachedInstrumentation ;
76use Overtrue \LaravelOpenTelemetry \Facades \Measure ;
87use Overtrue \LaravelOpenTelemetry \Hooks \Illuminate \Http \Kernel ;
98use Overtrue \LaravelOpenTelemetry \Tests \TestCase ;
@@ -25,9 +24,8 @@ public function test_adds_trace_id_to_response_header()
2524 $ expectedTraceId = '12345678901234567890123456789012 ' ;
2625 Measure::shouldReceive ('traceId ' )->andReturn ($ expectedTraceId );
2726
28- // Create hook
29- $ instrumentation = new CachedInstrumentation ('test ' );
30- $ hook = Kernel::hook ($ instrumentation );
27+ // Create hook - 在测试环境中直接实例化而不是通过 hook() 方法
28+ $ hook = new Kernel ();
3129
3230 // Create response
3331 $ response = new Response ;
@@ -49,9 +47,8 @@ public function test_does_not_add_header_when_config_is_null()
4947 // Set configuration to null
5048 config (['otel.response_trace_header_name ' => null ]);
5149
52- // Create hook
53- $ instrumentation = new CachedInstrumentation ('test ' );
54- $ hook = Kernel::hook ($ instrumentation );
50+ // Create hook - 在测试环境中直接实例化
51+ $ hook = new Kernel ();
5552
5653 // Create response
5754 $ response = new Response ;
@@ -73,9 +70,8 @@ public function test_does_not_add_header_when_config_is_empty()
7370 // Set configuration to empty string
7471 config (['otel.response_trace_header_name ' => '' ]);
7572
76- // Create hook
77- $ instrumentation = new CachedInstrumentation ('test ' );
78- $ hook = Kernel::hook ($ instrumentation );
73+ // Create hook - 在测试环境中直接实例化
74+ $ hook = new Kernel ();
7975
8076 // Create response
8177 $ response = new Response ;
@@ -100,9 +96,8 @@ public function test_does_not_add_header_when_trace_id_is_empty()
10096 // Mock empty trace ID
10197 Measure::shouldReceive ('traceId ' )->andReturn ('' );
10298
103- // Create hook
104- $ instrumentation = new CachedInstrumentation ('test ' );
105- $ hook = Kernel::hook ($ instrumentation );
99+ // Create hook - 在测试环境中直接实例化
100+ $ hook = new Kernel ();
106101
107102 // Create response
108103 $ response = new Response ;
@@ -128,9 +123,8 @@ public function test_does_not_add_header_when_trace_id_is_all_zeros()
128123 $ allZerosTraceId = '00000000000000000000000000000000 ' ;
129124 Measure::shouldReceive ('traceId ' )->andReturn ($ allZerosTraceId );
130125
131- // Create hook
132- $ instrumentation = new CachedInstrumentation ('test ' );
133- $ hook = Kernel::hook ($ instrumentation );
126+ // Create hook - 在测试环境中直接实例化
127+ $ hook = new Kernel ();
134128
135129 // Create response
136130 $ response = new Response ;
@@ -155,9 +149,8 @@ public function test_handles_exception_gracefully()
155149 // Mock Measure::traceId() to throw exception
156150 Measure::shouldReceive ('traceId ' )->andThrow (new \Exception ('Test exception ' ));
157151
158- // Create hook
159- $ instrumentation = new CachedInstrumentation ('test ' );
160- $ hook = Kernel::hook ($ instrumentation );
152+ // Create hook - 在测试环境中直接实例化
153+ $ hook = new Kernel ();
161154
162155 // Create response
163156 $ response = new Response ;
@@ -183,9 +176,8 @@ public function test_uses_custom_header_name()
183176 $ expectedTraceId = '98765432109876543210987654321098 ' ;
184177 Measure::shouldReceive ('traceId ' )->andReturn ($ expectedTraceId );
185178
186- // Create hook
187- $ instrumentation = new CachedInstrumentation ('test ' );
188- $ hook = Kernel::hook ($ instrumentation );
179+ // Create hook - 在测试环境中直接实例化
180+ $ hook = new Kernel ();
189181
190182 // Create response
191183 $ response = new Response ;
0 commit comments