From 9cb17d29150f0444e5f7efd43c4813c4b3264d6e Mon Sep 17 00:00:00 2001 From: Vladislav Veselinov Date: Tue, 10 Jun 2014 18:53:19 +0300 Subject: [PATCH] EntityManagerInterface instead of EntityManager Make connection available in filters Add test for the changes --- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 18 ++++++++++++++---- .../Tests/ORM/Functional/SQLFilterTest.php | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 2fe921b75..3c6daaaad 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -19,7 +19,7 @@ namespace Doctrine\ORM\Query\Filter; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\ParameterTypeInferer; @@ -37,7 +37,7 @@ abstract class SQLFilter /** * The entity manager. * - * @var EntityManager + * @var EntityManagerInterface */ private $em; @@ -51,9 +51,9 @@ abstract class SQLFilter /** * Constructs the SQLFilter object. * - * @param EntityManager $em The entity manager. + * @param EntityManagerInterface $em The entity manager. */ - final public function __construct(EntityManager $em) + final public function __construct(EntityManagerInterface $em) { $this->em = $em; } @@ -133,6 +133,16 @@ abstract class SQLFilter return serialize($this->parameters); } + /** + * Returns the database connection used by the entity manager + * + * @return \Doctrine\DBAL\Connection + */ + final protected function getConnection() + { + return $this->em->getConnection(); + } + /** * Gets the SQL query part to add to a query. * diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 590d5151e..2479cd283 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -243,6 +243,24 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals("'en'", $filter->getParameter('locale')); } + public function testSQLFilterGetConnection() + { + // Setup mock connection + $conn = $this->getMockConnection(); + + $em = $this->getMockEntityManager($conn); + $em->expects($this->once()) + ->method('getConnection') + ->will($this->returnValue($conn)); + + $filter = new MyLocaleFilter($em); + + $reflMethod = new \ReflectionMethod('Doctrine\ORM\Query\Filter\SQLFilter', 'getConnection'); + $reflMethod->setAccessible(true); + + $this->assertTrue($reflMethod->invoke($filter) === $conn); + } + public function testSQLFilterSetParameterInfersType() { // Setup mock connection