|
6 | 6 |
|
7 | 7 | use Blackfire\Client; |
8 | 8 | use Blackfire\Exception\LogicException; |
| 9 | +use Blackfire\Exception\RuntimeException; |
9 | 10 | use Blackfire\Probe; |
10 | 11 | use Blackfire\Profile\Configuration; |
11 | 12 | use Chubbyphp\Mock\MockMethod\WithCallback; |
@@ -121,7 +122,7 @@ public function testInvokeWithConfigAndWithLogger(): void |
121 | 122 | } |
122 | 123 |
|
123 | 124 | #[DoesNotPerformAssertions] |
124 | | - public function testInvokeWithExceptionOnCreateProbe(): void |
| 125 | + public function testInvokeWithLogicExceptionOnCreateProbe(): void |
125 | 126 | { |
126 | 127 | $builder = new MockObjectBuilder(); |
127 | 128 |
|
@@ -157,7 +158,43 @@ public function testInvokeWithExceptionOnCreateProbe(): void |
157 | 158 | } |
158 | 159 |
|
159 | 160 | #[DoesNotPerformAssertions] |
160 | | - public function testInvokeWithExceptionOnProbeEnd(): void |
| 161 | + public function testInvokeWithRuntimeExceptionOnCreateProbe(): void |
| 162 | + { |
| 163 | + $builder = new MockObjectBuilder(); |
| 164 | + |
| 165 | + /** @var SwooleRequest $swooleRequest */ |
| 166 | + $swooleRequest = $builder->create(SwooleRequest::class, []); |
| 167 | + $swooleRequest->header['x-blackfire-query'] = 'swoole'; |
| 168 | + |
| 169 | + /** @var SwooleResponse $swooleResponse */ |
| 170 | + $swooleResponse = $builder->create(SwooleResponse::class, []); |
| 171 | + |
| 172 | + /** @var OnRequestInterface $onRequest */ |
| 173 | + $onRequest = $builder->create(OnRequestInterface::class, [ |
| 174 | + new WithoutReturn('__invoke', [$swooleRequest, $swooleResponse]), |
| 175 | + ]); |
| 176 | + |
| 177 | + /** @var Configuration $config */ |
| 178 | + $config = $builder->create(Configuration::class, []); |
| 179 | + |
| 180 | + $exception = new RuntimeException('Something went wrong'); |
| 181 | + |
| 182 | + /** @var Client $client */ |
| 183 | + $client = $builder->create(Client::class, [ |
| 184 | + new WithException('createProbe', [$config, true], $exception), |
| 185 | + ]); |
| 186 | + |
| 187 | + /** @var LoggerInterface $logger */ |
| 188 | + $logger = $builder->create(LoggerInterface::class, [ |
| 189 | + new WithoutReturn('error', ['Blackfire exception: Something went wrong', []]), |
| 190 | + ]); |
| 191 | + |
| 192 | + $adapter = new BlackfireOnRequestAdapter($onRequest, $client, $config, $logger); |
| 193 | + $adapter($swooleRequest, $swooleResponse); |
| 194 | + } |
| 195 | + |
| 196 | + #[DoesNotPerformAssertions] |
| 197 | + public function testInvokeWithLogicExceptionOnProbeEnd(): void |
161 | 198 | { |
162 | 199 | $builder = new MockObjectBuilder(); |
163 | 200 |
|
@@ -195,4 +232,44 @@ public function testInvokeWithExceptionOnProbeEnd(): void |
195 | 232 | $adapter = new BlackfireOnRequestAdapter($onRequest, $client, $config, $logger); |
196 | 233 | $adapter($swooleRequest, $swooleResponse); |
197 | 234 | } |
| 235 | + |
| 236 | + #[DoesNotPerformAssertions] |
| 237 | + public function testInvokeWithRuntimeExceptionOnProbeEnd(): void |
| 238 | + { |
| 239 | + $builder = new MockObjectBuilder(); |
| 240 | + |
| 241 | + /** @var SwooleRequest $swooleRequest */ |
| 242 | + $swooleRequest = $builder->create(SwooleRequest::class, []); |
| 243 | + $swooleRequest->header['x-blackfire-query'] = 'swoole'; |
| 244 | + |
| 245 | + /** @var SwooleResponse $swooleResponse */ |
| 246 | + $swooleResponse = $builder->create(SwooleResponse::class, []); |
| 247 | + |
| 248 | + /** @var OnRequestInterface $onRequest */ |
| 249 | + $onRequest = $builder->create(OnRequestInterface::class, [ |
| 250 | + new WithoutReturn('__invoke', [$swooleRequest, $swooleResponse]), |
| 251 | + ]); |
| 252 | + |
| 253 | + /** @var Configuration $config */ |
| 254 | + $config = $builder->create(Configuration::class, []); |
| 255 | + |
| 256 | + /** @var Probe $probe */ |
| 257 | + $probe = $builder->create(Probe::class, []); |
| 258 | + |
| 259 | + $exception = new RuntimeException('Something went wrong'); |
| 260 | + |
| 261 | + /** @var Client $client */ |
| 262 | + $client = $builder->create(Client::class, [ |
| 263 | + new WithReturn('createProbe', [$config, true], $probe), |
| 264 | + new WithException('endProbe', [$probe], $exception), |
| 265 | + ]); |
| 266 | + |
| 267 | + /** @var LoggerInterface $logger */ |
| 268 | + $logger = $builder->create(LoggerInterface::class, [ |
| 269 | + new WithoutReturn('error', ['Blackfire exception: Something went wrong', []]), |
| 270 | + ]); |
| 271 | + |
| 272 | + $adapter = new BlackfireOnRequestAdapter($onRequest, $client, $config, $logger); |
| 273 | + $adapter($swooleRequest, $swooleResponse); |
| 274 | + } |
198 | 275 | } |
0 commit comments