|
10 | 10 | use Doctrine\DBAL\ParameterType;
|
11 | 11 | use PHPUnit\Framework\MockObject\MockObject;
|
12 | 12 | use Sentry\SentryBundle\Tests\DoctrineTestCase;
|
| 13 | +use Sentry\SentryBundle\Tests\Tracing\Doctrine\DBAL\Fixture\NativeDriverConnectionInterfaceStub; |
13 | 14 | use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnection;
|
| 15 | +use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionInterface; |
14 | 16 | use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingStatement;
|
15 | 17 | use Sentry\State\HubInterface;
|
16 | 18 | use Sentry\Tracing\Transaction;
|
@@ -417,6 +419,32 @@ public function testGetWrappedConnection(): void
|
417 | 419 | $this->assertSame($this->decoratedConnection, $connection->getWrappedConnection());
|
418 | 420 | }
|
419 | 421 |
|
| 422 | + public function testGetNativeConnection(): void |
| 423 | + { |
| 424 | + $nativeConnection = new class() { |
| 425 | + }; |
| 426 | + |
| 427 | + $decoratedConnection = $this->createMock(NativeDriverConnectionInterfaceStub::class); |
| 428 | + $decoratedConnection->expects($this->once()) |
| 429 | + ->method('getNativeConnection') |
| 430 | + ->willReturn($nativeConnection); |
| 431 | + |
| 432 | + $connection = new TracingDriverConnection($this->hub, $decoratedConnection, 'foo_platform', []); |
| 433 | + |
| 434 | + $this->assertSame($nativeConnection, $connection->getNativeConnection()); |
| 435 | + } |
| 436 | + |
| 437 | + public function testGetNativeConnectionThrowsExceptionIfDecoratedConnectionDoesNotImplementMethod(): void |
| 438 | + { |
| 439 | + $decoratedConnection = $this->createMock(TracingDriverConnectionInterface::class); |
| 440 | + $connection = new TracingDriverConnection($this->hub, $decoratedConnection, 'foo_platform', []); |
| 441 | + |
| 442 | + $this->expectException(\BadMethodCallException::class); |
| 443 | + $this->expectExceptionMessageMatches('/The connection ".*?" does not support accessing the native connection\./'); |
| 444 | + |
| 445 | + $connection->getNativeConnection(); |
| 446 | + } |
| 447 | + |
420 | 448 | /**
|
421 | 449 | * @return \Generator<mixed>
|
422 | 450 | */
|
|
0 commit comments