1
0
mirror of synced 2025-01-18 06:21:40 +03:00

Fix tests after merge of QueryBuilder#addCriteria changes.

This commit is contained in:
Benjamin Eberlei 2014-01-03 21:28:06 +01:00
parent 5828e4c67c
commit c8c7cf0528
2 changed files with 35 additions and 14 deletions

View File

@ -283,12 +283,18 @@ class QueryBuilder
* </code>
*
* @deprecated Please use $qb->getRootAliases() instead.
* @throws RuntimeException
*
* @return string
*/
public function getRootAlias()
{
$aliases = $this->getRootAliases();
if ( ! isset($aliases[0])) {
throw new \RuntimeException('No alias was set before invoking getRootAlias().');
}
return $aliases[0];
}

View File

@ -417,10 +417,17 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAddMultipleSameCriteriaWhere()
{
$qb = $this->_em->createQueryBuilder();
$qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1');
$criteria = new Criteria();
$criteria->where($criteria->expr()->andX($criteria->expr()->eq('field', 'value1'), $criteria->expr()->eq('field', 'value2')));
$criteria->where($criteria->expr()->andX(
$criteria->expr()->eq('field', 'value1'),
$criteria->expr()->eq('field', 'value2')
));
$qb->addCriteria($criteria);
$this->assertEquals('field = :field AND field = :field_1', (string) $qb->getDQLPart('where'));
$this->assertEquals('alias1.field = :field AND alias1.field = :field_1', (string) $qb->getDQLPart('where'));
$this->assertNotNull($qb->getParameter('field'));
$this->assertNotNull($qb->getParameter('field_1'));
}
@ -431,13 +438,15 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAddCriteriaWhereWithMultipleParametersWithSameField()
{
$qb = $this->_em->createQueryBuilder();
$qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1');
$criteria = new Criteria();
$criteria->where($criteria->expr()->eq('field', 'value1'));
$criteria->andWhere($criteria->expr()->gt('field', 'value2'));
$qb->addCriteria($criteria);
$this->assertEquals('field = :field AND field > :field_1', (string) $qb->getDQLPart('where'));
$this->assertEquals('alias1.field = :field AND alias1.field > :field_1', (string) $qb->getDQLPart('where'));
$this->assertSame('value1', $qb->getParameter('field')->getValue());
$this->assertSame('value2', $qb->getParameter('field_1')->getValue());
}
@ -448,13 +457,15 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAddCriteriaWhereWithMultipleParametersWithDifferentFields()
{
$qb = $this->_em->createQueryBuilder();
$qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1');
$criteria = new Criteria();
$criteria->where($criteria->expr()->eq('field1', 'value1'));
$criteria->andWhere($criteria->expr()->gt('field2', 'value2'));
$qb->addCriteria($criteria);
$this->assertEquals('field1 = :field1 AND field2 > :field2', (string) $qb->getDQLPart('where'));
$this->assertEquals('alias1.field1 = :field1 AND alias1.field2 > :field2', (string) $qb->getDQLPart('where'));
$this->assertSame('value1', $qb->getParameter('field1')->getValue());
$this->assertSame('value2', $qb->getParameter('field2')->getValue());
}
@ -465,15 +476,17 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAddCriteriaWhereWithMultipleParametersWithSubpathsAndDifferentProperties()
{
$qb = $this->_em->createQueryBuilder();
$qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1');
$criteria = new Criteria();
$criteria->where($criteria->expr()->eq('alias1.field1', 'value1'));
$criteria->andWhere($criteria->expr()->gt('alias1.field2', 'value2'));
$criteria->where($criteria->expr()->eq('field1', 'value1'));
$criteria->andWhere($criteria->expr()->gt('field2', 'value2'));
$qb->addCriteria($criteria);
$this->assertEquals('alias1.field1 = :alias1_field1 AND alias1.field2 > :alias1_field2', (string) $qb->getDQLPart('where'));
$this->assertSame('value1', $qb->getParameter('alias1_field1')->getValue());
$this->assertSame('value2', $qb->getParameter('alias1_field2')->getValue());
$this->assertEquals('alias1.field1 = :field1 AND alias1.field2 > :field2', (string) $qb->getDQLPart('where'));
$this->assertSame('value1', $qb->getParameter('field1')->getValue());
$this->assertSame('value2', $qb->getParameter('field2')->getValue());
}
/**
@ -482,15 +495,17 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
public function testAddCriteriaWhereWithMultipleParametersWithSubpathsAndSameProperty()
{
$qb = $this->_em->createQueryBuilder();
$qb->select('alias1')->from('Doctrine\Tests\Models\CMS\CmsUser', 'alias1');
$criteria = new Criteria();
$criteria->where($criteria->expr()->eq('alias1.field1', 'value1'));
$criteria->andWhere($criteria->expr()->gt('alias1.field1', 'value2'));
$criteria->where($criteria->expr()->eq('field1', 'value1'));
$criteria->andWhere($criteria->expr()->gt('field1', 'value2'));
$qb->addCriteria($criteria);
$this->assertEquals('alias1.field1 = :alias1_field1 AND alias1.field1 > :alias1_field1_1', (string) $qb->getDQLPart('where'));
$this->assertSame('value1', $qb->getParameter('alias1_field1')->getValue());
$this->assertSame('value2', $qb->getParameter('alias1_field1_1')->getValue());
$this->assertEquals('alias1.field1 = :field1 AND alias1.field1 > :field1_1', (string) $qb->getDQLPart('where'));
$this->assertSame('value1', $qb->getParameter('field1')->getValue());
$this->assertSame('value2', $qb->getParameter('field1_1')->getValue());
}
public function testAddCriteriaOrder()