|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Sentry\SentryBundle\Tests\Tracing\Doctrine\DBAL; |
| 6 | + |
| 7 | +use Doctrine\DBAL\Connection; |
| 8 | +use Doctrine\DBAL\Driver\API\ExceptionConverter; |
| 9 | +use Doctrine\DBAL\Driver as DriverInterface; |
| 10 | +use Doctrine\DBAL\Driver\Connection as DriverConnectionInterface; |
| 11 | +use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 12 | +use Doctrine\DBAL\Schema\AbstractSchemaManager; |
| 13 | +use PHPUnit\Framework\MockObject\MockObject; |
| 14 | +use Sentry\SentryBundle\Tests\DoctrineTestCase; |
| 15 | +use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionFactoryInterface; |
| 16 | +use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverConnectionInterface; |
| 17 | +use Sentry\SentryBundle\Tracing\Doctrine\DBAL\TracingDriverForV32; |
| 18 | + |
| 19 | +final class TracingDriverForV32Test extends DoctrineTestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var MockObject&TracingDriverConnectionFactoryInterface |
| 23 | + */ |
| 24 | + private $connectionFactory; |
| 25 | + |
| 26 | + public static function setUpBeforeClass(): void |
| 27 | + { |
| 28 | + if (!self::isDoctrineDBALVersion32Installed()) { |
| 29 | + self::markTestSkipped('This test requires the version of the "doctrine/dbal" Composer package to be >= 3.2.'); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + protected function setUp(): void |
| 34 | + { |
| 35 | + $this->connectionFactory = $this->createMock(TracingDriverConnectionFactoryInterface::class); |
| 36 | + } |
| 37 | + |
| 38 | + public function testConnect(): void |
| 39 | + { |
| 40 | + $params = ['host' => 'localhost']; |
| 41 | + $databasePlatform = $this->createMock(AbstractPlatform::class); |
| 42 | + $driverConnection = $this->createMock(DriverConnectionInterface::class); |
| 43 | + $tracingDriverConnection = $this->createMock(TracingDriverConnectionInterface::class); |
| 44 | + $decoratedDriver = $this->createMock(DriverInterface::class); |
| 45 | + |
| 46 | + $decoratedDriver->expects($this->once()) |
| 47 | + ->method('connect') |
| 48 | + ->with($params) |
| 49 | + ->willReturn($driverConnection); |
| 50 | + |
| 51 | + $decoratedDriver->expects($this->once()) |
| 52 | + ->method('getDatabasePlatform') |
| 53 | + ->willReturn($databasePlatform); |
| 54 | + |
| 55 | + $this->connectionFactory->expects($this->once()) |
| 56 | + ->method('create') |
| 57 | + ->with($driverConnection, $databasePlatform, $params) |
| 58 | + ->willReturn($tracingDriverConnection); |
| 59 | + |
| 60 | + $driver = new TracingDriverForV32($this->connectionFactory, $decoratedDriver); |
| 61 | + |
| 62 | + $this->assertSame($tracingDriverConnection, $driver->connect($params)); |
| 63 | + } |
| 64 | + |
| 65 | + public function testGetDatabasePlatform(): void |
| 66 | + { |
| 67 | + $databasePlatform = $this->createMock(AbstractPlatform::class); |
| 68 | + |
| 69 | + $decoratedDriver = $this->createMock(DriverInterface::class); |
| 70 | + $decoratedDriver->expects($this->once()) |
| 71 | + ->method('getDatabasePlatform') |
| 72 | + ->willReturn($databasePlatform); |
| 73 | + |
| 74 | + $driver = new TracingDriverForV32($this->connectionFactory, $decoratedDriver); |
| 75 | + |
| 76 | + $this->assertSame($databasePlatform, $driver->getDatabasePlatform()); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @group legacy |
| 81 | + */ |
| 82 | + public function testGetSchemaManager(): void |
| 83 | + { |
| 84 | + $connection = $this->createMock(Connection::class); |
| 85 | + $databasePlatform = $this->createMock(AbstractPlatform::class); |
| 86 | + $schemaManager = $this->createMock(AbstractSchemaManager::class); |
| 87 | + |
| 88 | + $decoratedDriver = $this->createMock(DriverInterface::class); |
| 89 | + $decoratedDriver->expects($this->once()) |
| 90 | + ->method('getSchemaManager') |
| 91 | + ->with($connection, $databasePlatform) |
| 92 | + ->willReturn($schemaManager); |
| 93 | + |
| 94 | + $driver = new TracingDriverForV32($this->connectionFactory, $decoratedDriver); |
| 95 | + |
| 96 | + $this->assertSame($schemaManager, $driver->getSchemaManager($connection, $databasePlatform)); |
| 97 | + } |
| 98 | + |
| 99 | + public function testGetExceptionConverter(): void |
| 100 | + { |
| 101 | + $exceptionConverter = $this->createMock(ExceptionConverter::class); |
| 102 | + |
| 103 | + $decoratedDriver = $this->createMock(DriverInterface::class); |
| 104 | + $decoratedDriver->expects($this->once()) |
| 105 | + ->method('getExceptionConverter') |
| 106 | + ->willReturn($exceptionConverter); |
| 107 | + |
| 108 | + $driver = new TracingDriverForV32($this->connectionFactory, $decoratedDriver); |
| 109 | + |
| 110 | + $this->assertSame($exceptionConverter, $driver->getExceptionConverter()); |
| 111 | + } |
| 112 | +} |
0 commit comments