1
0
mirror of synced 2025-01-09 18:47:10 +03:00

Merge branch 'feature/#1054-DDC-3161-allow-connection-access-in-filters'

Close #1054
This commit is contained in:
Marco Pivetta 2015-01-13 02:06:49 +01:00
commit ef113e52ab
2 changed files with 32 additions and 0 deletions

View File

@ -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.
*

View File

@ -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