diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 2fe921b75..80015a0a6 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -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..eddbc4c42 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -243,6 +243,28 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals("'en'", $filter->getParameter('locale')); } + /** + * @group DDC-3161 + * @group 1054 + */ + 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->assertSame($conn, $reflMethod->invoke($filter)); + } + public function testSQLFilterSetParameterInfersType() { // Setup mock connection