Skip to content

Commit 58ec963

Browse files
authored
fix: Implement createDatabasePlatformForVersion() method in TracingDriverForV32 class (#731)
1 parent 707212c commit 58ec963

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/Tracing/Doctrine/DBAL/TracingDriverForV32.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,20 @@ public function getExceptionConverter(): ExceptionConverter
8686
{
8787
return $this->decoratedDriver->getExceptionConverter();
8888
}
89+
90+
/**
91+
* {@inheritdoc}
92+
*
93+
* @phpstan-param string $version
94+
*
95+
* @phpstan-return AbstractPlatform
96+
*/
97+
public function createDatabasePlatformForVersion($version): AbstractPlatform
98+
{
99+
if (method_exists($this->decoratedDriver, 'createDatabasePlatformForVersion')) {
100+
return $this->decoratedDriver->createDatabasePlatformForVersion($version);
101+
}
102+
103+
return $this->getDatabasePlatform();
104+
}
89105
}

tests/Tracing/Doctrine/DBAL/TracingDriverForV32Test.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,40 @@ public function testGetExceptionConverter(): void
109109

110110
$this->assertSame($exceptionConverter, $driver->getExceptionConverter());
111111
}
112+
113+
public function testCreateDatabasePlatform(): void
114+
{
115+
$databasePlatform = $this->createMock(AbstractPlatform::class);
116+
117+
$decoratedDriver = $this->createMock(DriverInterface::class);
118+
$decoratedDriver->expects($this->once())
119+
->method('getDatabasePlatform')
120+
->willReturn($databasePlatform);
121+
122+
$driver = new TracingDriverForV32($this->connectionFactory, $decoratedDriver);
123+
124+
$this->assertSame($databasePlatform, $driver->createDatabasePlatformForVersion('5.7'));
125+
}
126+
127+
public function testCreateDatabasePlatformForVersionWhenDriverDefinedCreateDatabasePlatformForVersion(): void
128+
{
129+
$databasePlatform = $this->createMock(AbstractPlatform::class);
130+
131+
$decoratedDriver = $this->createMock(StubCreateDatabasePlatformForVersionDriver::class);
132+
$decoratedDriver->expects($this->once())
133+
->method('createDatabasePlatformForVersion')
134+
->with('5.7')
135+
->willReturn($databasePlatform);
136+
137+
$driver = new TracingDriverForV32($this->connectionFactory, $decoratedDriver);
138+
139+
$this->assertSame($databasePlatform, $driver->createDatabasePlatformForVersion('5.7'));
140+
}
141+
}
142+
143+
if (interface_exists(DriverInterface::class)) {
144+
interface StubCreateDatabasePlatformForVersionDriver extends DriverInterface
145+
{
146+
public function createDatabasePlatformForVersion(string $version): AbstractPlatform;
147+
}
112148
}

0 commit comments

Comments
 (0)