[2.0] Cleanup on QueryBuilder and Expr from discussion with roman
This commit is contained in:
parent
f608dd8a72
commit
ba8b4337bb
@ -262,11 +262,13 @@ class EntityManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Implementation.
|
||||
* Create a QueryBuilder instance
|
||||
*
|
||||
* @return QueryBuilder $qb
|
||||
*/
|
||||
public function createQueryBuilder()
|
||||
{
|
||||
//...
|
||||
return new QueryBuilder($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -291,7 +291,6 @@ final class Query extends AbstractQuery
|
||||
*/
|
||||
public function setDql($dqlQuery)
|
||||
{
|
||||
$this->free();
|
||||
if ($dqlQuery !== null) {
|
||||
$this->_dql = $dqlQuery;
|
||||
$this->_state = self::STATE_DIRTY;
|
||||
|
43
lib/Doctrine/ORM/Query/Expr/Having.php
Normal file
43
lib/Doctrine/ORM/Query/Expr/Having.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?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'
|
||||
);
|
||||
}
|
@ -79,28 +79,14 @@ class QueryBuilder
|
||||
private $_dql;
|
||||
|
||||
/**
|
||||
* @var array $params Parameters of this query.
|
||||
* @var Query $q The Query instance used for this QueryBuilder
|
||||
*/
|
||||
private $_params = array();
|
||||
|
||||
/**
|
||||
* @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;
|
||||
private $_q;
|
||||
|
||||
public function __construct(EntityManager $entityManager)
|
||||
{
|
||||
$this->_em = $entityManager;
|
||||
}
|
||||
|
||||
public static function create(EntityManager $entityManager)
|
||||
{
|
||||
return new self($entityManager);
|
||||
$this->_q = $entityManager->createQuery();
|
||||
}
|
||||
|
||||
public function getType()
|
||||
@ -148,18 +134,9 @@ class QueryBuilder
|
||||
|
||||
public function getQuery()
|
||||
{
|
||||
$q = new Query($this->_em);
|
||||
$q->setDql($this->getDql());
|
||||
$q->setParameters($this->getParameters());
|
||||
$q->setFirstResult($this->getFirstResult());
|
||||
$q->setMaxResults($this->getMaxResults());
|
||||
$this->_q->setDql($this->getDql());
|
||||
|
||||
return $q;
|
||||
}
|
||||
|
||||
public function execute($params = array(), $hydrationMode = null)
|
||||
{
|
||||
return $this->getQuery()->execute($params, $hydrationMode);
|
||||
return $this->_q;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -170,7 +147,7 @@ class QueryBuilder
|
||||
*/
|
||||
public function setParameter($key, $value)
|
||||
{
|
||||
$this->_params[$key] = $value;
|
||||
$this->_q->setParameter($key, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -182,9 +159,7 @@ class QueryBuilder
|
||||
*/
|
||||
public function setParameters(array $params)
|
||||
{
|
||||
foreach ($params as $key => $value) {
|
||||
$this->setParameter($key, $value);
|
||||
}
|
||||
$this->_q->setParameters($params);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -196,10 +171,7 @@ class QueryBuilder
|
||||
*/
|
||||
public function getParameters($params = array())
|
||||
{
|
||||
if ($params) {
|
||||
return array_merge($this->_params, $params);
|
||||
}
|
||||
return $this->_params;
|
||||
return $this->_q->getParameters($params);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,7 +182,7 @@ class QueryBuilder
|
||||
*/
|
||||
public function getParameter($key)
|
||||
{
|
||||
return isset($this->_params[$key]) ? $this->_params[$key] : null;
|
||||
return $this->_q->getParameter($key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -400,52 +372,6 @@ class QueryBuilder
|
||||
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
|
||||
*
|
||||
|
@ -34,7 +34,6 @@ class AllTests
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneSelfReferentialAssociationTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToManySelfReferentialAssociationTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ManyToManySelfReferentialAssociationTest');
|
||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\QueryBuilderTest');
|
||||
|
||||
return $suite;
|
||||
}
|
||||
|
@ -1,73 +0,0 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
@ -58,7 +58,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testSelectSetsType()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->select('u.id', 'u.username');
|
||||
|
||||
@ -67,7 +67,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testEmptySelectSetsType()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->delete('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->select();
|
||||
|
||||
@ -76,7 +76,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testDeleteSetsType()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->delete();
|
||||
|
||||
@ -85,7 +85,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testUpdateSetsType()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->update();
|
||||
|
||||
@ -94,7 +94,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testSimpleSelect()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->select('u.id', 'u.username');
|
||||
|
||||
@ -103,7 +103,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testSimpleDelete()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->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
|
||||
|
||||
public function testSimpleUpdate()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->update('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->set('u.username', ':username');
|
||||
|
||||
@ -120,7 +120,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testInnerJoin()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u', 'a')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->innerJoin('u', 'articles', 'a');
|
||||
@ -130,7 +130,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testLeftJoin()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u', 'a')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->leftJoin('u', 'articles', 'a');
|
||||
@ -140,7 +140,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testWhere()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :uid');
|
||||
@ -150,7 +150,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testAndWhere()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :uid')
|
||||
@ -161,7 +161,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testOrWhere()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :uid')
|
||||
@ -172,7 +172,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testAndWhereIn()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :uid')
|
||||
@ -183,7 +183,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testOrWhereIn()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :uid')
|
||||
@ -194,7 +194,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testAndWhereNotIn()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :uid')
|
||||
@ -205,7 +205,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testOrWhereNotIn()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :uid')
|
||||
@ -216,7 +216,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testGroupBy()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->groupBy('u.id')
|
||||
@ -227,7 +227,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testHaving()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->groupBy('u.id')
|
||||
@ -238,7 +238,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testAndHaving()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->groupBy('u.id')
|
||||
@ -250,7 +250,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testOrHaving()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->groupBy('u.id')
|
||||
@ -263,7 +263,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testOrderBy()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->orderBy('u.username', 'ASC');
|
||||
@ -273,7 +273,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testAddOrderBy()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->orderBy('u.username', 'ASC')
|
||||
@ -284,45 +284,41 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testGetQuery()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
||||
$q = $qb->getQuery();
|
||||
|
||||
$this->assertEquals(get_class($q), 'Doctrine\ORM\Query');
|
||||
$this->assertEquals('Doctrine\ORM\Query', get_class($q));
|
||||
}
|
||||
|
||||
public function testSetParameter()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :id')
|
||||
->setParameter('id', 1);
|
||||
|
||||
$q = $qb->getQuery();
|
||||
|
||||
$this->assertEquals($q->getParameters(), array('id' => 1));
|
||||
$this->assertEquals(array('id' => 1), $qb->getParameters());
|
||||
}
|
||||
|
||||
public function testSetParameters()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.username = :username OR u.username = :username2');
|
||||
|
||||
$qb->setParameters(array('username' => 'jwage', 'username2' => 'jonwage'));
|
||||
|
||||
$q = $qb->getQuery();
|
||||
|
||||
$this->assertEquals($q->getParameters(), array('username' => 'jwage', 'username2' => 'jonwage'));
|
||||
$this->assertEquals(array('username' => 'jwage', 'username2' => 'jonwage'), $qb->getQuery()->getParameters());
|
||||
}
|
||||
|
||||
|
||||
public function testGetParameters()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :id');
|
||||
@ -333,7 +329,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testGetParameter()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :id');
|
||||
@ -344,7 +340,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testMultipleWhere()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where('u.id = :uid', 'u.id = :uid2');
|
||||
@ -354,7 +350,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testMultipleAndWhere()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->andWhere('u.id = :uid', 'u.id = :uid2');
|
||||
@ -364,7 +360,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testMultipleOrWhere()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->orWhere('u.id = :uid', Expr::eq('u.id', ':uid2'));
|
||||
@ -378,7 +374,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
$orExpr->add(Expr::eq('u.id', ':uid3'));
|
||||
$orExpr->add(Expr::in('u.id', array(1)));
|
||||
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
|
||||
->where($orExpr);
|
||||
@ -388,19 +384,19 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
public function testGetEntityManager()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em);
|
||||
$qb = $this->_em->createQueryBuilder();
|
||||
$this->assertEquals($this->_em, $qb->getEntityManager());
|
||||
}
|
||||
|
||||
public function testInitialStateIsClean()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em);
|
||||
$qb = $this->_em->createQueryBuilder();
|
||||
$this->assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState());
|
||||
}
|
||||
|
||||
public function testAlteringQueryChangesStateToDirty()
|
||||
{
|
||||
$qb = QueryBuilder::create($this->_em)
|
||||
$qb = $this->_em->createQueryBuilder()
|
||||
->select('u')
|
||||
->from('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user