2009-07-09 08:18:58 +04:00
< ? php
/*
* $Id $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT
* LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL ,
* SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT
* LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL . For more information , see
* < http :// www . doctrine - project . org >.
*/
namespace Doctrine\Tests\ORM ;
2009-08-13 14:13:06 +04:00
use Doctrine\ORM\QueryBuilder ,
Doctrine\ORM\Query\Expr ;
2009-07-09 08:18:58 +04:00
require_once __DIR__ . '/../TestInit.php' ;
/**
* Test case for the QueryBuilder class used to build DQL query string in a
* object oriented way .
*
* @ author Jonathan H . Wage < jonwage @ gmail . com >
* @ author Roman Borschel < roman @ code - factory . org
* @ license http :// www . opensource . org / licenses / lgpl - license . php LGPL
* @ link http :// www . phpdoctrine . org
* @ since 2.0
* @ version $Revision $
*/
class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
{
private $_em ;
protected function setUp ()
{
$this -> _em = $this -> _getTestEntityManager ();
}
protected function assertValidQueryBuilder ( QueryBuilder $qb , $expectedDql )
{
$dql = $qb -> getDql ();
$q = $qb -> getQuery ();
$this -> assertEquals ( $expectedDql , $dql );
}
2009-07-10 01:56:34 +04:00
public function testSelectSetsType ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 01:56:34 +04:00
-> delete ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> select ( 'u.id' , 'u.username' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertEquals ( $qb -> getType (), QueryBuilder :: SELECT );
2009-07-09 08:18:58 +04:00
}
2009-07-10 21:53:48 +04:00
public function testEmptySelectSetsType ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 21:53:48 +04:00
-> delete ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> select ();
$this -> assertEquals ( $qb -> getType (), QueryBuilder :: SELECT );
}
2009-07-10 01:56:34 +04:00
public function testDeleteSetsType ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 01:56:34 +04:00
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> delete ();
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertEquals ( $qb -> getType (), QueryBuilder :: DELETE );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testUpdateSetsType ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 01:56:34 +04:00
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> update ();
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertEquals ( $qb -> getType (), QueryBuilder :: UPDATE );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testSimpleSelect ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-07-10 01:56:34 +04:00
-> select ( 'u.id' , 'u.username' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u.id, u.username FROM Doctrine\Tests\Models\CMS\CmsUser u' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testSimpleDelete ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 01:56:34 +04:00
-> delete ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertValidQueryBuilder ( $qb , 'DELETE Doctrine\Tests\Models\CMS\CmsUser u' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testSimpleUpdate ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 01:56:34 +04:00
-> update ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> set ( 'u.username' , ':username' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertValidQueryBuilder ( $qb , 'UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.username = :username' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testInnerJoin ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 01:56:34 +04:00
-> select ( 'u' , 'a' )
2009-07-09 08:18:58 +04:00
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-08-15 02:50:36 +04:00
-> innerJoin ( 'u.articles' , 'a' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a' );
2009-07-09 08:18:58 +04:00
}
2009-08-15 02:50:36 +04:00
public function testComplexInnerJoin ()
{
$qb = $this -> _em -> createQueryBuilder ()
-> select ( 'u' , 'a' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> innerJoin ( 'u.articles' , 'a' , 'ON' , 'u.id = a.author_id' );
$this -> assertValidQueryBuilder (
$qb ,
'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a ON u.id = a.author_id'
);
}
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
public function testLeftJoin ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 01:56:34 +04:00
-> select ( 'u' , 'a' )
2009-07-09 08:18:58 +04:00
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-08-15 02:50:36 +04:00
-> leftJoin ( 'u.articles' , 'a' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testWhere ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-07-10 01:56:34 +04:00
-> where ( 'u.id = :uid' );
2009-07-09 08:18:58 +04:00
2009-07-10 18:02:06 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid)' );
}
public function testAndWhere ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 18:02:06 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> where ( 'u.id = :uid' )
-> andWhere ( 'u.id = :uid2' );
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND (u.id = :uid2)' );
}
public function testOrWhere ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 18:02:06 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> where ( 'u.id = :uid' )
-> orWhere ( '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 testAndWhereIn ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 18:02:06 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> where ( 'u.id = :uid' )
-> andWhereIn ( '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 ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 18:02:06 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> where ( 'u.id = :uid' )
-> orWhereIn ( '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 ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 18:02:06 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> where ( 'u.id = :uid' )
-> andWhereNotIn ( '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 ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 18:02:06 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> where ( 'u.id = :uid' )
-> OrWhereNotIn ( '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)' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testGroupBy ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-07-10 21:53:48 +04:00
-> groupBy ( 'u.id' )
-> addGroupBy ( 'u.username' );
2009-07-09 08:18:58 +04:00
2009-07-10 21:53:48 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id, u.username' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testHaving ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-07-10 01:56:34 +04:00
-> groupBy ( 'u.id' )
-> having ( 'COUNT(u.id) > 1' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id HAVING COUNT(u.id) > 1' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testAndHaving ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-07-10 01:56:34 +04:00
-> groupBy ( 'u.id' )
-> having ( 'COUNT(u.id) > 1' )
-> andHaving ( 'COUNT(u.id) < 1' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id HAVING COUNT(u.id) > 1 AND COUNT(u.id) < 1' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testOrHaving ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-07-10 01:56:34 +04:00
-> groupBy ( 'u.id' )
-> having ( 'COUNT(u.id) > 1' )
-> andHaving ( 'COUNT(u.id) < 1' )
-> orHaving ( 'COUNT(u.id) > 1' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id HAVING COUNT(u.id) > 1 AND COUNT(u.id) < 1 OR COUNT(u.id) > 1' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testOrderBy ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-07-10 01:56:34 +04:00
-> orderBy ( 'u.username' , 'ASC' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testAddOrderBy ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-07-10 01:56:34 +04:00
-> orderBy ( 'u.username' , 'ASC' )
-> addOrderBy ( 'u.username' , 'DESC' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY u.username ASC, u.username DESC' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testGetQuery ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
2009-07-10 01:56:34 +04:00
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' );
$q = $qb -> getQuery ();
2009-07-09 08:18:58 +04:00
2009-07-10 22:26:43 +04:00
$this -> assertEquals ( 'Doctrine\ORM\Query' , get_class ( $q ));
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testSetParameter ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-07-10 01:56:34 +04:00
-> where ( 'u.id = :id' )
-> setParameter ( 'id' , 1 );
2009-07-09 08:18:58 +04:00
2009-07-10 22:26:43 +04:00
$this -> assertEquals ( array ( 'id' => 1 ), $qb -> getParameters ());
2009-07-09 08:18:58 +04:00
}
2009-07-10 01:56:34 +04:00
public function testSetParameters ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
2009-07-10 01:56:34 +04:00
-> where ( 'u.username = :username OR u.username = :username2' );
2009-07-09 08:18:58 +04:00
2009-07-10 01:56:34 +04:00
$qb -> setParameters ( array ( 'username' => 'jwage' , 'username2' => 'jonwage' ));
2009-07-09 08:18:58 +04:00
2009-07-10 22:26:43 +04:00
$this -> assertEquals ( array ( 'username' => 'jwage' , 'username2' => 'jonwage' ), $qb -> getQuery () -> getParameters ());
2009-07-09 08:18:58 +04:00
}
2009-07-10 21:53:48 +04:00
public function testGetParameters ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 21:53:48 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> where ( 'u.id = :id' );
$qb -> setParameters ( array ( 'id' => 1 ));
$this -> assertEquals ( array ( 'id' => 1 , 'test' => 1 ), $qb -> getParameters ( array ( 'test' => 1 )));
}
public function testGetParameter ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 21:53:48 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> where ( 'u.id = :id' );
$qb -> setParameters ( array ( 'id' => 1 ));
$this -> assertEquals ( 1 , $qb -> getParameter ( 'id' ));
}
2009-07-10 18:02:06 +04:00
public function testMultipleWhere ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
2009-07-10 18:02:06 +04:00
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> where ( 'u.id = :uid' , 'u.id = :uid2' );
2009-07-09 08:18:58 +04:00
2009-07-10 18:02:06 +04:00
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND (u.id = :uid2)' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 18:02:06 +04:00
public function testMultipleAndWhere ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
2009-07-10 18:02:06 +04:00
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> andWhere ( 'u.id = :uid' , 'u.id = :uid2' );
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND (u.id = :uid2)' );
}
public function testMultipleOrWhere ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 18:02:06 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> orWhere ( 'u.id = :uid' , 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 )));
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-10 18:02:06 +04:00
-> select ( 'u' )
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' )
-> where ( $orExpr );
$this -> assertValidQueryBuilder ( $qb , 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE ((u.id = :uid3) OR (u.id IN(1)))' );
2009-07-09 08:18:58 +04:00
}
2009-07-10 21:53:48 +04:00
public function testGetEntityManager ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ();
2009-07-10 21:53:48 +04:00
$this -> assertEquals ( $this -> _em , $qb -> getEntityManager ());
}
public function testInitialStateIsClean ()
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ();
2009-07-10 21:53:48 +04:00
$this -> assertEquals ( QueryBuilder :: STATE_CLEAN , $qb -> getState ());
}
public function testAlteringQueryChangesStateToDirty ()
2009-07-09 08:18:58 +04:00
{
2009-07-10 22:26:43 +04:00
$qb = $this -> _em -> createQueryBuilder ()
2009-07-09 08:18:58 +04:00
-> select ( 'u' )
2009-07-10 21:53:48 +04:00
-> from ( 'Doctrine\Tests\Models\CMS\CmsUser' , 'u' );
2009-07-09 08:18:58 +04:00
2009-07-10 21:53:48 +04:00
$this -> assertEquals ( QueryBuilder :: STATE_DIRTY , $qb -> getState ());
2009-07-09 08:18:58 +04:00
}
}