[2.0] Fixed issue with missing parenthesis in Math expressions
This commit is contained in:
parent
c81affb9f7
commit
b0202f2921
@ -45,6 +45,20 @@ class Math
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -129,6 +129,12 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
|
||||
{
|
||||
$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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user