Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain platform parameter in connection params #3521

Merged
merged 1 commit into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}