Commit b0202f29 authored by guilhermeblanco's avatar guilhermeblanco

[2.0] Fixed issue with missing parenthesis in Math expressions

parent c81affb9
...@@ -45,6 +45,20 @@ class Math ...@@ -45,6 +45,20 @@ class Math
public function __toString() public function __toString()
{ {
return $this->_leftExpr . ' ' . $this->_operator . ' ' . $this->_rightExpr; // Adjusting Left Expression
$leftExpr = (string) $this->_leftExpr;
if ($this->_leftExpr instanceof Math) {
$leftExpr = '(' . $leftExpr . ')';
}
// Adjusting Right Expression
$rightExpr = (string) $this->_rightExpr;
if ($this->_rightExpr instanceof Math) {
$rightExpr = '(' . $rightExpr . ')';
}
return $leftExpr . ' ' . $this->_operator . ' ' . $rightExpr;
} }
} }
\ No newline at end of file
...@@ -129,6 +129,12 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase ...@@ -129,6 +129,12 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
{ {
$this->assertEquals('10 / 2', (string) Expr::quot(10, 2)); $this->assertEquals('10 / 2', (string) Expr::quot(10, 2));
} }
public function testScopeInArithmeticExpr()
{
$this->assertEquals('(100 - 20) / 2', (string) Expr::quot(Expr::diff(100, 20), 2));
$this->assertEquals('100 - (20 / 2)', (string) Expr::diff(100, Expr::quot(20, 2)));
}
public function testSquareRootExpr() public function testSquareRootExpr()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment