Skip to content

Commit

Permalink
Fix 0 being converted into 1.
Browse files Browse the repository at this point in the history
empty() continues to be sharp and pointy.

Refs #7529
  • Loading branch information
markstory committed Oct 14, 2015
1 parent f8426d3 commit bd1b464
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Database/Expression/CaseExpression.php
Expand Up @@ -119,13 +119,12 @@ protected function _addExpressions($conditions, $values, $types)
if ($numericKey && empty($c)) {
continue;
}

if (!$c instanceof ExpressionInterface) {
continue;
}
array_push($this->_conditions, $c);

$value = !empty($rawValues[$k]) ? $rawValues[$k] : 1;
$value = isset($rawValues[$k]) ? $rawValues[$k] : 1;

if ($value === 'literal') {
$value = $keyValues[$k];
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/Database/Expression/CaseExpressionTest.php
Expand Up @@ -53,6 +53,26 @@ public function testSqlOutput()
$this->assertSame($expected, $caseExpression->sql(new ValueBinder()));
}

/**
* Test sql generation with 0 case.
*
* @return void
*/
public function testSqlOutputZero()
{
$expression = new QueryExpression();
$expression->add(['id' => 'test']);
$caseExpression = new CaseExpression([$expression], [0], ['integer']);
$expected = 'CASE WHEN id = :c0 THEN :c1 END';
$binder = new ValueBinder();
$this->assertSame($expected, $caseExpression->sql($binder));
$expected = [
':c0' => ['value' => 'test', 'type' => null, 'placeholder' => 'c0'],
':c1' => ['value' => 0, 'type' => 'integer', 'placeholder' => 'c1'],
];
$this->assertEquals($expected, $binder->bindings());
}

/**
* Tests that the expression is correctly traversed
*
Expand Down

0 comments on commit bd1b464

Please sign in to comment.