From bd8ba72584934a1f98fee92d5134808efa52d72b Mon Sep 17 00:00:00 2001 From: Travis Hill Date: Wed, 29 Jul 2015 13:12:18 -0400 Subject: [PATCH 1/2] Allow null $parameters in Predicate::expression() Zend\Db\Sql\Predicate\Expression::__construct() allows nulls for the $valueParameter, but this method that passes the parameter through does not allow nulls, so you have to explicitly pass null. Instead, in Zend\Db\Sql\Predicate\Predicate::expression(), the $parameters parameter should allow nulls. --- src/Sql/Predicate/Predicate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sql/Predicate/Predicate.php b/src/Sql/Predicate/Predicate.php index c928100e06..26cd180aeb 100644 --- a/src/Sql/Predicate/Predicate.php +++ b/src/Sql/Predicate/Predicate.php @@ -242,7 +242,7 @@ public function notLike($identifier, $notLike) * @param $parameters * @return $this */ - public function expression($expression, $parameters) + public function expression($expression, $parameters = null) { $this->addPredicate( new Expression($expression, $parameters), From 51863b73f287ea74a51fad2cab3669b454db09b7 Mon Sep 17 00:00:00 2001 From: Travis Hill Date: Sun, 6 Sep 2015 03:36:56 -0400 Subject: [PATCH 2/2] Added unit test for Predicate::expression() with null $parameters --- test/Sql/Predicate/PredicateTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/Sql/Predicate/PredicateTest.php b/test/Sql/Predicate/PredicateTest.php index a3186f01da..72e458106d 100644 --- a/test/Sql/Predicate/PredicateTest.php +++ b/test/Sql/Predicate/PredicateTest.php @@ -228,6 +228,19 @@ public function testExpression() $predicate->getExpressionData() ); } + + /** + * @testdox Unit test: Test expression() allows null $parameters + */ + public function testExpressionNullParameters() + { + $predicate = new Predicate; + + $predicate->expression('foo = bar'); + $predicates = $predicate->getPredicates(); + $expression = $predicates[0][1]; + $this->assertEquals([null], $expression->getParameters()); + } /** * @testdox Unit test: Test literal() is chainable, returns proper values, and is backwards compatible with 2.0.*