[2.0] Fixed E_NOTICE being throwing when ->getSingleScalarResult() is called and no result is found. Added coverage for this and also for multiple result (NonUniqueResultException).
This commit is contained in:
parent
12c9ca971b
commit
f3d91b9ea9
@ -36,7 +36,11 @@ class SingleScalarHydrator extends AbstractHydrator
|
|||||||
{
|
{
|
||||||
$cache = array();
|
$cache = array();
|
||||||
$result = $this->_stmt->fetchAll(\PDO::FETCH_ASSOC);
|
$result = $this->_stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
if (count($result) > 1 || count($result[key($result)]) > 1) {
|
$num = count($result);
|
||||||
|
|
||||||
|
if ($num == 0) {
|
||||||
|
throw new \Doctrine\ORM\NoResultException;
|
||||||
|
} else if ($num > 1 || count($result[key($result)]) > 1) {
|
||||||
throw new \Doctrine\ORM\NonUniqueResultException;
|
throw new \Doctrine\ORM\NonUniqueResultException;
|
||||||
}
|
}
|
||||||
$result = $this->_gatherScalarRowData($result[key($result)], $cache);
|
$result = $this->_gatherScalarRowData($result[key($result)], $cache);
|
||||||
|
@ -224,7 +224,47 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
public function testGetSingleResultThrowsExceptionOnNoResult()
|
public function testGetSingleResultThrowsExceptionOnNoResult()
|
||||||
{
|
{
|
||||||
$this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a")
|
$this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a")
|
||||||
->getSingleResult();
|
->getSingleResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Doctrine\ORM\NoResultException
|
||||||
|
*/
|
||||||
|
public function testGetSingleScalarResultThrowsExceptionOnNoResult()
|
||||||
|
{
|
||||||
|
$this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a")
|
||||||
|
->getSingleScalarResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Doctrine\ORM\NonUniqueResultException
|
||||||
|
*/
|
||||||
|
public function testGetSingleScalarResultThrowsExceptionOnNonUniqueResult()
|
||||||
|
{
|
||||||
|
$user = new CmsUser;
|
||||||
|
$user->name = 'Guilherme';
|
||||||
|
$user->username = 'gblanco';
|
||||||
|
$user->status = 'developer';
|
||||||
|
|
||||||
|
$article1 = new CmsArticle;
|
||||||
|
$article1->topic = "Doctrine 2";
|
||||||
|
$article1->text = "This is an introduction to Doctrine 2.";
|
||||||
|
$user->addArticle($article1);
|
||||||
|
|
||||||
|
$article2 = new CmsArticle;
|
||||||
|
$article2->topic = "Symfony 2";
|
||||||
|
$article2->text = "This is an introduction to Symfony 2.";
|
||||||
|
$user->addArticle($article2);
|
||||||
|
|
||||||
|
$this->_em->persist($user);
|
||||||
|
$this->_em->persist($article1);
|
||||||
|
$this->_em->persist($article2);
|
||||||
|
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a")
|
||||||
|
->getSingleScalarResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSupportsQueriesWithEntityNamespaces()
|
public function testSupportsQueriesWithEntityNamespaces()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user