1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\EventManager; |
6
|
|
|
use Doctrine\DBAL\Connection; |
7
|
|
|
use Doctrine\DBAL\Driver\Statement; |
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
9
|
|
|
use Doctrine\ORM\Events; |
10
|
|
|
use Doctrine\ORM\Internal\Hydration\AbstractHydrator; |
11
|
|
|
use Doctrine\ORM\Query\ResultSetMapping; |
12
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers \Doctrine\ORM\Internal\Hydration\AbstractHydrator |
16
|
|
|
*/ |
17
|
|
|
class AbstractHydratorTest extends OrmFunctionalTestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var EventManager|\PHPUnit_Framework_MockObject_MockObject |
21
|
|
|
*/ |
22
|
|
|
private $mockEventManager; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var Statement|\PHPUnit_Framework_MockObject_MockObject |
26
|
|
|
*/ |
27
|
|
|
private $mockStatement; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ResultSetMapping|\PHPUnit_Framework_MockObject_MockObject |
31
|
|
|
*/ |
32
|
|
|
private $mockResultMapping; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var AbstractHydrator |
36
|
|
|
*/ |
37
|
|
|
private $hydrator; |
38
|
|
|
|
39
|
|
|
protected function setUp() : void |
40
|
|
|
{ |
41
|
|
|
parent::setUp(); |
42
|
|
|
|
43
|
|
|
$mockConnection = $this->createMock(Connection::class); |
44
|
|
|
$mockEntityManagerInterface = $this->createMock(EntityManagerInterface::class); |
45
|
|
|
$this->mockEventManager = $this->createMock(EventManager::class); |
46
|
|
|
$this->mockStatement = $this->createMock(Statement::class); |
47
|
|
|
$this->mockResultMapping = $this->getMockBuilder(ResultSetMapping::class); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$mockEntityManagerInterface |
50
|
|
|
->expects(self::any()) |
51
|
|
|
->method('getEventManager') |
52
|
|
|
->willReturn($this->mockEventManager); |
53
|
|
|
$mockEntityManagerInterface |
54
|
|
|
->expects(self::any()) |
55
|
|
|
->method('getConnection') |
56
|
|
|
->willReturn($mockConnection); |
57
|
|
|
$this->mockStatement |
58
|
|
|
->expects(self::any()) |
59
|
|
|
->method('fetch') |
60
|
|
|
->willReturn(false); |
61
|
|
|
|
62
|
|
|
$this->hydrator = $this |
63
|
|
|
->getMockBuilder(AbstractHydrator::class) |
64
|
|
|
->setConstructorArgs([$mockEntityManagerInterface]) |
65
|
|
|
->setMethods(['hydrateAllData']) |
66
|
|
|
->getMock(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @group DDC-3146 |
71
|
|
|
* @group #1515 |
72
|
|
|
* |
73
|
|
|
* Verify that the number of added events to the event listener from the abstract hydrator class is equal to the |
74
|
|
|
* number of removed events |
75
|
|
|
*/ |
76
|
|
View Code Duplication |
public function testOnClearEventListenerIsDetachedOnCleanup() : void |
77
|
|
|
{ |
78
|
|
|
$this |
|
|
|
|
79
|
|
|
->mockEventManager |
80
|
|
|
->expects(self::at(0)) |
81
|
|
|
->method('addEventListener') |
82
|
|
|
->with([Events::onClear], $this->hydrator); |
83
|
|
|
|
84
|
|
|
$this |
85
|
|
|
->mockEventManager |
86
|
|
|
->expects(self::at(1)) |
87
|
|
|
->method('removeEventListener') |
88
|
|
|
->with([Events::onClear], $this->hydrator); |
89
|
|
|
|
90
|
|
|
iterator_to_array($this->hydrator->iterate($this->mockStatement, $this->mockResultMapping)); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @group #6623 |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
public function testHydrateAllRegistersAndClearsAllAttachedListeners() : void |
97
|
|
|
{ |
98
|
|
|
$this |
|
|
|
|
99
|
|
|
->mockEventManager |
100
|
|
|
->expects(self::at(0)) |
101
|
|
|
->method('addEventListener') |
102
|
|
|
->with([Events::onClear], $this->hydrator); |
103
|
|
|
|
104
|
|
|
$this |
105
|
|
|
->mockEventManager |
106
|
|
|
->expects(self::at(1)) |
107
|
|
|
->method('removeEventListener') |
108
|
|
|
->with([Events::onClear], $this->hydrator); |
109
|
|
|
|
110
|
|
|
$this->hydrator->hydrateAll($this->mockStatement, $this->mockResultMapping); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..