Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and improve functional test cases expecting NonUniqueResultException from AbstractQuery::getSingleScalarResult() #10722

Merged
merged 1 commit into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions tests/Doctrine/Tests/ORM/Functional/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}

Expand Down