Skip to content

Commit

Permalink
Merge pull request #3521 from doctrine/maintain-platform-in-params
Browse files Browse the repository at this point in the history
Maintain platform parameter in connection params
  • Loading branch information
jwage authored Apr 18, 2019
2 parents 372fe8e + f202e76 commit 9b75cd5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ public function __construct(
}

$this->platform = $params['platform'];
unset($this->params['platform']);
}

// Create default config and event manager if none given
Expand Down Expand Up @@ -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);
Expand Down
51 changes: 51 additions & 0 deletions tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 9b75cd5

Please sign in to comment.