Skip to content

Commit 02346fe

Browse files
committed
Add DBAL version check to compiler pass
1 parent 6485a3e commit 02346fe

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/DependencyInjection/Compiler/DbalTracingPass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Sentry\SentryBundle\DependencyInjection\Compiler;
66

7+
use Doctrine\DBAL\Driver;
78
use Doctrine\DBAL\Driver\ResultStatement;
89
use Sentry\SentryBundle\Tracing\Doctrine\DBAL\ConnectionConfigurator;
910
use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverMiddleware;
@@ -39,6 +40,10 @@ public function process(ContainerBuilder $container): void
3940
return;
4041
}
4142

43+
if (!interface_exists(Driver::class)) {
44+
throw new \InvalidArgumentException(sprintf('The Doctrine "%s" interface is missing, DBAL connection cannot be instrumented; check that you have DBAL 2.13+ installed', Driver::class));
45+
}
46+
4247
/** @var string[] $connectionsToTrace */
4348
$connectionsToTrace = $container->getParameter('sentry.tracing.dbal.connections');
4449

tests/DependencyInjection/Compiler/DbalTracingPassTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ public function testProcessWithDoctrineDBALVersionLowerThan30(): void
103103
$this->assertNull($connection2->getConfigurator());
104104
}
105105

106+
public function testProcessWithDoctrineDBALVersionLowerThan213OrMissing(): void
107+
{
108+
if (self::isDoctrineDBALInstalled()) {
109+
$this->markTestSkipped('This test requires the version of the "doctrine/dbal" Composer package to be < 2.13 or missing.');
110+
}
111+
112+
$container = $this->createContainerBuilder();
113+
$container->setParameter('sentry.tracing.dbal.connections', ['foo', 'baz']);
114+
115+
$this->expectException(\RuntimeException::class);
116+
$this->expectExceptionMessage('DBAL connection cannot be instrumented; check that you have DBAL 2.13+ installed');
117+
118+
$container->compile();
119+
}
120+
106121
/**
107122
* @dataProvider processDoesNothingIfConditionsForEnablingTracingAreMissingDataProvider
108123
*/

tests/DoctrineTestCase.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@
55
namespace Sentry\SentryBundle\Tests;
66

77
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
8-
use Doctrine\DBAL\Driver\ResultStatement;
8+
use Doctrine\DBAL\Driver;
9+
use Doctrine\DBAL\Driver\Middleware;
910
use PHPUnit\Framework\TestCase;
1011

1112
abstract class DoctrineTestCase extends TestCase
1213
{
14+
protected static function isDoctrineDBALInstalled(): bool
15+
{
16+
return interface_exists(Driver::class);
17+
}
18+
1319
protected static function isDoctrineDBALVersion3Installed(): bool
1420
{
15-
return !interface_exists(ResultStatement::class);
21+
return interface_exists(Middleware::class);
1622
}
1723

1824
protected static function isDoctrineBundlePackageInstalled(): bool

0 commit comments

Comments
 (0)