|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Doctrine Bundle |
|
5
|
|
|
* |
|
6
|
|
|
* The code was originally distributed inside the Symfony framework. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Fabien Potencier <[email protected]> |
|
9
|
|
|
* (c) Doctrine Project, Benjamin Eberlei <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
12
|
|
|
* file that was distributed with this source code. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Doctrine\Bundle\DoctrineBundle\Tests\DataCollector; |
|
16
|
|
|
|
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
20
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataInfo; |
|
21
|
|
|
use Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector; |
|
22
|
|
|
|
|
23
|
|
|
class DoctrineDataCollectorTest extends TestCase |
|
24
|
|
|
{ |
|
25
|
|
|
const FIRST_ENTITY = 'TestBundle\Test\Entity\Test1'; |
|
26
|
|
|
const SECOND_ENTITY = 'TestBundle\Test\Entity\Test2'; |
|
27
|
|
|
|
|
28
|
|
|
public function testCollectEntities() |
|
29
|
|
|
{ |
|
30
|
|
|
$manager = $this->getMockBuilder('Doctrine\ORM\EntityManager')->disableOriginalConstructor()->getMock(); |
|
31
|
|
|
$config = $this->getMockBuilder('Doctrine\ORM\Configuration')->getMock(); |
|
32
|
|
|
$factory = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory') |
|
33
|
|
|
->setMethods(array('getLoadedMetadata'))->getMockForAbstractClass(); |
|
34
|
|
|
$collector = $this->createCollector(array('default' => $manager)); |
|
35
|
|
|
|
|
36
|
|
|
$manager->expects($this->any()) |
|
37
|
|
|
->method('getMetadataFactory') |
|
38
|
|
|
->will($this->returnValue($factory)); |
|
39
|
|
|
$manager->expects($this->any()) |
|
40
|
|
|
->method('getConfiguration') |
|
41
|
|
|
->will($this->returnValue($config)); |
|
42
|
|
|
|
|
43
|
|
|
if (method_exists($config, 'isSecondLevelCacheEnabled')) { |
|
44
|
|
|
$config->expects($this->once()) |
|
45
|
|
|
->method('isSecondLevelCacheEnabled') |
|
46
|
|
|
->will($this->returnValue(false)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$metadatas = array( |
|
50
|
|
|
$this->createEntityMetadata(self::FIRST_ENTITY), |
|
51
|
|
|
$this->createEntityMetadata(self::SECOND_ENTITY), |
|
52
|
|
|
$this->createEntityMetadata(self::FIRST_ENTITY), |
|
53
|
|
|
); |
|
54
|
|
|
$factory->expects($this->once()) |
|
55
|
|
|
->method('getLoadedMetadata') |
|
56
|
|
|
->will($this->returnValue($metadatas)); |
|
57
|
|
|
|
|
58
|
|
|
$collector->collect(new Request(), new Response()); |
|
59
|
|
|
|
|
60
|
|
|
$entities = $collector->getEntities(); |
|
61
|
|
|
$this->assertArrayHasKey('default', $entities); |
|
62
|
|
|
$this->assertCount(2, $entities['default']); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $entityFQCN |
|
67
|
|
|
* |
|
68
|
|
|
* @return ClassMetadataInfo |
|
69
|
|
|
*/ |
|
70
|
|
|
private function createEntityMetadata($entityFQCN) |
|
71
|
|
|
{ |
|
72
|
|
|
$metadata = new ClassMetadataInfo($entityFQCN); |
|
73
|
|
|
$metadata->name = $entityFQCN; |
|
74
|
|
|
$metadata->reflClass = new \ReflectionClass('stdClass'); |
|
75
|
|
|
|
|
76
|
|
|
return $metadata; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param array $managers |
|
81
|
|
|
* |
|
82
|
|
|
* @return DoctrineDataCollector |
|
83
|
|
|
*/ |
|
84
|
|
|
private function createCollector(array $managers) |
|
85
|
|
|
{ |
|
86
|
|
|
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); |
|
87
|
|
|
$registry |
|
88
|
|
|
->expects($this->any()) |
|
89
|
|
|
->method('getConnectionNames') |
|
90
|
|
|
->will($this->returnValue(array('default' => 'doctrine.dbal.default_connection'))); |
|
91
|
|
|
$registry |
|
92
|
|
|
->expects($this->any()) |
|
93
|
|
|
->method('getManagerNames') |
|
94
|
|
|
->will($this->returnValue(array('default' => 'doctrine.orm.default_entity_manager'))); |
|
95
|
|
|
$registry |
|
96
|
|
|
->expects($this->any()) |
|
97
|
|
|
->method('getManagers') |
|
98
|
|
|
->will($this->returnValue($managers)); |
|
99
|
|
|
|
|
100
|
|
|
$collector = new DoctrineDataCollector($registry); |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
return $collector; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: