-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Platform from params are not correctly passed to a QueryCacheProfile
#2821
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
Platform from params are not correctly passed to a QueryCacheProfile
#2821
Conversation
…Profile::generateCacheKeys()
Any suggestions for how i fix this? One way could be to remove it from params in detectDatabasePlatform, but that only happens if getPlatform have been called. We could also check for it in the the constructor, or remove it from the passed connection params to generateCacheKeys() And would there be any BC concerns with removing it from params, after we have assign it to $this->platform? |
lib/Doctrine/DBAL/Connection.php
Outdated
@@ -211,6 +211,15 @@ public function __construct(array $params, Driver $driver, Configuration $config | |||
unset($this->_params['pdo']); | |||
} | |||
|
|||
if (isset($params["platform"])) { | |||
if ( ! $params['platform'] instanceof Platforms\AbstractPlatform) { | |||
throw DBALException::invalidPlatformSpecified(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should at least pass in the $params['platform']
and let the exception produce a more detailed message about what was given instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added more detailed exception message if an object is given. If another type is given it fails horrible and the bottom of your coffee mug will go out. Should i try to add support for any type? Or are we ok with that? :D
->with('cacheKey') | ||
->will($this->returnValue(['realKey' => []])); | ||
|
||
$query = 'SELECT * FROM foo WHERE bar = ?'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a simpler SELECT 1
query - remove all unnecessary params/types
$connectionParams = $this->params; | ||
$expectedParams = $connectionParams; | ||
|
||
$connectionParams["platform"] = $this->createMock(AbstractPlatform::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single quotes
@@ -211,6 +211,15 @@ public function __construct(array $params, Driver $driver, Configuration $config | |||
unset($this->_params['pdo']); | |||
} | |||
|
|||
if (isset($params["platform"])) { | |||
if ( ! $params['platform'] instanceof Platforms\AbstractPlatform) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch isn't tested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
->will($this->returnValue($resultCacheDriverMock)); | ||
|
||
$connectionParams = $this->params; | ||
$expectedParams = $connectionParams; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this variable - just rely on $connectionParams
below
|
||
$this->assertInstanceOf( | ||
ArrayStatement::class, | ||
(new Connection($connectionParams, $driver))->executeCacheQuery($query, $params, $types, $queryCacheProfileMock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a message to assertInstanceOf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the assert as it is tested by "testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCacheQuery"
/* @var $driver Driver */ | ||
$driver = $this->createMock(Driver::class); | ||
|
||
$this->assertInstanceOf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self::assertInstanceOf()
@@ -777,6 +778,49 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach | |||
); | |||
} | |||
|
|||
public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecuteCacheQuery() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an @group
annotation to the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark the method as void
Fixed cs issues
…e detailed about what was given.
Can someone give me a hint why Scrutinizer is suddenly throwing up? |
lib/Doctrine/DBAL/DBALException.php
Outdated
@@ -36,13 +37,19 @@ public static function notSupported($method) | |||
} | |||
|
|||
/** | |||
* @return \Doctrine\DBAL\DBALException | |||
* @param $invalidPlatform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be documented as BC break or moved to a new method
lib/Doctrine/DBAL/DBALException.php
Outdated
"\Doctrine\DBAL\Platforms\AbstractPlatform."); | ||
sprintf( | ||
"Given 'platform' option '%s' must be a subtype of '%s'", | ||
get_class($invalidPlatform), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be a non-object
|
||
$connectionParams = $this->params; | ||
|
||
// This is our main expectation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment can be dropped: if there were no expectations, the test would be marked as risky
public function testThrowsExceptionWhenInValidPlatformSpecified(): void | ||
{ | ||
self::expectException(DBALException::class); | ||
self::expectExceptionMessage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needed to be a $this->
call (IIRac, it's an instance method)
*/ | ||
public function testThrowsExceptionWhenInValidPlatformSpecified(): void | ||
{ | ||
self::expectException(DBALException::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needed to be a $this->
call (IIRac, it's an instance method)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the exception expectations right before the method call that raises them
{ | ||
self::expectException(DBALException::class); | ||
self::expectExceptionMessage( | ||
"Given 'platform' option 'stdClass' must be a subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thos should be a test on the exception test itself
Scrutinizer fails on the mocks union types: ignore
…On 24 Aug 2017 11:46 PM, "Kim Hemsø Rasmussen" ***@***.***> wrote:
Can someone give me a hint why Scrutinizer is suddenly throwing up?
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#2821 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAJakNJDWjAYfYQMswRTNhHW4SFmp8E2ks5sbe9CgaJpZM4O-_04>
.
|
…d' to DBALDBALExceptionTest. Added upgrade notice about BC break. Cleanups
…w method to avoid API changes
…w method to avoid API changes
…-query-cache-2.6' into 2.6 Backport #2821
QueryCacheProfile
@kimhemsoe merged and backported, thanks! |
…AL-* issues are from JIRA, not Github
If you pass in the platform from connection params it will be used to generate the cache key, which in most cases is not serializable.
dbal/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php
Line 105 in db1395b
I can create a better test case where it will fail from the serialize() call if needed. But i was lazy, copy pasted one there fitted my case :D