Commit d10daf35 authored by jwage's avatar jwage

[2.0] Changing Expr static methods to be normal public methods (closes #2466)

parent dbce89d7
......@@ -40,13 +40,13 @@ class Expr
*
* [php]
* // (u.type = ?1) AND (u.role = ?2)
* $q->where(Expr::andx('u.type = ?1', 'u.role = ?2'));
* $q->where($q->expr()->andx('u.type = ?1', 'u.role = ?2'));
*
* @param mixed $x Optional clause. Defaults = null, but requires
* at least one defined when converting to string.
* @return Expr\Andx
*/
public static function andx($x = null)
public function andx($x = null)
{
return new Expr\Andx(func_get_args());
}
......@@ -57,13 +57,13 @@ class Expr
*
* [php]
* // (u.type = ?1) OR (u.role = ?2)
* $q->where(Expr::orx('u.type = ?1', 'u.role = ?2'));
* $q->where($q->expr()->orx('u.type = ?1', 'u.role = ?2'));
*
* @param mixed $x Optional clause. Defaults = null, but requires
* at least one defined when converting to string.
* @return Expr\Orx
*/
public static function orx($x = null)
public function orx($x = null)
{
return new Expr\Orx(func_get_args());
}
......@@ -74,13 +74,13 @@ class Expr
*
* [php]
* // u.id, u.name, u.surname
* $q->select(Expr::select('u.id', 'u.name')->add('u.surname'));
* $q->select($q->expr()->select('u.id', 'u.name')->add('u.surname'));
*
* @param mixed $select Optional select. Defaults = null, but requires
* at least one defined when converting to string.
* @return Expr\Select
*/
public static function select($select = null)
public function select($select = null)
{
return new Expr\Select(func_get_args());
}
......@@ -90,13 +90,13 @@ class Expr
*
* [php]
* // User u
* $q->from(Expr::from('User', 'u'));
* $q->from($q->expr()->from('User', 'u'));
*
* @param string $from Entity name.
* @param string $alias Optional alias to be used by Entity.
* @return Expr\From
*/
public static function from($from, $alias = null)
public function from($from, $alias = null)
{
return new Expr\From($from, $alias);
}
......@@ -106,7 +106,7 @@ class Expr
*
* [php]
* // LEFT JOIN u.Group g WITH g.name = 'admin'
* Expr::leftJoin('u.Group', 'g', 'WITH', "g.name = 'admin'")
* $q->expr()->leftJoin('u.Group', 'g', 'WITH', "g.name = 'admin'")
*
* @param string $join Relation join.
* @param string $alias Optional alias to be used by Relation.
......@@ -115,7 +115,7 @@ class Expr
* @param mixed $condition Optional condition to be appended.
* @return Expr\Join
*/
public static function leftJoin($join, $alias = null, $conditionType = null, $condition = null)
public function leftJoin($join, $alias = null, $conditionType = null, $condition = null)
{
return new Expr\Join(Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition);
}
......@@ -125,7 +125,7 @@ class Expr
*
* [php]
* // INNER JOIN u.Group g WITH g.name = 'admin'
* Expr::innerJoin('u.Group', 'g', 'WITH', "g.name = 'admin'")
* $q->expr()->innerJoin('u.Group', 'g', 'WITH', "g.name = 'admin'")
*
* @param string $join Relation join.
* @param string $alias Optional alias to be used by Relation.
......@@ -134,7 +134,7 @@ class Expr
* @param mixed $condition Optional condition to be appended.
* @return Expr\Join
*/
public static function innerJoin($join, $alias = null, $conditionType = null, $condition = null)
public function innerJoin($join, $alias = null, $conditionType = null, $condition = null)
{
return new Expr\Join(Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition);
}
......@@ -144,13 +144,13 @@ class Expr
* Each argument is separated by a ",". Example:
*
* [php]
* $q->orderBy(Expr::orderBy('u.surname', 'ASC')->add('u.name', 'ASC'));
* $q->orderBy($q->expr()->orderBy('u.surname', 'ASC')->add('u.name', 'ASC'));
*
* @param string $sort Optional item sort.
* @param string $order Optional order to be applied in item.
* @return Expr\OrderBy
*/
public static function orderBy($sort = null, $order = null)
public function orderBy($sort = null, $order = null)
{
return new Expr\OrderBy($sort, $order);
}
......@@ -161,13 +161,13 @@ class Expr
*
* [php]
* // u.id, u.name
* $q->select(Expr::groupBy('u.id', 'u.name'));
* $q->select($q->expr()->groupBy('u.id', 'u.name'));
*
* @param mixed $groupBy Optional group by. Defaults = null, but requires
* at least one defined when converting to string.
* @return Expr\Select
*/
public static function groupBy($groupBy = null)
public function groupBy($groupBy = null)
{
return new Expr\GroupBy(func_get_args());
}
......@@ -179,13 +179,13 @@ class Expr
*
* [php]
* // u.id = ?1
* $q->where(Expr::eq('u.id', '?1'));
* $q->where($q->expr()->eq('u.id', '?1'));
*
* @param mixed $x Left expression
* @param mixed $y Right expression
* @return Expr\Comparison
*/
public static function eq($x, $y)
public function eq($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::EQ, $y);
}
......@@ -197,13 +197,13 @@ class Expr
*
* [php]
* // u.id <> ?1
* $q->where(Expr::neq('u.id', '?1'));
* $q->where($q->expr()->neq('u.id', '?1'));
*
* @param mixed $x Left expression
* @param mixed $y Right expression
* @return Expr\Comparison
*/
public static function neq($x, $y)
public function neq($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::NEQ, $y);
}
......@@ -215,13 +215,13 @@ class Expr
*
* [php]
* // u.id < ?1
* $q->where(Expr::lt('u.id', '?1'));
* $q->where($q->expr()->lt('u.id', '?1'));
*
* @param mixed $x Left expression
* @param mixed $y Right expression
* @return Expr\Comparison
*/
public static function lt($x, $y)
public function lt($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::LT, $y);
}
......@@ -233,13 +233,13 @@ class Expr
*
* [php]
* // u.id <= ?1
* $q->where(Expr::lte('u.id', '?1'));
* $q->where($q->expr()->lte('u.id', '?1'));
*
* @param mixed $x Left expression
* @param mixed $y Right expression
* @return Expr\Comparison
*/
public static function lte($x, $y)
public function lte($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::LTE, $y);
}
......@@ -251,13 +251,13 @@ class Expr
*
* [php]
* // u.id > ?1
* $q->where(Expr::gt('u.id', '?1'));
* $q->where($q->expr()->gt('u.id', '?1'));
*
* @param mixed $x Left expression
* @param mixed $y Right expression
* @return Expr\Comparison
*/
public static function gt($x, $y)
public function gt($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::GT, $y);
}
......@@ -269,13 +269,13 @@ class Expr
*
* [php]
* // u.id >= ?1
* $q->where(Expr::gte('u.id', '?1'));
* $q->where($q->expr()->gte('u.id', '?1'));
*
* @param mixed $x Left expression
* @param mixed $y Right expression
* @return Expr\Comparison
*/
public static function gte($x, $y)
public function gte($x, $y)
{
return new Expr\Comparison($x, Expr\Comparison::GTE, $y);
}
......@@ -286,7 +286,7 @@ class Expr
* @param mixed $x Argument to be used in AVG() function.
* @return Expr\Func
*/
public static function avg($x)
public function avg($x)
{
return new Expr\Func('AVG', array($x));
}
......@@ -297,7 +297,7 @@ class Expr
* @param mixed $x Argument to be used in MAX() function.
* @return Expr\Func
*/
public static function max($x)
public function max($x)
{
return new Expr\Func('MAX', array($x));
}
......@@ -308,7 +308,7 @@ class Expr
* @param mixed $x Argument to be used in MIN() function.
* @return Expr\Func
*/
public static function min($x)
public function min($x)
{
return new Expr\Func('MIN', array($x));
}
......@@ -319,7 +319,7 @@ class Expr
* @param mixed $x Argument to be used in COUNT() function.
* @return Expr\Func
*/
public static function count($x)
public function count($x)
{
return new Expr\Func('COUNT', array($x));
}
......@@ -330,7 +330,7 @@ class Expr
* @param mixed $x Argument to be used in COUNT(DISTINCT) function.
* @return string
*/
public static function countDistinct($x)
public function countDistinct($x)
{
return 'COUNT(DISTINCT ' . implode(', ', func_get_args()) . ')';
}
......@@ -341,7 +341,7 @@ class Expr
* @param mixed $subquery DQL Subquery to be used in EXISTS() function.
* @return Expr\Func
*/
public static function exists($subquery)
public function exists($subquery)
{
return new Expr\Func('EXISTS', array($subquery));
}
......@@ -352,7 +352,7 @@ class Expr
* @param mixed $subquery DQL Subquery to be used in ALL() function.
* @return Expr\Func
*/
public static function all($subquery)
public function all($subquery)
{
return new Expr\Func('ALL', array($subquery));
}
......@@ -363,7 +363,7 @@ class Expr
* @param mixed $subquery DQL Subquery to be used in SOME() function.
* @return Expr\Func
*/
public static function some($subquery)
public function some($subquery)
{
return new Expr\Func('SOME', array($subquery));
}
......@@ -374,7 +374,7 @@ class Expr
* @param mixed $subquery DQL Subquery to be used in ANY() function.
* @return Expr\Func
*/
public static function any($subquery)
public function any($subquery)
{
return new Expr\Func('ANY', array($subquery));
}
......@@ -385,7 +385,7 @@ class Expr
* @param mixed $restriction Restriction to be used in NOT() function.
* @return Expr\Func
*/
public static function not($restriction)
public function not($restriction)
{
return new Expr\Func('NOT', array($restriction));
}
......@@ -396,7 +396,7 @@ class Expr
* @param mixed $x Argument to be used in ABS() function.
* @return Expr\Func
*/
public static function abs($x)
public function abs($x)
{
return new Expr\Func('ABS', array($x));
}
......@@ -408,13 +408,13 @@ class Expr
*
* [php]
* // u.salary * u.percentAnualSalaryIncrease
* Expr::prod('u.salary', 'u.percentAnualSalaryIncrease')
* $q->expr()->prod('u.salary', 'u.percentAnualSalaryIncrease')
*
* @param mixed $x Left expression
* @param mixed $y Right expression
* @return Expr\Math
*/
public static function prod($x, $y)
public function prod($x, $y)
{
return new Expr\Math($x, '*', $y);
}
......@@ -426,13 +426,13 @@ class Expr
*
* [php]
* // u.monthlySubscriptionCount - 1
* Expr::diff('u.monthlySubscriptionCount', '1')
* $q->expr()->diff('u.monthlySubscriptionCount', '1')
*
* @param mixed $x Left expression
* @param mixed $y Right expression
* @return Expr\Math
*/
public static function diff($x, $y)
public function diff($x, $y)
{
return new Expr\Math($x, '-', $y);
}
......@@ -444,13 +444,13 @@ class Expr
*
* [php]
* // u.numChildren + 1
* Expr::diff('u.numChildren', '1')
* $q->expr()->diff('u.numChildren', '1')
*
* @param mixed $x Left expression
* @param mixed $y Right expression
* @return Expr\Math
*/
public static function sum($x, $y)
public function sum($x, $y)
{
return new Expr\Math($x, '+', $y);
}
......@@ -462,13 +462,13 @@ class Expr
*
* [php]
* // u.total - u.period
* Expr::diff('u.total', 'u.period')
* $q->expr()->diff('u.total', 'u.period')
*
* @param mixed $x Left expression
* @param mixed $y Right expression
* @return Expr\Math
*/
public static function quot($x, $y)
public function quot($x, $y)
{
return new Expr\Math($x, '/', $y);
}
......@@ -479,7 +479,7 @@ class Expr
* @param mixed $x Argument to be used in SQRT() function.
* @return Expr\Func
*/
public static function sqrt($x)
public function sqrt($x)
{
return new Expr\Func('SQRT', array($x));
}
......@@ -491,7 +491,7 @@ class Expr
* @param mixed $y Argument to be used in IN() function.
* @return Expr\Func
*/
public static function in($x, $y)
public function in($x, $y)
{
return new Expr\Func($x . ' IN', (array) $y);
}
......@@ -503,7 +503,7 @@ class Expr
* @param mixed $y Argument to be used in NOT IN() function.
* @return Expr\Func
*/
public static function notIn($x, $y)
public function notIn($x, $y)
{
return new Expr\Func($x . ' NOT IN', (array) $y);
}
......@@ -515,7 +515,7 @@ class Expr
* @param mixed $y Argument to be used in LIKE() comparison.
* @return Expr\Comparison
*/
public static function like($x, $y)
public function like($x, $y)
{
return new Expr\Comparison($x, 'LIKE', $y);
}
......@@ -527,7 +527,7 @@ class Expr
* @param mixed $x Second argument to be used in CONCAT() function.
* @return Expr\Func
*/
public static function concat($x, $y)
public function concat($x, $y)
{
return new Expr\Func('CONCAT', array($x, $y));
}
......@@ -540,7 +540,7 @@ class Expr
* @param integer $len Length of crop. May accept negative values.
* @return Expr\Func
*/
public static function substr($x, $from, $len)
public function substr($x, $from, $len)
{
return new Expr\Func('SUBSTR', array($x, $from, $len));
}
......@@ -551,7 +551,7 @@ class Expr
* @param mixed $x Argument to be used in LOWER() function.
* @return Expr\Func
*/
public static function lower($x)
public function lower($x)
{
return new Expr\Func('LOWER', array($x));
}
......@@ -562,7 +562,7 @@ class Expr
* @param mixed $x Argument to be used in LOWER() function.
* @return Expr\Func
*/
public static function upper($x)
public function upper($x)
{
return new Expr\Func('UPPER', array($x));
}
......@@ -573,7 +573,7 @@ class Expr
* @param mixed $x Argument to be used as argument of LENGTH() function.
* @return Expr\Func
*/
public static function length($x)
public function length($x)
{
return new Expr\Func('LENGTH', array($x));
}
......@@ -584,7 +584,7 @@ class Expr
* @param mixed $literal Argument to be converted to literal.
* @return string
*/
public static function literal($literal)
public function literal($literal)
{
if (is_numeric($literal)) {
return (string) $literal;
......@@ -601,7 +601,7 @@ class Expr
* @param integer $y End point value to be used in BETWEEN() function.
* @return Expr\Func
*/
public static function between($val, $x, $y)
public function between($val, $x, $y)
{
return new Expr\Func('BETWEEN', array($val, $x, $y));
}
......@@ -612,7 +612,7 @@ class Expr
* @param mixed $x Argument to be used as argument of TRIM() function.
* @return Expr\Func
*/
public static function trim($x)
public function trim($x)
{
return new Expr\Func('TRIM', $x);
}
......
......@@ -83,6 +83,11 @@ class QueryBuilder
*/
private $_q;
/**
* @var Expr The Expr instance used to generate DQL expressions
*/
private $_expr;
/**
* Initializes a new <tt>QueryBuilder</tt> that uses the given <tt>EntityManager</tt>.
*
......@@ -94,6 +99,19 @@ class QueryBuilder
$this->_q = $entityManager->createQuery();
}
/**
* Factory for instantiating and retrieving the Expr instance when needed
*
* @return Expr $expr
*/
public function expr()
{
if ( ! $this->_expr) {
$this->_expr = new Expr;
}
return $this->_expr;
}
public function getType()
{
return $this->_type;
......
......@@ -43,31 +43,32 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
protected function setUp()
{
$this->_em = $this->_getTestEntityManager();
$this->_expr = new Expr;
}
public function testAvgExpr()
{
$this->assertEquals('AVG(u.id)', (string) Expr::avg('u.id'));
$this->assertEquals('AVG(u.id)', (string) $this->_expr->avg('u.id'));
}
public function testMaxExpr()
{
$this->assertEquals('MAX(u.id)', (string) Expr::max('u.id'));
$this->assertEquals('MAX(u.id)', (string) $this->_expr->max('u.id'));
}
public function testMinExpr()
{
$this->assertEquals('MIN(u.id)', (string) Expr::min('u.id'));
$this->assertEquals('MIN(u.id)', (string) $this->_expr->min('u.id'));
}
public function testCountExpr()
{
$this->assertEquals('MAX(u.id)', (string) Expr::max('u.id'));
$this->assertEquals('MAX(u.id)', (string) $this->_expr->max('u.id'));
}
public function testCountDistinctExpr()
{
$this->assertEquals('COUNT(DISTINCT u.id)', (string) Expr::countDistinct('u.id'));
$this->assertEquals('COUNT(DISTINCT u.id)', (string) $this->_expr->countDistinct('u.id'));
}
public function testExistsExpr()
......@@ -75,7 +76,7 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
$qb = $this->_em->createQueryBuilder();
$qb->select('u')->from('User', 'u')->where('u.name = ?1');
$this->assertEquals('EXISTS(SELECT u FROM User u WHERE u.name = ?1)', (string) Expr::exists($qb));
$this->assertEquals('EXISTS(SELECT u FROM User u WHERE u.name = ?1)', (string) $this->_expr->exists($qb));
}
public function testAllExpr()
......@@ -83,7 +84,7 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
$qb = $this->_em->createQueryBuilder();
$qb->select('u')->from('User', 'u')->where('u.name = ?1');
$this->assertEquals('ALL(SELECT u FROM User u WHERE u.name = ?1)', (string) Expr::all($qb));
$this->assertEquals('ALL(SELECT u FROM User u WHERE u.name = ?1)', (string) $this->_expr->all($qb));
}
public function testSomeExpr()
......@@ -91,7 +92,7 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
$qb = $this->_em->createQueryBuilder();
$qb->select('u')->from('User', 'u')->where('u.name = ?1');
$this->assertEquals('SOME(SELECT u FROM User u WHERE u.name = ?1)', (string) Expr::some($qb));
$this->assertEquals('SOME(SELECT u FROM User u WHERE u.name = ?1)', (string) $this->_expr->some($qb));
}
public function testAnyExpr()
......@@ -99,7 +100,7 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
$qb = $this->_em->createQueryBuilder();
$qb->select('u')->from('User', 'u')->where('u.name = ?1');
$this->assertEquals('ANY(SELECT u FROM User u WHERE u.name = ?1)', (string) Expr::any($qb));
$this->assertEquals('ANY(SELECT u FROM User u WHERE u.name = ?1)', (string) $this->_expr->any($qb));
}
public function testNotExpr()
......@@ -107,168 +108,168 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
$qb = $this->_em->createQueryBuilder();
$qb->select('u')->from('User', 'u')->where('u.name = ?1');
$this->assertEquals('NOT(SELECT u FROM User u WHERE u.name = ?1)', (string) Expr::not($qb));
$this->assertEquals('NOT(SELECT u FROM User u WHERE u.name = ?1)', (string) $this->_expr->not($qb));
}
public function testAndExpr()
{
$this->assertEquals('(1 = 1) AND (2 = 2)', (string) Expr::andx((string) Expr::eq(1, 1), (string) Expr::eq(2, 2)));
$this->assertEquals('(1 = 1) AND (2 = 2)', (string) $this->_expr->andx((string) $this->_expr->eq(1, 1), (string) $this->_expr->eq(2, 2)));
}
public function testIntelligentParenthesisPreventionAndExpr()
{
$this->assertEquals(
'(1 = 1) AND (2 = 2)',
(string) Expr::andx(Expr::orx(Expr::andx(Expr::eq(1, 1))), (string) Expr::eq(2, 2))
(string) $this->_expr->andx($this->_expr->orx($this->_expr->andx($this->_expr->eq(1, 1))), (string) $this->_expr->eq(2, 2))
);
}
public function testOrExpr()
{
$this->assertEquals('(1 = 1) OR (2 = 2)', (string) Expr::orx((string) Expr::eq(1, 1), (string) Expr::eq(2, 2)));
$this->assertEquals('(1 = 1) OR (2 = 2)', (string) $this->_expr->orx((string) $this->_expr->eq(1, 1), (string) $this->_expr->eq(2, 2)));
}
public function testAbsExpr()
{
$this->assertEquals('ABS(1)', (string) Expr::abs(1));
$this->assertEquals('ABS(1)', (string) $this->_expr->abs(1));
}
public function testProdExpr()
{
$this->assertEquals('1 * 2', (string) Expr::prod(1, 2));
$this->assertEquals('1 * 2', (string) $this->_expr->prod(1, 2));
}
public function testDiffExpr()
{
$this->assertEquals('1 - 2', (string) Expr::diff(1, 2));
$this->assertEquals('1 - 2', (string) $this->_expr->diff(1, 2));
}
public function testSumExpr()
{
$this->assertEquals('1 + 2', (string) Expr::sum(1, 2));
$this->assertEquals('1 + 2', (string) $this->_expr->sum(1, 2));
}
public function testQuotientExpr()
{
$this->assertEquals('10 / 2', (string) Expr::quot(10, 2));
$this->assertEquals('10 / 2', (string) $this->_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)));
$this->assertEquals('(100 - 20) / 2', (string) $this->_expr->quot($this->_expr->diff(100, 20), 2));
$this->assertEquals('100 - (20 / 2)', (string) $this->_expr->diff(100, $this->_expr->quot(20, 2)));
}
public function testSquareRootExpr()
{
$this->assertEquals('SQRT(1)', (string) Expr::sqrt(1));
$this->assertEquals('SQRT(1)', (string) $this->_expr->sqrt(1));
}
public function testEqualExpr()
{
$this->assertEquals('1 = 1', (string) Expr::eq(1, 1));
$this->assertEquals('1 = 1', (string) $this->_expr->eq(1, 1));
}
public function testLikeExpr()
{
$this->assertEquals('a.description LIKE :description', (string) Expr::like('a.description', ':description'));
$this->assertEquals('a.description LIKE :description', (string) $this->_expr->like('a.description', ':description'));
}
public function testConcatExpr()
{
$this->assertEquals('CONCAT(u.first_name, u.last_name)', (string) Expr::concat('u.first_name', 'u.last_name'));
$this->assertEquals('CONCAT(u.first_name, u.last_name)', (string) $this->_expr->concat('u.first_name', 'u.last_name'));
}
public function testSubstrExpr()
{
$this->assertEquals('SUBSTR(a.title, 0, 25)', (string) Expr::substr('a.title', 0, 25));
$this->assertEquals('SUBSTR(a.title, 0, 25)', (string) $this->_expr->substr('a.title', 0, 25));
}
public function testLowerExpr()
{
$this->assertEquals('LOWER(u.first_name)', (string) Expr::lower('u.first_name'));
$this->assertEquals('LOWER(u.first_name)', (string) $this->_expr->lower('u.first_name'));
}
public function testUpperExpr()
{
$this->assertEquals('UPPER(u.first_name)', (string) Expr::upper('u.first_name'));
$this->assertEquals('UPPER(u.first_name)', (string) $this->_expr->upper('u.first_name'));
}
public function testLengthExpr()
{
$this->assertEquals('LENGTH(u.first_name)', (string) Expr::length('u.first_name'));
$this->assertEquals('LENGTH(u.first_name)', (string) $this->_expr->length('u.first_name'));
}
public function testGreaterThanExpr()
{
$this->assertEquals('5 > 2', (string) Expr::gt(5, 2));
$this->assertEquals('5 > 2', (string) $this->_expr->gt(5, 2));
}
public function testLessThanExpr()
{
$this->assertEquals('2 < 5', (string) Expr::lt(2, 5));
$this->assertEquals('2 < 5', (string) $this->_expr->lt(2, 5));
}
public function testStringLiteralExpr()
{
$this->assertEquals("'word'", (string) Expr::literal('word'));
$this->assertEquals("'word'", (string) $this->_expr->literal('word'));
}
public function testNumericLiteralExpr()
{
$this->assertEquals(5, (string) Expr::literal(5));
$this->assertEquals(5, (string) $this->_expr->literal(5));
}
public function testGreaterThanOrEqualToExpr()
{
$this->assertEquals('5 >= 2', (string) Expr::gte(5, 2));
$this->assertEquals('5 >= 2', (string) $this->_expr->gte(5, 2));
}
public function testLessThanOrEqualTo()
{
$this->assertEquals('2 <= 5', (string) Expr::lte(2, 5));
$this->assertEquals('2 <= 5', (string) $this->_expr->lte(2, 5));
}
public function testBetweenExpr()
{
$this->assertEquals('BETWEEN(u.id, 3, 6)', (string) Expr::between('u.id', 3, 6));
$this->assertEquals('BETWEEN(u.id, 3, 6)', (string) $this->_expr->between('u.id', 3, 6));
}
public function testTrimExpr()
{
$this->assertEquals('TRIM(u.id)', (string) Expr::trim('u.id'));
$this->assertEquals('TRIM(u.id)', (string) $this->_expr->trim('u.id'));
}
public function testInExpr()
{
$this->assertEquals('u.id IN(1, 2, 3)', (string) Expr::in('u.id', array(1, 2, 3)));
$this->assertEquals('u.id IN(1, 2, 3)', (string) $this->_expr->in('u.id', array(1, 2, 3)));
}
public function testAndxOrxExpr()
{
$andExpr = Expr::andx();
$andExpr->add(Expr::eq(1, 1));
$andExpr->add(Expr::lt(1, 5));
$andExpr = $this->_expr->andx();
$andExpr->add($this->_expr->eq(1, 1));
$andExpr->add($this->_expr->lt(1, 5));
$orExpr = Expr::orx();
$orExpr = $this->_expr->orx();
$orExpr->add($andExpr);
$orExpr->add(Expr::eq(1, 1));
$orExpr->add($this->_expr->eq(1, 1));
$this->assertEquals('((1 = 1) AND (1 < 5)) OR (1 = 1)', (string) $orExpr);
}
public function testOrxExpr()
{
$orExpr = Expr::orx();
$orExpr->add(Expr::eq(1, 1));
$orExpr->add(Expr::lt(1, 5));
$orExpr = $this->_expr->orx();
$orExpr->add($this->_expr->eq(1, 1));
$orExpr->add($this->_expr->lt(1, 5));
$this->assertEquals('(1 = 1) OR (1 < 5)', (string) $orExpr);
}
public function testSelectExpr()
{
$selectExpr = Expr::select();
$selectExpr = $this->_expr->select();
$selectExpr->add('u.id');
$selectExpr->add('u.username');
......@@ -277,13 +278,13 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
public function testFromExpr()
{
$this->assertEquals('User', (string) Expr::from('User'));
$this->assertEquals('User u', (string) Expr::from('User', 'u'));
$this->assertEquals('User', (string) $this->_expr->from('User'));
$this->assertEquals('User u', (string) $this->_expr->from('User', 'u'));
}
public function testExprBaseCount()
{
$selectExpr = Expr::select();
$selectExpr = $this->_expr->select();
$selectExpr->add('u.id');
$selectExpr->add('u.username');
......@@ -292,7 +293,7 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
public function testOrderByCountExpr()
{
$orderByExpr = Expr::orderBy();
$orderByExpr = $this->_expr->orderBy();
$orderByExpr->add('u.username', 'DESC');
$this->assertEquals($orderByExpr->count(), 1);
......@@ -301,13 +302,13 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
public function testOrderByOrder()
{
$orderByExpr = Expr::orderBy('u.username', 'DESC');
$orderByExpr = $this->_expr->orderBy('u.username', 'DESC');
$this->assertEquals('u.username DESC', (string) $orderByExpr);
}
public function testOrderByDefaultOrderIsAsc()
{
$orderByExpr = Expr::orderBy('u.username');
$orderByExpr = $this->_expr->orderBy('u.username');
$this->assertEquals('u.username ASC', (string) $orderByExpr);
}
......@@ -316,7 +317,7 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase
*/
public function testAddThrowsException()
{
$orExpr = Expr::orx();
$orExpr->add(Expr::quot(5, 2));
$orExpr = $this->_expr->orx();
$orExpr->add($this->_expr->quot(5, 2));
}
}
\ No newline at end of file
......@@ -183,44 +183,44 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAndWhereIn()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
$qb = $this->_em->createQueryBuilder();
$qb->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid')
->andWhere(Expr::in('u.id', array(1, 2, 3)));
->andWhere($qb->expr()->in('u.id', array(1, 2, 3)));
$this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND (u.id IN(1, 2, 3))');
}
public function testOrWhereIn()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
$qb = $this->_em->createQueryBuilder();
$qb->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid')
->orWhere(Expr::in('u.id', array(1, 2, 3)));
->orWhere($qb->expr()->in('u.id', array(1, 2, 3)));
$this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) OR (u.id IN(1, 2, 3))');
}
public function testAndWhereNotIn()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
$qb = $this->_em->createQueryBuilder();
$qb->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid')
->andWhere(Expr::notIn('u.id', array(1, 2, 3)));
->andWhere($qb->expr()->notIn('u.id', array(1, 2, 3)));
$this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND (u.id NOT IN(1, 2, 3))');
}
public function testOrWhereNotIn()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
$qb = $this->_em->createQueryBuilder();
$qb->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid')
->OrWhere(Expr::notIn('u.id', array(1, 2, 3)));
->orWhere($qb->expr()->notIn('u.id', array(1, 2, 3)));
$this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) OR (u.id NOT IN(1, 2, 3))');
}
......@@ -316,10 +316,10 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testSetParameters()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
$qb = $this->_em->createQueryBuilder();
$qb->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where(Expr::orx('u.username = :username', 'u.username = :username2'));
->where($qb->expr()->orx('u.username = :username', 'u.username = :username2'));
$qb->setParameters(array('username' => 'jwage', 'username2' => 'jonwage'));
......@@ -329,8 +329,8 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testGetParameters()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
$qb = $this->_em->createQueryBuilder();
$qb->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :id');
......@@ -371,22 +371,22 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testMultipleOrWhere()
{
$qb = $this->_em->createQueryBuilder()
->select('u')
$qb = $this->_em->createQueryBuilder();
$qb->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->orWhere('u.id = :uid', Expr::eq('u.id', ':uid2'));
->orWhere('u.id = :uid', $qb->expr()->eq('u.id', ':uid2'));
$this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) OR (u.id = :uid2)');
}
public function testComplexWhere()
{
$orExpr = Expr::orx();
$orExpr->add(Expr::eq('u.id', ':uid3'));
$orExpr->add(Expr::in('u.id', array(1)));
$qb = $this->_em->createQueryBuilder();
$orExpr = $qb->expr()->orx();
$orExpr->add($qb->expr()->eq('u.id', ':uid3'));
$orExpr->add($qb->expr()->in('u.id', array(1)));
$qb = $this->_em->createQueryBuilder()
->select('u')
$qb->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where($orExpr);
......
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