Skip to content

Commit f18be32

Browse files
committed
Test with RuntimeException as well
1 parent 2a3e038 commit f18be32

File tree

1 file changed

+79
-2
lines changed

1 file changed

+79
-2
lines changed

tests/Unit/Adapter/BlackfireOnRequestAdapterTest.php

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Blackfire\Client;
88
use Blackfire\Exception\LogicException;
9+
use Blackfire\Exception\RuntimeException;
910
use Blackfire\Probe;
1011
use Blackfire\Profile\Configuration;
1112
use Chubbyphp\Mock\MockMethod\WithCallback;
@@ -121,7 +122,7 @@ public function testInvokeWithConfigAndWithLogger(): void
121122
}
122123

123124
#[DoesNotPerformAssertions]
124-
public function testInvokeWithExceptionOnCreateProbe(): void
125+
public function testInvokeWithLogicExceptionOnCreateProbe(): void
125126
{
126127
$builder = new MockObjectBuilder();
127128

@@ -157,7 +158,43 @@ public function testInvokeWithExceptionOnCreateProbe(): void
157158
}
158159

159160
#[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
161198
{
162199
$builder = new MockObjectBuilder();
163200

@@ -195,4 +232,44 @@ public function testInvokeWithExceptionOnProbeEnd(): void
195232
$adapter = new BlackfireOnRequestAdapter($onRequest, $client, $config, $logger);
196233
$adapter($swooleRequest, $swooleResponse);
197234
}
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+
}
198275
}

0 commit comments

Comments
 (0)