Skip to content

Commit

Permalink
Method hydrateAll() does not take into account possible
Browse files Browse the repository at this point in the history
exception from hydrateAllData() which in turn does not call
cleanup()
  • Loading branch information
olsavmic committed Feb 18, 2021
1 parent 0ae53a6 commit d684598
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
Expand Up @@ -205,12 +205,13 @@ public function hydrateAll($stmt, $resultSetMapping, array $hints = [])
$this->_hints = $hints;

$this->_em->getEventManager()->addEventListener([Events::onClear], $this);

$this->prepare();

$result = $this->hydrateAllData();

$this->cleanup();
try {
$result = $this->hydrateAllData();
} finally {
$this->cleanup();
}

return $result;
}
Expand Down
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php
Expand Up @@ -10,6 +10,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Events;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit_Framework_MockObject_MockObject;
Expand Down Expand Up @@ -106,4 +107,31 @@ public function testHydrateAllRegistersAndClearsAllAttachedListeners(): void

$this->hydrator->hydrateAll($this->mockStatement, $this->mockResultMapping);
}

/**
* @group #DDC-8482
*/
public function testHydrateAllClearsAllAttachedListenersEvenOnError(): void
{
$this
->mockEventManager
->expects(self::at(0))
->method('addEventListener')
->with([Events::onClear], $this->hydrator);

$this
->mockEventManager
->expects(self::at(1))
->method('removeEventListener')
->with([Events::onClear], $this->hydrator);

$this
->hydrator
->expects(self::once())
->method('hydrateAllData')
->willThrowException(new NoResultException());

$this->expectException(NoResultException::class);
$this->hydrator->hydrateAll($this->mockStatement, $this->mockResultMapping);
}
}

0 comments on commit d684598

Please sign in to comment.