Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 62ef303

Browse files
committed
feat: frankenphp
1 parent 8db1c4a commit 62ef303

File tree

3 files changed

+58
-53
lines changed

3 files changed

+58
-53
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
name: Test
22

33
on:
4-
push:
5-
branches: [main]
6-
pull_request:
7-
branches: [main]
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
88

99
jobs:
10-
phpcs:
11-
runs-on: ubuntu-latest
12-
steps:
13-
- uses: actions/checkout@v2
14-
- name: Setup PHP environment
15-
uses: shivammathur/setup-php@v2
16-
- name: Install dependencies
17-
run: composer install --ignore-platform-reqs
18-
- name: PHPCSFixer check
19-
run: composer check-style
20-
phpunit:
21-
strategy:
22-
matrix:
23-
php_version: [8.4]
24-
runs-on: ubuntu-latest
25-
steps:
26-
- uses: actions/checkout@v2
27-
- name: Setup PHP environment
28-
uses: shivammathur/setup-php@v2
29-
with:
30-
php-version: ${{ matrix.php_version }}
31-
coverage: xdebug
32-
- name: Install dependencies
33-
run: composer install --ignore-platform-reqs
34-
- name: PHPUnit check
35-
run: ./vendor/bin/phpunit --coverage-text
10+
phpcs:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Setup PHP environment
15+
uses: shivammathur/setup-php@v2
16+
- name: Install dependencies
17+
run: composer install --ignore-platform-reqs
18+
- name: PHPCSFixer check
19+
run: composer check-style
20+
phpunit:
21+
strategy:
22+
matrix:
23+
php_version: [8.4]
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Setup PHP environment
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: ${{ matrix.php_version }}
31+
coverage: xdebug
32+
extensions: opentelemetry
33+
- name: Install dependencies
34+
run: composer install --ignore-platform-reqs
35+
- name: PHPUnit check
36+
run: ./vendor/bin/phpunit --coverage-text

tests/Hooks/Illuminate/Http/KernelTest.php

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Overtrue\LaravelOpenTelemetry\Tests\Hooks\Illuminate\Http;
44

55
use Mockery;
6-
use OpenTelemetry\API\Instrumentation\CachedInstrumentation;
76
use Overtrue\LaravelOpenTelemetry\Facades\Measure;
87
use Overtrue\LaravelOpenTelemetry\Hooks\Illuminate\Http\Kernel;
98
use 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;

tests/TestCase.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
namespace Overtrue\LaravelOpenTelemetry\Tests;
44

5+
use Orchestra\Testbench\TestCase as OrchestraTestCase;
56
use Overtrue\LaravelOpenTelemetry\OpenTelemetryServiceProvider;
67

7-
abstract class TestCase extends \Orchestra\Testbench\TestCase
8+
abstract class TestCase extends OrchestraTestCase
89
{
10+
protected function setUp(): void
11+
{
12+
parent::setUp();
13+
}
14+
915
protected function getPackageProviders($app): array
1016
{
1117
return [
@@ -49,4 +55,10 @@ protected function defineEnvironment($app)
4955
{
5056
$app['config']->set('otel.enabled', true);
5157
}
58+
59+
protected function getEnvironmentSetUp($app): void
60+
{
61+
// Setup the application environment for testing
62+
config()->set('database.default', 'testing');
63+
}
5264
}

0 commit comments

Comments
 (0)