Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLFilters enahancements #1054

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/Doctrine/ORM/Query/Filter/SQLFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,7 +37,7 @@ abstract class SQLFilter
/**
* The entity manager.
*
* @var EntityManager
* @var EntityManagerInterface
*/
private $em;

Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the typehint is a BC break

{
$this->em = $em;
}
Expand Down Expand Up @@ -133,6 +133,16 @@ final public function __toString()
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.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ public function testSQLFilterGetSetParameter()
$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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should rather be $this->assertSame($conn, $reflMethod->invoke($filter));

}

public function testSQLFilterSetParameterInfersType()
{
// Setup mock connection
Expand Down