fix DDC-1822
This commit is contained in:
parent
4ef552e07a
commit
0af5da77f1
@ -25,7 +25,7 @@ namespace Doctrine\ORM;
|
|||||||
* @author robo
|
* @author robo
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
class NoResultException extends ORMException
|
class NoResultException extends UnexpectedResultException
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -25,4 +25,7 @@ namespace Doctrine\ORM;
|
|||||||
* @author robo
|
* @author robo
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
class NonUniqueResultException extends ORMException {}
|
class NonUniqueResultException extends UnexpectedResultException
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
31
lib/Doctrine/ORM/UnexpectedResultException.php
Normal file
31
lib/Doctrine/ORM/UnexpectedResultException.php
Normal 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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -619,4 +619,41 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
$this->assertEquals($userC->id, $q->getParameter(1));
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user