From 4266ab77b219242455c8d46a93f81e2dcf13b143 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 22 Jul 2011 14:55:00 +0200 Subject: [PATCH] [DDC-551] Added __toString() method to SQLFilter --- lib/Doctrine/ORM/Query/Filter/SQLFilter.php | 5 +++++ .../Tests/ORM/Functional/SQLFilterTest.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 4ca31d64d..2ac413788 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -62,5 +62,10 @@ abstract class SQLFilter return $this->conn->quote($this->parameters[$name]['value'], $this->parameters[$name]['type']); } + final function __toString() + { + return serialize($this->parameters); + } + abstract function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index a58fef3bf..6cc1a75be 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -173,6 +173,25 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals('', $filter->addFilterConstraint($targetEntity, 't1_')); } + + public function testSQLFilterToString() + { + $filter = new MyLocaleFilter($this->getMockConnection()); + $filter->setParameter('locale', 'en', TYPE::STRING); + $filter->setParameter('foo', 'bar', TYPE::STRING); + + $filter2 = new MyLocaleFilter($this->getMockConnection()); + $filter2->setParameter('foo', 'bar', TYPE::STRING); + $filter2->setParameter('locale', 'en', TYPE::STRING); + + $parameters = array( + 'foo' => array('value' => 'bar', 'type' => TYPE::STRING), + 'locale' => array('value' => 'en', 'type' => TYPE::STRING), + ); + + $this->assertEquals(serialize($parameters), ''.$filter); + $this->assertEquals(''.$filter, ''.$filter2); + } } class MySoftDeleteFilter extends SQLFilter