Skip to content

Commit

Permalink
Merge pull request #5981 from jdelaune/3.6.x
Browse files Browse the repository at this point in the history
For PrimaryReadReplicaConnection passthrough primary server version
  • Loading branch information
derrabus committed Apr 14, 2023
2 parents f687df2 + a209b17 commit b4bd1cf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ private function getDatabasePlatformVersion()
return $this->params['serverVersion'];
}

if (isset($this->params['primary']) && isset($this->params['primary']['serverVersion'])) {
return $this->params['primary']['serverVersion'];
}

// If not connected, we need to connect now to determine the platform version.
if ($this->_conn === null) {
try {
Expand Down
1 change: 1 addition & 0 deletions src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* persistent?: bool,
* platform?: Platforms\AbstractPlatform,
* port?: int,
* serverVersion?: string,
* url?: string,
* user?: string,
* unix_socket?: string,
Expand Down
44 changes: 44 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,50 @@ public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform(): vo
self::assertSame($platformMock, $connection->getDatabasePlatform());
}

public function testPlatformDetectionFetchedFromParameters(): void
{
$driverMock = $this->createMock(VersionAwarePlatformDriver::class);

$driverConnectionMock = $this->createMock(ServerInfoAwareConnection::class);

$platformMock = $this->getMockForAbstractClass(AbstractPlatform::class);

$connection = new Connection(['serverVersion' => '8.0'], $driverMock);

$driverMock->expects(self::never())
->method('connect')
->willReturn($driverConnectionMock);

$driverMock->expects(self::once())
->method('createDatabasePlatformForVersion')
->with('8.0')
->willReturn($platformMock);

self::assertSame($platformMock, $connection->getDatabasePlatform());
}

public function testPlatformDetectionFetchedFromPrimaryReplicaParameters(): void
{
$driverMock = $this->createMock(VersionAwarePlatformDriver::class);

$driverConnectionMock = $this->createMock(ServerInfoAwareConnection::class);

$platformMock = $this->getMockForAbstractClass(AbstractPlatform::class);

$connection = new Connection(['primary' => ['serverVersion' => '8.0']], $driverMock);

$driverMock->expects(self::never())
->method('connect')
->willReturn($driverConnectionMock);

$driverMock->expects(self::once())
->method('createDatabasePlatformForVersion')
->with('8.0')
->willReturn($platformMock);

self::assertSame($platformMock, $connection->getDatabasePlatform());
}

public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCacheQuery(): void
{
$cacheItemMock = $this->createMock(CacheItemInterface::class);
Expand Down

0 comments on commit b4bd1cf

Please sign in to comment.