1
0
mirror of synced 2024-12-12 22:36:02 +03:00

[2.0] Fixed issue with missing parenthesis in Math expressions

This commit is contained in:
guilhermeblanco 2009-08-14 21:03:27 +00:00
parent c81affb9f7
commit b0202f2921
2 changed files with 21 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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()
{