diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index dbd6e0c8261..894ab729dbc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -486,13 +486,35 @@ public function testGetSingleResultThrowsExceptionOnNoResult(): void public function testGetSingleScalarResultThrowsExceptionOnNoResult(): void { $this->expectException('Doctrine\ORM\NoResultException'); - $this->_em->createQuery('select a from Doctrine\Tests\Models\CMS\CmsArticle a') + $this->_em->createQuery('select a.id from Doctrine\Tests\Models\CMS\CmsArticle a') ->getSingleScalarResult(); } + public function testGetSingleScalarResultThrowsExceptionOnSingleRowWithMultipleColumns(): void + { + $user = new CmsUser(); + $user->name = 'Javier'; + $user->username = 'phansys'; + $user->status = 'developer'; + + $this->_em->persist($user); + + $this->_em->flush(); + $this->_em->clear(); + + $this->expectException(NonUniqueResultException::class); + $this->expectExceptionMessage( + 'The query returned a row containing multiple columns. Change the query or use a different result function' + . ' like getScalarResult().' + ); + + $this->_em->createQuery('select u from Doctrine\Tests\Models\CMS\CmsUser u') + ->setMaxResults(1) + ->getSingleScalarResult(); + } + public function testGetSingleScalarResultThrowsExceptionOnNonUniqueResult(): void { - $this->expectException('Doctrine\ORM\NonUniqueResultException'); $user = new CmsUser(); $user->name = 'Guilherme'; $user->username = 'gblanco'; @@ -515,7 +537,12 @@ public function testGetSingleScalarResultThrowsExceptionOnNonUniqueResult(): voi $this->_em->flush(); $this->_em->clear(); - $this->_em->createQuery('select a from Doctrine\Tests\Models\CMS\CmsArticle a') + $this->expectException(NonUniqueResultException::class); + $this->expectExceptionMessage( + 'The query returned multiple rows. Change the query or use a different result function like getScalarResult().' + ); + + $this->_em->createQuery('select a.id from Doctrine\Tests\Models\CMS\CmsArticle a') ->getSingleScalarResult(); }