Skip to content

Commit

Permalink
boolean expression should prepare/output a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK committed Feb 11, 2015
1 parent 344a9e4 commit 006ecac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Assembler/Segments/ExpressionAssembler.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public function assembleNumericExpression(NumericExpression $expr)

public function assembleBooleanExpression(BooleanExpression $expr)
{
return $this->_assemblePrepared((int)$expr->getValue())
?: (int)$expr->getValue();
return $this->_assemblePrepared($expr->getValue())
?: ($expr->getValue() ? 'true' : 'false');
}

public function assembleArithmeticExpression(
Expand Down
18 changes: 9 additions & 9 deletions tests/Expression/BooleanExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ public function testBoolean()
{
$expression = new BooleanExpression();
$expression->setValue(true);
$this->assertEquals(1, QueryAssembler::stringify($expression));
$this->assertEquals('true', QueryAssembler::stringify($expression));
$expression->setValue(1);
$this->assertEquals(1, QueryAssembler::stringify($expression));
$this->assertEquals('true', QueryAssembler::stringify($expression));
$expression->setValue('abc');
$this->assertEquals(1, QueryAssembler::stringify($expression));
$this->assertEquals('true', QueryAssembler::stringify($expression));

$expression->setValue(false);
$this->assertEquals(0, QueryAssembler::stringify($expression));
$this->assertEquals('false', QueryAssembler::stringify($expression));
$expression->setValue(0);
$this->assertEquals(0, QueryAssembler::stringify($expression));
$this->assertEquals('false', QueryAssembler::stringify($expression));
$expression->setValue('');
$this->assertEquals(0, QueryAssembler::stringify($expression));
$this->assertEquals('false', QueryAssembler::stringify($expression));

$stmt = QueryBuilder::update('tbl', ['field' => $expression]);
$assembler = new QueryAssembler($stmt);
$this->assertEquals('UPDATE tbl SET field = ?', $assembler->getQuery());
$this->assertEquals([0], $assembler->getParameters());
$this->assertEquals([false], $assembler->getParameters());
}

public function testBooleanValue()
{
$expression = new ValueExpression();
$expression->setValue(true);
$this->assertEquals(1, QueryAssembler::stringify($expression));
$this->assertEquals('true', QueryAssembler::stringify($expression));
$expression->setValue(false);
$this->assertEquals(0, QueryAssembler::stringify($expression));
$this->assertEquals('false', QueryAssembler::stringify($expression));
}
}

0 comments on commit 006ecac

Please sign in to comment.