Commit ba8b4337 authored by jwage's avatar jwage

[2.0] Cleanup on QueryBuilder and Expr from discussion with roman

parent f608dd8a
...@@ -262,11 +262,13 @@ class EntityManager ...@@ -262,11 +262,13 @@ class EntityManager
} }
/** /**
* @todo Implementation. * Create a QueryBuilder instance
*
* @return QueryBuilder $qb
*/ */
public function createQueryBuilder() public function createQueryBuilder()
{ {
//... return new QueryBuilder($this);
} }
/** /**
......
...@@ -291,7 +291,6 @@ final class Query extends AbstractQuery ...@@ -291,7 +291,6 @@ final class Query extends AbstractQuery
*/ */
public function setDql($dqlQuery) public function setDql($dqlQuery)
{ {
$this->free();
if ($dqlQuery !== null) { if ($dqlQuery !== null) {
$this->_dql = $dqlQuery; $this->_dql = $dqlQuery;
$this->_state = self::STATE_DIRTY; $this->_state = self::STATE_DIRTY;
......
<?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\ORM\Query\Expr;
/**
* Expression class for building DQL Having parts
*
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Guilherme Blanco <guilhermeblanco@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Having extends Base
{
protected $_preSeparator = '';
protected $_postSeparator = '';
protected $_allowedClasses = array(
'Doctrine\ORM\Query\Expr\Comparison',
'Doctrine\ORM\Query\Expr\Orx',
'Doctrine\ORM\Query\Expr\Func'
);
}
\ No newline at end of file
...@@ -79,28 +79,14 @@ class QueryBuilder ...@@ -79,28 +79,14 @@ class QueryBuilder
private $_dql; private $_dql;
/** /**
* @var array $params Parameters of this query. * @var Query $q The Query instance used for this QueryBuilder
*/ */
private $_params = array(); private $_q;
/**
* @var integer The first result to return (the "offset").
*/
private $_firstResult = null;
/**
* @var integer The maximum number of results to return (the "limit").
*/
private $_maxResults = null;
public function __construct(EntityManager $entityManager) public function __construct(EntityManager $entityManager)
{ {
$this->_em = $entityManager; $this->_em = $entityManager;
} $this->_q = $entityManager->createQuery();
public static function create(EntityManager $entityManager)
{
return new self($entityManager);
} }
public function getType() public function getType()
...@@ -148,18 +134,9 @@ class QueryBuilder ...@@ -148,18 +134,9 @@ class QueryBuilder
public function getQuery() public function getQuery()
{ {
$q = new Query($this->_em); $this->_q->setDql($this->getDql());
$q->setDql($this->getDql());
$q->setParameters($this->getParameters());
$q->setFirstResult($this->getFirstResult());
$q->setMaxResults($this->getMaxResults());
return $q;
}
public function execute($params = array(), $hydrationMode = null) return $this->_q;
{
return $this->getQuery()->execute($params, $hydrationMode);
} }
/** /**
...@@ -170,7 +147,7 @@ class QueryBuilder ...@@ -170,7 +147,7 @@ class QueryBuilder
*/ */
public function setParameter($key, $value) public function setParameter($key, $value)
{ {
$this->_params[$key] = $value; $this->_q->setParameter($key, $value);
return $this; return $this;
} }
...@@ -182,9 +159,7 @@ class QueryBuilder ...@@ -182,9 +159,7 @@ class QueryBuilder
*/ */
public function setParameters(array $params) public function setParameters(array $params)
{ {
foreach ($params as $key => $value) { $this->_q->setParameters($params);
$this->setParameter($key, $value);
}
return $this; return $this;
} }
...@@ -196,10 +171,7 @@ class QueryBuilder ...@@ -196,10 +171,7 @@ class QueryBuilder
*/ */
public function getParameters($params = array()) public function getParameters($params = array())
{ {
if ($params) { return $this->_q->getParameters($params);
return array_merge($this->_params, $params);
}
return $this->_params;
} }
/** /**
...@@ -210,7 +182,7 @@ class QueryBuilder ...@@ -210,7 +182,7 @@ class QueryBuilder
*/ */
public function getParameter($key) public function getParameter($key)
{ {
return isset($this->_params[$key]) ? $this->_params[$key] : null; return $this->_q->getParameter($key);
} }
/** /**
...@@ -400,52 +372,6 @@ class QueryBuilder ...@@ -400,52 +372,6 @@ class QueryBuilder
return $this->add('orderBy', Expr::orderBy($sort, $order), true); return $this->add('orderBy', Expr::orderBy($sort, $order), true);
} }
/**
* Sets the position of the first result to retrieve (the "offset").
*
* @param integer $firstResult The first result to return.
* @return Query This query object.
*/
public function setFirstResult($firstResult)
{
$this->_firstResult = $firstResult;
return $this;
}
/**
* Gets the position of the first result the query object was set to retrieve (the "offset").
* Returns NULL if {@link setFirstResult} was not applied to this query.
*
* @return integer The position of the first result.
*/
public function getFirstResult()
{
return $this->_firstResult;
}
/**
* Sets the maximum number of results to retrieve (the "limit").
*
* @param integer $maxResults
* @return Query This query object.
*/
public function setMaxResults($maxResults)
{
$this->_maxResults = $maxResults;
return $this;
}
/**
* Gets the maximum number of results the query object was set to retrieve (the "limit").
* Returns NULL if {@link setMaxResults} was not applied to this query.
*
* @return integer Maximum number of results.
*/
public function getMaxResults()
{
return $this->_maxResults;
}
/** /**
* Get the DQL query string for DELETE queries * Get the DQL query string for DELETE queries
* *
......
...@@ -34,7 +34,6 @@ class AllTests ...@@ -34,7 +34,6 @@ class AllTests
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneSelfReferentialAssociationTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneSelfReferentialAssociationTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToManySelfReferentialAssociationTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToManySelfReferentialAssociationTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ManyToManySelfReferentialAssociationTest'); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\ManyToManySelfReferentialAssociationTest');
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\QueryBuilderTest');
return $suite; return $suite;
} }
......
<?php
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\ORM\QueryBuilder;
require_once __DIR__ . '/../../TestInit.php';
class QueryBuilderTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
$this->useModelSet('cms');
parent::setUp();
}
public function testExecute()
{
$qb = QueryBuilder::create($this->_em)
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u');
$results = $qb->execute();
$this->assertEquals('Doctrine\Common\Collections\Collection', get_class($results));
}
public function testSetMaxResultsAndSetFirstResultZero()
{
$qb = QueryBuilder::create($this->_em)
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->setMaxResults(10)
->setFirstResult(0);
$this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ OFFSET 0 LIMIT 10', $qb->getQuery()->getSql());
}
public function testSetMaxResultsAndSetFirstResult()
{
$qb = QueryBuilder::create($this->_em)
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->setMaxResults(10)
->setFirstResult(10);
$this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ OFFSET 10 LIMIT 10', $qb->getQuery()->getSql());
}
public function testRemoveSetMaxResultsAndSetFirstResult()
{
$qb = QueryBuilder::create($this->_em)
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->setMaxResults(10)
->setFirstResult(0)
->setMaxResults(null)
->setFirstResult(null);
$this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_', $qb->getQuery()->getSql());
}
public function testOnlyFirstResult()
{
$qb = QueryBuilder::create($this->_em)
->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->setMaxResults(10);
$this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ LIMIT 10', $qb->getQuery()->getSql());
}
}
\ No newline at end of file
...@@ -58,7 +58,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -58,7 +58,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testSelectSetsType() public function testSelectSetsType()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->select('u.id', 'u.username'); ->select('u.id', 'u.username');
...@@ -67,7 +67,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -67,7 +67,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testEmptySelectSetsType() public function testEmptySelectSetsType()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->select(); ->select();
...@@ -76,7 +76,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -76,7 +76,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testDeleteSetsType() public function testDeleteSetsType()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->delete(); ->delete();
...@@ -85,7 +85,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -85,7 +85,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testUpdateSetsType() public function testUpdateSetsType()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->update(); ->update();
...@@ -94,7 +94,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -94,7 +94,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testSimpleSelect() public function testSimpleSelect()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->select('u.id', 'u.username'); ->select('u.id', 'u.username');
...@@ -103,7 +103,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -103,7 +103,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testSimpleDelete() public function testSimpleDelete()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u'); ->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u');
$this->assertValidQueryBuilder($qb, 'DELETE Doctrine\Tests\Models\CMS\CmsUser u'); $this->assertValidQueryBuilder($qb, 'DELETE Doctrine\Tests\Models\CMS\CmsUser u');
...@@ -111,7 +111,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -111,7 +111,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testSimpleUpdate() public function testSimpleUpdate()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->update('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->update('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->set('u.username', ':username'); ->set('u.username', ':username');
...@@ -120,7 +120,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -120,7 +120,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testInnerJoin() public function testInnerJoin()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u', 'a') ->select('u', 'a')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->innerJoin('u', 'articles', 'a'); ->innerJoin('u', 'articles', 'a');
...@@ -130,7 +130,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -130,7 +130,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testLeftJoin() public function testLeftJoin()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u', 'a') ->select('u', 'a')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->leftJoin('u', 'articles', 'a'); ->leftJoin('u', 'articles', 'a');
...@@ -140,7 +140,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -140,7 +140,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testWhere() public function testWhere()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid'); ->where('u.id = :uid');
...@@ -150,7 +150,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -150,7 +150,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAndWhere() public function testAndWhere()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid') ->where('u.id = :uid')
...@@ -161,7 +161,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -161,7 +161,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testOrWhere() public function testOrWhere()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid') ->where('u.id = :uid')
...@@ -172,7 +172,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -172,7 +172,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAndWhereIn() public function testAndWhereIn()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid') ->where('u.id = :uid')
...@@ -183,7 +183,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -183,7 +183,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testOrWhereIn() public function testOrWhereIn()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid') ->where('u.id = :uid')
...@@ -194,7 +194,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -194,7 +194,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAndWhereNotIn() public function testAndWhereNotIn()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid') ->where('u.id = :uid')
...@@ -205,7 +205,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -205,7 +205,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testOrWhereNotIn() public function testOrWhereNotIn()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid') ->where('u.id = :uid')
...@@ -216,7 +216,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -216,7 +216,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testGroupBy() public function testGroupBy()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->groupBy('u.id') ->groupBy('u.id')
...@@ -227,7 +227,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -227,7 +227,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testHaving() public function testHaving()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->groupBy('u.id') ->groupBy('u.id')
...@@ -238,7 +238,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -238,7 +238,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAndHaving() public function testAndHaving()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->groupBy('u.id') ->groupBy('u.id')
...@@ -250,7 +250,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -250,7 +250,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testOrHaving() public function testOrHaving()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->groupBy('u.id') ->groupBy('u.id')
...@@ -263,7 +263,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -263,7 +263,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testOrderBy() public function testOrderBy()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->orderBy('u.username', 'ASC'); ->orderBy('u.username', 'ASC');
...@@ -273,7 +273,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -273,7 +273,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAddOrderBy() public function testAddOrderBy()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->orderBy('u.username', 'ASC') ->orderBy('u.username', 'ASC')
...@@ -284,45 +284,41 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -284,45 +284,41 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testGetQuery() public function testGetQuery()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u');
$q = $qb->getQuery(); $q = $qb->getQuery();
$this->assertEquals(get_class($q), 'Doctrine\ORM\Query'); $this->assertEquals('Doctrine\ORM\Query', get_class($q));
} }
public function testSetParameter() public function testSetParameter()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :id') ->where('u.id = :id')
->setParameter('id', 1); ->setParameter('id', 1);
$q = $qb->getQuery(); $this->assertEquals(array('id' => 1), $qb->getParameters());
$this->assertEquals($q->getParameters(), array('id' => 1));
} }
public function testSetParameters() public function testSetParameters()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.username = :username OR u.username = :username2'); ->where('u.username = :username OR u.username = :username2');
$qb->setParameters(array('username' => 'jwage', 'username2' => 'jonwage')); $qb->setParameters(array('username' => 'jwage', 'username2' => 'jonwage'));
$q = $qb->getQuery(); $this->assertEquals(array('username' => 'jwage', 'username2' => 'jonwage'), $qb->getQuery()->getParameters());
$this->assertEquals($q->getParameters(), array('username' => 'jwage', 'username2' => 'jonwage'));
} }
public function testGetParameters() public function testGetParameters()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :id'); ->where('u.id = :id');
...@@ -333,7 +329,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -333,7 +329,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testGetParameter() public function testGetParameter()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :id'); ->where('u.id = :id');
...@@ -344,7 +340,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -344,7 +340,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testMultipleWhere() public function testMultipleWhere()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where('u.id = :uid', 'u.id = :uid2'); ->where('u.id = :uid', 'u.id = :uid2');
...@@ -354,7 +350,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -354,7 +350,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testMultipleAndWhere() public function testMultipleAndWhere()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->andWhere('u.id = :uid', 'u.id = :uid2'); ->andWhere('u.id = :uid', 'u.id = :uid2');
...@@ -364,7 +360,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -364,7 +360,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testMultipleOrWhere() public function testMultipleOrWhere()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->orWhere('u.id = :uid', Expr::eq('u.id', ':uid2')); ->orWhere('u.id = :uid', Expr::eq('u.id', ':uid2'));
...@@ -378,7 +374,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -378,7 +374,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
$orExpr->add(Expr::eq('u.id', ':uid3')); $orExpr->add(Expr::eq('u.id', ':uid3'));
$orExpr->add(Expr::in('u.id', array(1))); $orExpr->add(Expr::in('u.id', array(1)));
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
->where($orExpr); ->where($orExpr);
...@@ -388,19 +384,19 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ...@@ -388,19 +384,19 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testGetEntityManager() public function testGetEntityManager()
{ {
$qb = QueryBuilder::create($this->_em); $qb = $this->_em->createQueryBuilder();
$this->assertEquals($this->_em, $qb->getEntityManager()); $this->assertEquals($this->_em, $qb->getEntityManager());
} }
public function testInitialStateIsClean() public function testInitialStateIsClean()
{ {
$qb = QueryBuilder::create($this->_em); $qb = $this->_em->createQueryBuilder();
$this->assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState()); $this->assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState());
} }
public function testAlteringQueryChangesStateToDirty() public function testAlteringQueryChangesStateToDirty()
{ {
$qb = QueryBuilder::create($this->_em) $qb = $this->_em->createQueryBuilder()
->select('u') ->select('u')
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u'); ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u');
......
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