diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 75b862bf74f..78bc38023b0 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -200,7 +200,6 @@ public function __construct( } $this->platform = $params['platform']; - unset($this->params['platform']); } // Create default config and event manager if none given @@ -932,7 +931,10 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc throw CacheException::noResultDriverConfigured(); } - [$cacheKey, $realKey] = $qcp->generateCacheKeys($query, $params, $types, $this->getParams()); + $connectionParams = $this->getParams(); + unset($connectionParams['platform']); + + [$cacheKey, $realKey] = $qcp->generateCacheKeys($query, $params, $types, $connectionParams); // fetch the row pointers entry $data = $resultCache->fetch($cacheKey); diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index c036bd89885..3c3bc9f9b50 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -880,4 +880,55 @@ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnecting $connection->getDatabasePlatform(); } + + /** + * @group #3194 + */ + public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGeneratingCacheKeys() : void + { + /** @var Driver|MockObject $driver */ + $driver = $this->createMock(Driver::class); + + /** @var AbstractPlatform|MockObject $platform */ + $platform = $this->createMock(AbstractPlatform::class); + + /** @var QueryCacheProfile|MockObject $queryCacheProfile */ + $queryCacheProfile = $this->createMock(QueryCacheProfile::class); + + /** @var Cache|MockObject $resultCacheDriver */ + $resultCacheDriver = $this->createMock(Cache::class); + + $queryCacheProfile + ->expects($this->any()) + ->method('getResultCacheDriver') + ->will($this->returnValue($resultCacheDriver)); + + $resultCacheDriver + ->expects($this->atLeastOnce()) + ->method('fetch') + ->with('cacheKey') + ->will($this->returnValue(['realKey' => []])); + + $query = 'SELECT 1'; + + $params = [ + 'dbname' => 'foo', + 'platform' => $platform, + ]; + + $paramsWithoutPlatform = $params; + unset($paramsWithoutPlatform['platform']); + + $queryCacheProfile + ->expects($this->once()) + ->method('generateCacheKeys') + ->with($query, [], [], $paramsWithoutPlatform) + ->will($this->returnValue(['cacheKey', 'realKey'])); + + $connection = new Connection($params, $driver); + + self::assertSame($params, $connection->getParams()); + + $connection->executeCacheQuery($query, [], [], $queryCacheProfile); + } }