From 0af5da77f1ddddb3320f126e5e675dfafcf92f0e Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Sat, 19 May 2012 13:40:01 -0300 Subject: [PATCH] fix DDC-1822 --- lib/Doctrine/ORM/NoResultException.php | 2 +- lib/Doctrine/ORM/NonUniqueResultException.php | 5 ++- .../ORM/UnexpectedResultException.php | 31 ++++++++++++++++ .../Tests/ORM/Functional/QueryTest.php | 37 +++++++++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 lib/Doctrine/ORM/UnexpectedResultException.php diff --git a/lib/Doctrine/ORM/NoResultException.php b/lib/Doctrine/ORM/NoResultException.php index eb31f7cc9..6bcf50bb0 100644 --- a/lib/Doctrine/ORM/NoResultException.php +++ b/lib/Doctrine/ORM/NoResultException.php @@ -25,7 +25,7 @@ namespace Doctrine\ORM; * @author robo * @since 2.0 */ -class NoResultException extends ORMException +class NoResultException extends UnexpectedResultException { public function __construct() { diff --git a/lib/Doctrine/ORM/NonUniqueResultException.php b/lib/Doctrine/ORM/NonUniqueResultException.php index 1a3a8b7eb..cc226da9c 100644 --- a/lib/Doctrine/ORM/NonUniqueResultException.php +++ b/lib/Doctrine/ORM/NonUniqueResultException.php @@ -25,4 +25,7 @@ namespace Doctrine\ORM; * @author robo * @since 2.0 */ -class NonUniqueResultException extends ORMException {} \ No newline at end of file +class NonUniqueResultException extends UnexpectedResultException +{ + +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/UnexpectedResultException.php b/lib/Doctrine/ORM/UnexpectedResultException.php new file mode 100644 index 000000000..148ff681a --- /dev/null +++ b/lib/Doctrine/ORM/UnexpectedResultException.php @@ -0,0 +1,31 @@ +. + */ + +namespace Doctrine\ORM; + +/** + * Exception for a unexpected query result. + * + * @author Fabio B. Silva + * @since 2.3 + */ +class UnexpectedResultException extends ORMException +{ + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php index b19a8a6d2..7ac2d1e02 100644 --- a/tests/Doctrine/Tests/ORM/Functional/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/QueryTest.php @@ -619,4 +619,41 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals($userC->id, $q->getParameter(1)); } + + + /** + * @group DDC-1822 + */ + public function testUnexpectedResultException() + { + $dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u"; + $u1 = new CmsUser; + $u2 = new CmsUser; + $u1->name = 'Fabio B. Silva'; + $u1->username = 'FabioBatSilva'; + $u1->status = 'developer'; + $u2->name = 'Test'; + $u2->username = 'test'; + $u2->status = 'tester'; + + try { + $this->_em->createQuery($dql)->getSingleResult(); + $this->fail('Expected exception "\Doctrine\ORM\NoResultException".'); + } catch (\Doctrine\ORM\UnexpectedResultException $exc) { + $this->assertInstanceOf('\Doctrine\ORM\NoResultException', $exc); + } + + + $this->_em->persist($u1); + $this->_em->persist($u2); + $this->_em->flush(); + $this->_em->clear(); + + try { + $this->_em->createQuery($dql)->getSingleResult(); + $this->fail('Expected exception "\Doctrine\ORM\NonUniqueResultException".'); + } catch (\Doctrine\ORM\UnexpectedResultException $exc) { + $this->assertInstanceOf('\Doctrine\ORM\NonUniqueResultException', $exc); + } + } }