EntityManagerInterface instead of EntityManager
Make connection available in filters Add test for the changes
This commit is contained in:
parent
14c3adbec0
commit
9cb17d2915
@ -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.
|
||||
*
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user