Skip to content
Permalink
Browse files

Fixing bug in BetweenExpression

The bug prevented the use of expression objects as parts of the between
  • Loading branch information...
lorenzo committed Sep 15, 2015
1 parent 7a9e321 commit f9dcdd9e073c7115391b174146cfc0f63424402e
Showing with 28 additions and 1 deletion.
  1. +1 −1 src/Database/Expression/BetweenExpression.php
  2. +27 −0 tests/TestCase/Database/QueryTest.php
@@ -83,7 +83,7 @@ public function sql(ValueBinder $generator)
}
foreach ($parts as $name => $part) {
if ($field instanceof ExpressionInterface) {
if ($part instanceof ExpressionInterface) {
$parts[$name] = $part->sql($generator);
continue;
}
@@ -1298,6 +1298,33 @@ public function testWhereWithBetweenWithExpressionField()
$this->assertEquals(6, $second['id']);
}
/**
* Tests that it is possible to use an expression object
* as any of the parts of the between expression
*
* @return void
*/
public function testWhereWithBetweenWithExpressionParts()
{
$query = new Query($this->connection);
$result = $query
->select(['id'])
->from('comments')
->where(function ($exp, $q) {
$from = $q->newExpr("'2007-03-18 10:51:00'");
$to = $q->newExpr("'2007-03-18 10:54:00'");
return $exp->between('created', $from, $to);
})
->execute();
$this->assertCount(2, $result);
$first = $result->fetch('assoc');
$this->assertEquals(4, $first['id']);
$second = $result->fetch('assoc');
$this->assertEquals(5, $second['id']);
}
/**
* Tests nesting query expressions both using arrays and closures
*

0 comments on commit f9dcdd9

Please sign in to comment.
You can’t perform that action at this time.