From 9cb17d29150f0444e5f7efd43c4813c4b3264d6e Mon Sep 17 00:00:00 2001 From: Vladislav Veselinov Date: Tue, 10 Jun 2014 18:53:19 +0300 Subject: [PATCH 1/4] 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 From 79bf84e1ad33fc1bf1c1cb6d64ccc1fc348ed3be Mon Sep 17 00:00:00 2001 From: Vladislav Veselinov Date: Tue, 10 Jun 2014 19:21:35 +0300 Subject: [PATCH 2/4] revert typehint change --- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 3c6daaaad..80015a0a6 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\EntityManagerInterface; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\ParameterTypeInferer; @@ -37,7 +37,7 @@ abstract class SQLFilter /** * The entity manager. * - * @var EntityManagerInterface + * @var EntityManager */ private $em; @@ -51,9 +51,9 @@ abstract class SQLFilter /** * Constructs the SQLFilter object. * - * @param EntityManagerInterface $em The entity manager. + * @param EntityManager $em The entity manager. */ - final public function __construct(EntityManagerInterface $em) + final public function __construct(EntityManager $em) { $this->em = $em; } From 759836113fc36816a81261f2cc9423adb6fe334c Mon Sep 17 00:00:00 2001 From: Vladislav Veselinov Date: Fri, 8 Aug 2014 16:44:08 +0300 Subject: [PATCH 3/4] assertion fix --- tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 2479cd283..946fc45fb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -258,7 +258,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $reflMethod = new \ReflectionMethod('Doctrine\ORM\Query\Filter\SQLFilter', 'getConnection'); $reflMethod->setAccessible(true); - $this->assertTrue($reflMethod->invoke($filter) === $conn); + $this->assertSame($conn, $reflMethod->invoke($filter)); } public function testSQLFilterSetParameterInfersType() From ef5a3f1bb783a6e6b498d9d62a06de59a30350ea Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 13 Jan 2015 02:06:39 +0100 Subject: [PATCH 4/4] #1054 DDC-3161 - adding `@group` annotation for newly introduced tests --- tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 946fc45fb..eddbc4c42 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -243,6 +243,10 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals("'en'", $filter->getParameter('locale')); } + /** + * @group DDC-3161 + * @group 1054 + */ public function testSQLFilterGetConnection() { // Setup mock connection