1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\EventManager; |
8
|
|
|
use Doctrine\DBAL\Connection; |
9
|
|
|
use Doctrine\ORM\Annotation as ORM; |
10
|
|
|
use Doctrine\ORM\Configuration; |
11
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
12
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
13
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataFactory; |
14
|
|
|
use Doctrine\ORM\Mapping\Driver\MappingDriver; |
15
|
|
|
use Doctrine\Tests\DoctrineTestCase; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @group DDC-2359 |
19
|
|
|
*/ |
20
|
|
|
class DDC2359Test extends DoctrineTestCase |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Verifies that {@see \Doctrine\ORM\Mapping\ClassMetadataFactory::wakeupReflection} is |
25
|
|
|
* not called when loading metadata from a driver |
26
|
|
|
*/ |
27
|
|
|
public function testIssue() |
28
|
|
|
{ |
29
|
|
|
$mockDriver = $this->createMock(MappingDriver::class); |
30
|
|
|
$mockMetadata = $this->createMock(ClassMetadata::class); |
31
|
|
|
$entityManager = $this->createMock(EntityManagerInterface::class); |
32
|
|
|
|
33
|
|
|
/* @var $metadataFactory \Doctrine\ORM\Mapping\ClassMetadataFactory|\PHPUnit_Framework_MockObject_MockObject */ |
34
|
|
|
$metadataFactory = $this->getMockBuilder(ClassMetadataFactory::class) |
35
|
|
|
->setMethods(['doLoadMetadata', 'wakeupReflection']) |
36
|
|
|
->getMock(); |
37
|
|
|
|
38
|
|
|
$configuration = $this->getMockBuilder(Configuration::class) |
39
|
|
|
->setMethods(['getMetadataDriverImpl']) |
40
|
|
|
->getMock(); |
41
|
|
|
|
42
|
|
|
$connection = $this->createMock(Connection::class); |
43
|
|
|
|
44
|
|
|
$configuration |
45
|
|
|
->expects($this->any()) |
46
|
|
|
->method('getMetadataDriverImpl') |
47
|
|
|
->will($this->returnValue($mockDriver)); |
48
|
|
|
|
49
|
|
|
$mockMetadata |
50
|
|
|
->expects($this->any()) |
51
|
|
|
->method('getDeclaredPropertiesIterator') |
52
|
|
|
->will($this->returnValue(new \ArrayIterator([]))); |
53
|
|
|
|
54
|
|
|
$entityManager |
55
|
|
|
->expects($this->any()) |
56
|
|
|
->method('getConfiguration') |
57
|
|
|
->will($this->returnValue($configuration)); |
58
|
|
|
|
59
|
|
|
$entityManager |
60
|
|
|
->expects($this->any()) |
61
|
|
|
->method('getConnection') |
62
|
|
|
->will($this->returnValue($connection)); |
63
|
|
|
|
64
|
|
|
$entityManager |
65
|
|
|
->expects($this->any()) |
66
|
|
|
->method('getEventManager') |
67
|
|
|
->will($this->returnValue($this->createMock(EventManager::class))); |
68
|
|
|
|
69
|
|
|
$metadataFactory |
|
|
|
|
70
|
|
|
->expects($this->any()) |
71
|
|
|
->method('doLoadMetadata') |
72
|
|
|
->will($this->returnValue($mockMetadata)); |
73
|
|
|
|
74
|
|
|
$metadataFactory |
75
|
|
|
->expects($this->never()) |
76
|
|
|
->method('wakeupReflection'); |
77
|
|
|
|
78
|
|
|
$metadataFactory->setEntityManager($entityManager); |
|
|
|
|
79
|
|
|
|
80
|
|
|
self::assertSame($mockMetadata, $metadataFactory->getMetadataFor(DDC2359Foo::class)); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** @ORM\Entity */ |
85
|
|
|
class DDC2359Foo |
86
|
|
|
{ |
87
|
|
|
/** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue */ |
88
|
|
|
public $id; |
89
|
|
|
} |
90
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: