|
14 | 14 | use Hyperf\Codec\Json; |
15 | 15 | use Hyperf\Config\Config; |
16 | 16 | use Hyperf\Context\ApplicationContext; |
| 17 | +use Hyperf\Context\Context; |
17 | 18 | use Hyperf\Contract\ConfigInterface; |
18 | 19 | use Hyperf\Contract\NormalizerInterface; |
19 | 20 | use Hyperf\Coroutine\Coroutine; |
@@ -119,6 +120,19 @@ public function testClientGetUri() |
119 | 120 | $this->assertSame($id, $data['params']['id']); |
120 | 121 | } |
121 | 122 |
|
| 123 | + public function testClientCallable() |
| 124 | + { |
| 125 | + $container = $this->getContainer(); |
| 126 | + |
| 127 | + $client = new Client($container); |
| 128 | + |
| 129 | + $id = uniqid(); |
| 130 | + |
| 131 | + $res = $client->request('GET', '/context', callable: fn () => Context::set('request_id', $id)); |
| 132 | + |
| 133 | + $this->assertSame(['request_id' => $id], Json::decode((string) $res->getBody())); |
| 134 | + } |
| 135 | + |
122 | 136 | public function getContainer() |
123 | 137 | { |
124 | 138 | $container = Mockery::mock(Container::class); |
@@ -175,6 +189,7 @@ public function getContainer() |
175 | 189 | Router::get('/', [FooController::class, 'index']); |
176 | 190 | Router::get('/exception', [FooController::class, 'exception']); |
177 | 191 | Router::get('/id', [FooController::class, 'id']); |
| 192 | + Router::get('/context', [FooController::class, 'context']); |
178 | 193 | Router::addRoute(['GET', 'POST'], '/request', [FooController::class, 'request']); |
179 | 194 |
|
180 | 195 | return $container; |
|
0 commit comments