1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Lug package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Lug\Bundle\ResourceBundle\Tests\DependencyInjection\Configurator; |
13
|
|
|
|
14
|
|
|
use Lug\Bundle\ResourceBundle\DependencyInjection\Configurator\ResolveTargetSubscriberConfigurator; |
15
|
|
|
use Lug\Bundle\ResourceBundle\EventSubscriber\ResolveTargetSubscriberInterface; |
16
|
|
|
use Lug\Component\Registry\Model\RegistryInterface; |
17
|
|
|
use Lug\Component\Resource\Model\ResourceInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author GeLo <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ResolveTargetEntitySubscriberConfiguratorTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ResolveTargetSubscriberConfigurator |
26
|
|
|
*/ |
27
|
|
|
private $configurator; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|RegistryInterface |
31
|
|
|
*/ |
32
|
|
|
private $serviceRegistry; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
protected function setUp() |
38
|
|
|
{ |
39
|
|
|
$this->serviceRegistry = $this->createServiceRegistryMock(); |
40
|
|
|
$this->configurator = new ResolveTargetSubscriberConfigurator($this->serviceRegistry); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testConfigure() |
44
|
|
|
{ |
45
|
|
|
$this->serviceRegistry |
|
|
|
|
46
|
|
|
->expects($this->once()) |
47
|
|
|
->method('getIterator') |
48
|
|
|
->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()]))); |
49
|
|
|
|
50
|
|
|
$resource |
51
|
|
|
->expects($this->once()) |
52
|
|
|
->method('getDriver') |
53
|
|
|
->will($this->returnValue(ResourceInterface::DRIVER_DOCTRINE_ORM)); |
54
|
|
|
|
55
|
|
|
$resource |
56
|
|
|
->expects($this->once()) |
57
|
|
|
->method('getInterfaces') |
58
|
|
|
->will($this->returnValue([$interface = 'interface'])); |
59
|
|
|
|
60
|
|
|
$resource |
61
|
|
|
->expects($this->once()) |
62
|
|
|
->method('getModel') |
63
|
|
|
->will($this->returnValue($model = 'model')); |
64
|
|
|
|
65
|
|
|
$subscriber = $this->createResolveTargetSubscriberMock(); |
66
|
|
|
$subscriber |
67
|
|
|
->expects($this->once()) |
68
|
|
|
->method('addResolveTarget') |
69
|
|
|
->with( |
70
|
|
|
$this->identicalTo($interface), |
71
|
|
|
$this->identicalTo($model) |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$this->configurator->configure($subscriber); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testConfigureWithoutDriver() |
78
|
|
|
{ |
79
|
|
|
$this->serviceRegistry |
|
|
|
|
80
|
|
|
->expects($this->once()) |
81
|
|
|
->method('getIterator') |
82
|
|
|
->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()]))); |
83
|
|
|
|
84
|
|
|
$resource |
85
|
|
|
->expects($this->once()) |
86
|
|
|
->method('getDriver') |
87
|
|
|
->will($this->returnValue(null)); |
88
|
|
|
|
89
|
|
|
$subscriber = $this->createResolveTargetSubscriberMock(); |
90
|
|
|
$subscriber |
91
|
|
|
->expects($this->never()) |
92
|
|
|
->method('addResolveTarget'); |
93
|
|
|
|
94
|
|
|
$this->configurator->configure($subscriber); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|RegistryInterface |
99
|
|
|
*/ |
100
|
|
|
private function createServiceRegistryMock() |
101
|
|
|
{ |
102
|
|
|
return $this->createMock(RegistryInterface::class); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface |
107
|
|
|
*/ |
108
|
|
|
private function createResourceMock() |
109
|
|
|
{ |
110
|
|
|
return $this->createMock(ResourceInterface::class); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ResolveTargetSubscriberInterface |
115
|
|
|
*/ |
116
|
|
|
private function createResolveTargetSubscriberMock() |
117
|
|
|
{ |
118
|
|
|
return $this->createMock(ResolveTargetSubscriberInterface::class); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
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: