|
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; |
@@ -121,6 +122,19 @@ public function testClientGetUri() |
121 | 122 | $this->assertSame($id, $data['params']['id']); |
122 | 123 | } |
123 | 124 |
|
| 125 | + public function testClientCallable() |
| 126 | + { |
| 127 | + $container = $this->getContainer(); |
| 128 | + |
| 129 | + $client = new Client($container); |
| 130 | + |
| 131 | + $id = uniqid(); |
| 132 | + |
| 133 | + $res = $client->request('GET', '/context', callable: fn () => Context::set('request_id', $id)); |
| 134 | + |
| 135 | + $this->assertSame(['request_id' => $id], Json::decode((string) $res->getBody())); |
| 136 | + } |
| 137 | + |
124 | 138 | public function getContainer() |
125 | 139 | { |
126 | 140 | $container = Mockery::mock(Container::class); |
@@ -177,6 +191,7 @@ public function getContainer() |
177 | 191 | Router::get('/', [FooController::class, 'index']); |
178 | 192 | Router::get('/exception', [FooController::class, 'exception']); |
179 | 193 | Router::get('/id', [FooController::class, 'id']); |
| 194 | + Router::get('/context', [FooController::class, 'context']); |
180 | 195 | Router::addRoute(['GET', 'POST'], '/request', [FooController::class, 'request']); |
181 | 196 |
|
182 | 197 | return $container; |
|
0 commit comments