Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
367b731d
Unverified
Commit
367b731d
authored
Aug 28, 2017
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix/#2821-verify-that-platform-params-are-passed-to-the-query-cache-2.6' into 2.6
Backport #2821
parents
324f3ac2
45c022d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
14 deletions
+122
-14
Connection.php
lib/Doctrine/DBAL/Connection.php
+13
-10
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+26
-4
ConnectionTest.php
tests/Doctrine/Tests/DBAL/ConnectionTest.php
+57
-0
DBALExceptionTest.php
tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
+26
-0
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
367b731d
...
...
@@ -211,6 +211,15 @@ class Connection implements DriverConnection
unset
(
$this
->
_params
[
'pdo'
]);
}
if
(
isset
(
$params
[
"platform"
]))
{
if
(
!
$params
[
'platform'
]
instanceof
Platforms\AbstractPlatform
)
{
throw
DBALException
::
invalidPlatformType
(
$params
[
'platform'
]);
}
$this
->
platform
=
$params
[
"platform"
];
unset
(
$this
->
_params
[
"platform"
]);
}
// Create default config and event manager if none given
if
(
!
$config
)
{
$config
=
new
Configuration
();
...
...
@@ -384,18 +393,12 @@ class Connection implements DriverConnection
*/
private
function
detectDatabasePlatform
()
{
if
(
!
isset
(
$this
->
_params
[
'platform'
]))
{
$version
=
$this
->
getDatabasePlatformVersion
();
$version
=
$this
->
getDatabasePlatformVersion
();
if
(
null
!==
$version
)
{
$this
->
platform
=
$this
->
_driver
->
createDatabasePlatformForVersion
(
$version
);
}
else
{
$this
->
platform
=
$this
->
_driver
->
getDatabasePlatform
();
}
}
elseif
(
$this
->
_params
[
'platform'
]
instanceof
Platforms\AbstractPlatform
)
{
$this
->
platform
=
$this
->
_params
[
'platform'
];
if
(
null
!==
$version
)
{
$this
->
platform
=
$this
->
_driver
->
createDatabasePlatformForVersion
(
$version
);
}
else
{
throw
DBALException
::
invalidPlatformSpecified
();
$this
->
platform
=
$this
->
_driver
->
getDatabasePlatform
();
}
$this
->
platform
->
setEventManager
(
$this
->
_eventManager
);
...
...
lib/Doctrine/DBAL/DBALException.php
View file @
367b731d
...
...
@@ -22,6 +22,7 @@ namespace Doctrine\DBAL;
use
Doctrine\DBAL\Exception
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
class
DBALException
extends
\Exception
{
...
...
@@ -35,16 +36,37 @@ class DBALException extends \Exception
return
new
self
(
"Operation '
$method
' is not supported by platform."
);
}
/**
* @return \Doctrine\DBAL\DBALException
*/
public
static
function
invalidPlatformSpecified
()
public
static
function
invalidPlatformSpecified
()
:
self
{
return
new
self
(
"Invalid 'platform' option specified, need to give an instance of "
.
"\Doctrine\DBAL\Platforms\AbstractPlatform."
);
}
/**
* @param mixed $invalidPlatform
*/
public
static
function
invalidPlatformType
(
$invalidPlatform
)
:
self
{
if
(
\is_object
(
$invalidPlatform
))
{
return
new
self
(
sprintf
(
"Option 'platform' must be a subtype of '%s', instance of '%s' given"
,
AbstractPlatform
::
class
,
\get_class
(
$invalidPlatform
)
)
);
}
return
new
self
(
sprintf
(
"Option 'platform' must be an object and subtype of '%s'. Got '%s'"
,
AbstractPlatform
::
class
,
\gettype
(
$invalidPlatform
)
)
);
}
/**
* Returns a new instance for an invalid specified platform version.
*
...
...
tests/Doctrine/Tests/DBAL/ConnectionTest.php
View file @
367b731d
...
...
@@ -7,8 +7,10 @@ use Doctrine\Common\EventManager;
use
Doctrine\DBAL\Cache\QueryCacheProfile
;
use
Doctrine\DBAL\Configuration
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Events
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\Tests\Mocks\DriverConnectionMock
;
use
Doctrine\Tests\Mocks\DriverMock
;
use
Doctrine\DBAL\Cache\ArrayStatement
;
...
...
@@ -777,6 +779,61 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
);
}
/**
* @group DBAL-2821
*/
public
function
testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecuteCacheQuery
()
:
void
{
$resultCacheDriverMock
=
$this
->
createMock
(
Cache
::
class
);
$resultCacheDriverMock
->
expects
(
$this
->
atLeastOnce
())
->
method
(
'fetch'
)
->
with
(
'cacheKey'
)
->
will
(
$this
->
returnValue
([
'realKey'
=>
[]]));
/* @var $queryCacheProfileMock QueryCacheProfile|\PHPUnit_Framework_MockObject_MockObject */
$queryCacheProfileMock
=
$this
->
createMock
(
QueryCacheProfile
::
class
);
$queryCacheProfileMock
->
expects
(
$this
->
any
())
->
method
(
'getResultCacheDriver'
)
->
will
(
$this
->
returnValue
(
$resultCacheDriverMock
));
$query
=
'SELECT 1'
;
$connectionParams
=
$this
->
params
;
$queryCacheProfileMock
->
expects
(
$this
->
once
())
->
method
(
'generateCacheKeys'
)
->
with
(
$query
,
[],
[],
$connectionParams
)
->
will
(
$this
->
returnValue
([
'cacheKey'
,
'realKey'
]));
$connectionParams
[
'platform'
]
=
$this
->
createMock
(
AbstractPlatform
::
class
);
/* @var $driver Driver */
$driver
=
$this
->
createMock
(
Driver
::
class
);
(
new
Connection
(
$connectionParams
,
$driver
))
->
executeCacheQuery
(
$query
,
[],
[],
$queryCacheProfileMock
);
}
/**
* @group DBAL-2821
*/
public
function
testThrowsExceptionWhenInValidPlatformSpecified
()
:
void
{
$connectionParams
=
$this
->
params
;
$connectionParams
[
'platform'
]
=
new
\stdClass
();
/* @var $driver Driver */
$driver
=
$this
->
createMock
(
Driver
::
class
);
$this
->
expectException
(
DBALException
::
class
);
new
Connection
(
$connectionParams
,
$driver
);
}
/**
* @group DBAL-990
*/
...
...
tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
View file @
367b731d
...
...
@@ -58,4 +58,30 @@ class DBALExceptionTest extends DbalTestCase
$exception
->
getMessage
()
);
}
/**
* @group DBAL-2821
*/
public
function
testInvalidPlatformTypeObject
()
:
void
{
$exception
=
DBALException
::
invalidPlatformType
(
new
\stdClass
());
self
::
assertSame
(
"Option 'platform' must be a subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform', instance of 'stdClass' given"
,
$exception
->
getMessage
()
);
}
/**
* @group DBAL-2821
*/
public
function
testInvalidPlatformTypeScalar
()
:
void
{
$exception
=
DBALException
::
invalidPlatformType
(
'some string'
);
self
::
assertSame
(
"Option 'platform' must be an object and subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform'. Got 'string'"
,
$exception
->
getMessage
()
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment