1
0
mirror of synced 2025-01-31 12:32:59 +03:00

fix DDC-1822

This commit is contained in:
Fabio B. Silva 2012-05-19 13:40:01 -03:00
parent 4ef552e07a
commit 0af5da77f1
4 changed files with 73 additions and 2 deletions

View File

@ -25,7 +25,7 @@ namespace Doctrine\ORM;
* @author robo
* @since 2.0
*/
class NoResultException extends ORMException
class NoResultException extends UnexpectedResultException
{
public function __construct()
{

View File

@ -25,4 +25,7 @@ namespace Doctrine\ORM;
* @author robo
* @since 2.0
*/
class NonUniqueResultException extends ORMException {}
class NonUniqueResultException extends UnexpectedResultException
{
}

View File

@ -0,0 +1,31 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM;
/**
* Exception for a unexpected query result.
*
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
* @since 2.3
*/
class UnexpectedResultException extends ORMException
{
}

View File

@ -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);
}
}
}