2017-06-24 03:40:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
use Doctrine\Common\EventManager;
|
2017-08-16 15:07:48 +02:00
|
|
|
use Doctrine\DBAL\Connection;
|
2017-06-24 03:40:12 +02:00
|
|
|
use Doctrine\DBAL\Driver\Statement;
|
2017-08-16 15:07:48 +02:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2017-06-24 03:40:12 +02:00
|
|
|
use Doctrine\ORM\Events;
|
|
|
|
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
|
2017-08-16 15:07:48 +02:00
|
|
|
use Doctrine\ORM\Query\ResultSetMapping;
|
2017-06-24 03:40:12 +02:00
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Doctrine\ORM\Internal\Hydration\AbstractHydrator
|
|
|
|
*/
|
|
|
|
class AbstractHydratorTest extends OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
/**
|
2017-08-16 15:07:48 +02:00
|
|
|
* @var EventManager|\PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
private $mockEventManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Statement|\PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
private $mockStatement;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ResultSetMapping|\PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
private $mockResultMapping;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var AbstractHydrator
|
2017-06-24 03:40:12 +02:00
|
|
|
*/
|
2017-08-16 15:07:48 +02:00
|
|
|
private $hydrator;
|
|
|
|
|
|
|
|
protected function setUp() : void
|
2017-06-24 03:40:12 +02:00
|
|
|
{
|
2017-08-16 15:07:48 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-06-24 03:40:12 +02:00
|
|
|
$mockConnection = $this->createMock(Connection::class);
|
|
|
|
$mockEntityManagerInterface = $this->createMock(EntityManagerInterface::class);
|
2017-08-16 15:07:48 +02:00
|
|
|
$this->mockEventManager = $this->createMock(EventManager::class);
|
|
|
|
$this->mockStatement = $this->createMock(Statement::class);
|
|
|
|
$this->mockResultMapping = $this->getMockBuilder(ResultSetMapping::class);
|
2017-06-24 03:40:12 +02:00
|
|
|
|
2017-08-16 15:07:48 +02:00
|
|
|
$mockEntityManagerInterface
|
|
|
|
->expects(self::any())
|
|
|
|
->method('getEventManager')
|
|
|
|
->willReturn($this->mockEventManager);
|
|
|
|
$mockEntityManagerInterface
|
|
|
|
->expects(self::any())
|
|
|
|
->method('getConnection')
|
|
|
|
->willReturn($mockConnection);
|
|
|
|
$this->mockStatement
|
|
|
|
->expects(self::any())
|
|
|
|
->method('fetch')
|
|
|
|
->willReturn(false);
|
2017-06-24 03:40:12 +02:00
|
|
|
|
2017-08-16 15:07:48 +02:00
|
|
|
$this->hydrator = $this
|
2017-06-24 03:40:12 +02:00
|
|
|
->getMockBuilder(AbstractHydrator::class)
|
|
|
|
->setConstructorArgs([$mockEntityManagerInterface])
|
|
|
|
->setMethods(['hydrateAllData'])
|
|
|
|
->getMock();
|
2017-08-16 15:07:48 +02:00
|
|
|
}
|
2017-06-24 03:40:12 +02:00
|
|
|
|
2017-08-16 15:07:48 +02:00
|
|
|
/**
|
|
|
|
* @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() : void
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->mockEventManager
|
2017-06-24 03:40:12 +02:00
|
|
|
->expects(self::at(0))
|
|
|
|
->method('addEventListener')
|
2017-08-16 15:07:48 +02:00
|
|
|
->with([Events::onClear], $this->hydrator);
|
2017-06-24 03:40:12 +02:00
|
|
|
|
2017-08-16 15:07:48 +02:00
|
|
|
$this
|
|
|
|
->mockEventManager
|
2017-06-24 03:40:12 +02:00
|
|
|
->expects(self::at(1))
|
|
|
|
->method('removeEventListener')
|
2017-08-16 15:07:48 +02:00
|
|
|
->with([Events::onClear], $this->hydrator);
|
2017-06-24 03:40:12 +02:00
|
|
|
|
2017-08-16 15:07:48 +02:00
|
|
|
iterator_to_array($this->hydrator->iterate($this->mockStatement, $this->mockResultMapping));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group #6623
|
|
|
|
*/
|
|
|
|
public function testHydrateAllRegistersAndClearsAllAttachedListeners() : void
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->mockEventManager
|
|
|
|
->expects(self::at(0))
|
2017-08-13 22:42:09 +02:00
|
|
|
->method('addEventListener')
|
2017-08-16 15:07:48 +02:00
|
|
|
->with([Events::onClear], $this->hydrator);
|
2017-08-13 22:42:09 +02:00
|
|
|
|
2017-08-16 15:07:48 +02:00
|
|
|
$this
|
|
|
|
->mockEventManager
|
|
|
|
->expects(self::at(1))
|
2017-08-13 22:42:09 +02:00
|
|
|
->method('removeEventListener')
|
2017-08-16 15:07:48 +02:00
|
|
|
->with([Events::onClear], $this->hydrator);
|
2017-08-13 22:42:09 +02:00
|
|
|
|
2017-08-16 15:07:48 +02:00
|
|
|
$this->hydrator->hydrateAll($this->mockStatement, $this->mockResultMapping);
|
2017-06-24 03:40:12 +02:00
|
|
|
}
|
|
|
|
}
|