DDC-749 - Refactor Query tests, add a test for setParameters()
This commit is contained in:
parent
4727489134
commit
ee9158ffb4
2 changed files with 34 additions and 20 deletions
|
@ -128,6 +128,13 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
$user = $q->getSingleResult();
|
$user = $q->getSingleResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetParameters()
|
||||||
|
{
|
||||||
|
$q = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name = ?1 AND u.status = ?2');
|
||||||
|
$q->setParameters(array(1 => 'jwage', 2 => 'active'));
|
||||||
|
$users = $q->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
public function testIterateResult_IterativelyBuildUpUnitOfWork()
|
public function testIterateResult_IterativelyBuildUpUnitOfWork()
|
||||||
{
|
{
|
||||||
$article1 = new CmsArticle;
|
$article1 = new CmsArticle;
|
||||||
|
@ -175,26 +182,6 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
$query = $this->_em->createQuery("SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a");
|
$query = $this->_em->createQuery("SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.articles a");
|
||||||
$articles = $query->iterate();
|
$articles = $query->iterate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFluentQueryInterface()
|
|
||||||
{
|
|
||||||
$q = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a");
|
|
||||||
$q2 = $q->expireQueryCache(true)
|
|
||||||
->setQueryCacheLifetime(3600)
|
|
||||||
->setQueryCacheDriver(null)
|
|
||||||
->expireResultCache(true)
|
|
||||||
->setHint('foo', 'bar')
|
|
||||||
->setHint('bar', 'baz')
|
|
||||||
->setParameter(1, 'bar')
|
|
||||||
->setParameters(array(2 => 'baz'))
|
|
||||||
->setResultCacheDriver(null)
|
|
||||||
->setResultCacheId('foo')
|
|
||||||
->setDql('foo')
|
|
||||||
->setFirstResult(10)
|
|
||||||
->setMaxResults(10);
|
|
||||||
|
|
||||||
$this->assertSame($q2, $q);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Doctrine\ORM\NoResultException
|
* @expectedException Doctrine\ORM\NoResultException
|
||||||
|
|
|
@ -35,6 +35,13 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase
|
||||||
$this->assertEquals(array(2 => 84), $query->getParameters());
|
$this->assertEquals(array(2 => 84), $query->getParameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetParameters()
|
||||||
|
{
|
||||||
|
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
|
||||||
|
$query->setParameters(array(1 => 'foo', 2 => 'bar'));
|
||||||
|
$this->assertEquals(array(1 => 'foo', 2 => 'bar'), $query->getParameters());
|
||||||
|
}
|
||||||
|
|
||||||
public function testFree()
|
public function testFree()
|
||||||
{
|
{
|
||||||
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
|
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
|
||||||
|
@ -59,4 +66,24 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase
|
||||||
$this->assertEquals(array(), $cloned->getParameters());
|
$this->assertEquals(array(), $cloned->getParameters());
|
||||||
$this->assertFalse($cloned->getHint('foo'));
|
$this->assertFalse($cloned->getHint('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFluentQueryInterface()
|
||||||
|
{
|
||||||
|
$q = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a");
|
||||||
|
$q2 = $q->expireQueryCache(true)
|
||||||
|
->setQueryCacheLifetime(3600)
|
||||||
|
->setQueryCacheDriver(null)
|
||||||
|
->expireResultCache(true)
|
||||||
|
->setHint('foo', 'bar')
|
||||||
|
->setHint('bar', 'baz')
|
||||||
|
->setParameter(1, 'bar')
|
||||||
|
->setParameters(array(2 => 'baz'))
|
||||||
|
->setResultCacheDriver(null)
|
||||||
|
->setResultCacheId('foo')
|
||||||
|
->setDql('foo')
|
||||||
|
->setFirstResult(10)
|
||||||
|
->setMaxResults(10);
|
||||||
|
|
||||||
|
$this->assertSame($q2, $q);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue