8000 Platform from params are not correctly passed to a `QueryCacheProfile` by kimhemsoe · Pull Request #2821 · doctrine/dbal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged

Conversation

kimhemsoe
Copy link
Member
@kimhemsoe kimhemsoe commented Aug 22, 2017

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.

'&connectionParams=' . serialize($connectionParams);

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

@kimhemsoe
Copy link
Member Author
kimhemsoe commented Aug 22, 2017

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?

@@ -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();
Copy link
Member

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.

Copy link
Member Author

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 = ?';
Copy link
Member

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);
Copy link
Member

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) {
Copy link
Member

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

Copy link
Member Author

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;
Copy link
Member

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)
Copy link
Member

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

Copy link
Member Author

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(
Copy link
Member

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()
Copy link
Member

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

Copy link
Member

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

@kimhemsoe
Copy link
Member Author

Can someone give me a hint why Scrutinizer is suddenly throwing up?

@@ -36,13 +37,19 @@ public static function notSupported($method)
}

/**
* @return \Doctrine\DBAL\DBALException
* @param $invalidPlatform
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixed

Copy link
Member

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

"\Doctrine\DBAL\Platforms\AbstractPlatform.");
sprintf(
"Given 'platform' option '%s' must be a subtype of '%s'",
get_class($invalidPlatform),
Copy link
Member

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
Copy link
Member

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(
Copy link
Member

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);
Copy link
Member

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)

Copy link
Member

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'"
Copy link
Member

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

@Ocramius
Copy link
Member
Ocramius commented Aug 25, 2017 via email

…d' to DBALDBALExceptionTest.

Added upgrade notice about BC break.
Cleanups
@Ocramius Ocramius assigned Ocramius and unassigned kimhemsoe Aug 28, 2017
@Ocramius Ocramius removed the BC Break label Aug 28, 2017
@Ocramius Ocramius merged commit 2d57c68 into doctrine:master Aug 28, 2017
@Ocramius Ocramius added this to the 2.6.2 milestone Aug 28, 2017
Ocramius added a commit that referenced this pull request Aug 28, 2017
Ocramius added a commit that referenced this pull request Aug 28, 2017
Ocramius added a commit that referenced this pull request Aug 28, 2017
Ocramius added a commit that referenced this pull request Aug 28, 2017
@Ocramius Ocramius changed the title Added failure test where platform from params is passed to QueryCache… Platform from params are not correctly passed to a QueryCacheProfile Aug 28, 2017
@Ocramius
Copy link
Member

@kimhemsoe merged and backported, thanks!

master: ce7560f
2.6: 367b731

Ocramius added a commit that referenced this pull request Aug 28, 2017
…AL-* issues are from JIRA, not Github
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0