1
0
mirror of synced 2025-02-02 13:31:45 +03:00

fix AbstractHydrator addEventListener on hydrateAll()

This commit is contained in:
Nikolas Tsiongas 2017-08-13 22:42:09 +02:00 committed by Marco Pivetta
parent f311dd1dd1
commit 814aa9f322
No known key found for this signature in database
GPG Key ID: 4167D3337FD9D629
2 changed files with 71 additions and 0 deletions

View File

@ -142,6 +142,9 @@ abstract class AbstractHydrator
$this->_rsm = $resultSetMapping; $this->_rsm = $resultSetMapping;
$this->_hints = $hints; $this->_hints = $hints;
$evm = $this->_em->getEventManager();
$evm->addEventListener(array(Events::onClear), $this);
$this->prepare(); $this->prepare();
$result = $this->hydrateAllData(); $result = $this->hydrateAllData();

View File

@ -0,0 +1,68 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\ORM\Events;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use Doctrine\Tests\OrmFunctionalTestCase;
/**
* @covers \Doctrine\ORM\Internal\Hydration\AbstractHydrator
*/
class AbstractHydratorTest extends OrmFunctionalTestCase
{
/**
* @group DDC-3146
* @group #1515
*
* Verify that the number of added events to the event listener from the abstract hydrator class is equal to the
* number of removed events
*/
public function testOnClearEventListenerIsDetachedOnCleanup()
{
$mockConnection = $this->createMock(Connection::class);
$mockEntityManagerInterface = $this->createMock(EntityManagerInterface::class);
$mockEventManager = $this->createMock(EventManager::class);
$mockStatement = $this->createMock(Statement::class);
$mockResultMapping = $this->getMockBuilder(ResultSetMapping::class);
$mockEntityManagerInterface->expects(self::any())->method('getEventManager')->willReturn($mockEventManager);
$mockEntityManagerInterface->expects(self::any())->method('getConnection')->willReturn($mockConnection);
$mockStatement->expects(self::once())->method('fetch')->willReturn(false);
/* @var $mockAbstractHydrator AbstractHydrator */
$mockAbstractHydrator = $this
->getMockBuilder(AbstractHydrator::class)
->setConstructorArgs([$mockEntityManagerInterface])
->setMethods(['hydrateAllData'])
->getMock();
$mockEventManager
->expects(self::at(0))
->method('addEventListener')
->with([Events::onClear], $mockAbstractHydrator);
$mockEventManager
->expects(self::at(1))
->method('removeEventListener')
->with([Events::onClear], $mockAbstractHydrator);
$mockEventManager
->expects(self::at(2))
->method('addEventListener')
->with([Events::onClear], $mockAbstractHydrator);
$mockEventManager
->expects(self::at(3))
->method('removeEventListener')
->with([Events::onClear], $mockAbstractHydrator);
iterator_to_array($mockAbstractHydrator->iterate($mockStatement, $mockResultMapping));
$mockAbstractHydrator->hydrateAll($mockStatement, $mockResultMapping);
}
}