From 400f420925eea9d50eee9ea3d78a847b381865ce Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Wed, 19 Mar 2014 13:00:45 +0100 Subject: [PATCH 1/3] Added MEMBER OF and INSTANCE OF helpers to ExpressionBuilder --- lib/Doctrine/ORM/Query/Expr.php | 28 +++++++++++++++++++++ tests/Doctrine/Tests/ORM/Query/ExprTest.php | 13 ++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index 48fb790b6..b70ecad77 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -644,4 +644,32 @@ class Expr { return new Expr\Func('TRIM', $x); } + + + /** + * Creates an instance of MEMBER OF function, with the given arguments. + * + * @param string $x Value to be checked + * @param string $y Value to be checked against + * + * @return string + */ + public function isMemberOf($x, $y) + { + return $x . ' MEMBER OF ' . $y; + } + + + /** + * Creates an instance of INSTANCE OF function, with the given arguments. + * + * @param string $x Value to be checked + * @param string $y Value to be checked against + + * @return string + */ + public function isInstanceOf($x, $y) + { + return $x . ' INSTANCE OF ' . $y; + } } diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index 4d90ea1d8..7179bd1bb 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -38,6 +38,11 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase { private $_em; + /** + * @var Expr + */ + private $_expr; + protected function setUp() { $this->_em = $this->_getTestEntityManager(); @@ -271,6 +276,14 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('u.id IS NOT NULL', (string) $this->_expr->isNotNull('u.id')); } + public function testIsInstanceOfExpr() { + $this->assertEquals('u INSTANCE OF Doctrine\Tests\Models\Company\CompanyEmployee', (string) $this->_expr->isInstanceOf('u', 'Doctrine\Tests\Models\Company\CompanyEmployee')); + } + + public function testIsMemberOfExpr() { + $this->assertEquals(':groupId MEMBER OF u.groups', (string) $this->_expr->isMemberOf(':groupId', 'u.groups')); + } + public function testInExpr() { $this->assertEquals('u.id IN(1, 2, 3)', (string) $this->_expr->in('u.id', array(1, 2, 3))); From 56e879b7aab45f3f6b2e58d8de1ec72e82b8a920 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Wed, 19 Mar 2014 13:03:26 +0100 Subject: [PATCH 2/3] Removed double linebreaks --- lib/Doctrine/ORM/Query/Expr.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index b70ecad77..c70b69aff 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -645,7 +645,6 @@ class Expr return new Expr\Func('TRIM', $x); } - /** * Creates an instance of MEMBER OF function, with the given arguments. * @@ -659,7 +658,6 @@ class Expr return $x . ' MEMBER OF ' . $y; } - /** * Creates an instance of INSTANCE OF function, with the given arguments. * From 262e465e39116f7fe0554d3b45766fb9ec814ca3 Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Thu, 20 Mar 2014 09:02:39 +0100 Subject: [PATCH 3/3] Processed code-review feedback --- lib/Doctrine/ORM/Query/Expr.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index c70b69aff..cd2be5d1d 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -651,11 +651,11 @@ class Expr * @param string $x Value to be checked * @param string $y Value to be checked against * - * @return string + * @return Expr\Comparison */ public function isMemberOf($x, $y) { - return $x . ' MEMBER OF ' . $y; + return new Expr\Comparison($x, 'MEMBER OF', $y); } /** @@ -663,11 +663,11 @@ class Expr * * @param string $x Value to be checked * @param string $y Value to be checked against - - * @return string + * + * @return Expr\Comparison */ public function isInstanceOf($x, $y) { - return $x . ' INSTANCE OF ' . $y; + return new Expr\Comparison($x, 'INSTANCE OF', $y); } }