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\Component\Resource\Tests\Model; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Lug\Component\Resource\Domain\DomainManagerInterface; |
16
|
|
|
use Lug\Component\Resource\Factory\FactoryInterface; |
17
|
|
|
use Lug\Component\Resource\Model\Resource; |
18
|
|
|
use Lug\Component\Resource\Model\ResourceInterface; |
19
|
|
|
use Lug\Component\Resource\Repository\RepositoryInterface; |
20
|
|
|
use Symfony\Component\Form\FormInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author GeLo <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class ResourceTest extends \PHPUnit_Framework_TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var resource |
29
|
|
|
*/ |
30
|
|
|
private $resource; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $name; |
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string[] |
39
|
|
|
*/ |
40
|
|
|
private $interfaces; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $model; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
protected function setUp() |
51
|
|
|
{ |
52
|
|
|
$this->name = 'name'; |
53
|
|
|
$this->interfaces = [\ArrayAccess::class, \Countable::class]; |
|
|
|
|
54
|
|
|
$this->model = \ArrayIterator::class; |
55
|
|
|
|
56
|
|
|
$this->resource = new Resource($this->name, $this->interfaces, $this->model); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testInheritance() |
60
|
|
|
{ |
61
|
|
|
$this->assertInstanceOf(ResourceInterface::class, $this->resource); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testDefaultState() |
65
|
|
|
{ |
66
|
|
|
$this->assertSame($this->name, $this->resource->getName()); |
|
|
|
|
67
|
|
|
$this->assertSame($this->interfaces, $this->resource->getInterfaces()); |
|
|
|
|
68
|
|
|
$this->assertSame($this->model, $this->resource->getModel()); |
|
|
|
|
69
|
|
|
$this->assertNull($this->resource->getDriver()); |
|
|
|
|
70
|
|
|
$this->assertNull($this->resource->getDriverManager()); |
|
|
|
|
71
|
|
|
$this->assertNull($this->resource->getDriverMappingPath()); |
|
|
|
|
72
|
|
|
$this->assertNull($this->resource->getDriverMappingFormat()); |
|
|
|
|
73
|
|
|
$this->assertNull($this->resource->getRepository()); |
|
|
|
|
74
|
|
|
$this->assertNull($this->resource->getFactory()); |
|
|
|
|
75
|
|
|
$this->assertNull($this->resource->getForm()); |
|
|
|
|
76
|
|
|
$this->assertNull($this->resource->getChoiceForm()); |
|
|
|
|
77
|
|
|
$this->assertNull($this->resource->getDomainManager()); |
|
|
|
|
78
|
|
|
$this->assertNull($this->resource->getController()); |
|
|
|
|
79
|
|
|
$this->assertNull($this->resource->getIdPropertyPath()); |
|
|
|
|
80
|
|
|
$this->assertNull($this->resource->getLabelPropertyPath()); |
|
|
|
|
81
|
|
|
$this->assertNull($this->resource->getTranslation()); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testDriver() |
85
|
|
|
{ |
86
|
|
|
$this->resource->setDriver($driver = ResourceInterface::DRIVER_DOCTRINE_ORM); |
|
|
|
|
87
|
|
|
|
88
|
|
|
$this->assertSame($driver, $this->resource->getDriver()); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testDriverManager() |
92
|
|
|
{ |
93
|
|
|
$this->resource->setDriverManager($driverManager = 'default'); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$this->assertSame($driverManager, $this->resource->getDriverManager()); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testDriverMappingPath() |
99
|
|
|
{ |
100
|
|
|
$this->resource->setDriverMappingPath($driverMappingPath = __DIR__); |
|
|
|
|
101
|
|
|
|
102
|
|
|
$this->assertSame($driverMappingPath, $this->resource->getDriverMappingPath()); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testDriverMappingFormat() |
106
|
|
|
{ |
107
|
|
|
$this->resource->setDriverMappingFormat($driverMappingFormat = ResourceInterface::DRIVER_MAPPING_FORMAT_YAML); |
|
|
|
|
108
|
|
|
|
109
|
|
|
$this->assertSame($driverMappingFormat, $this->resource->getDriverMappingFormat()); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testModel() |
113
|
|
|
{ |
114
|
|
|
$this->resource->setModel($model = ArrayCollection::class); |
|
|
|
|
115
|
|
|
|
116
|
|
|
$this->assertSame($model, $this->resource->getModel()); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function testFactory() |
120
|
|
|
{ |
121
|
|
|
$this->resource->setFactory($factory = $this->createFactoryClassMock()); |
|
|
|
|
122
|
|
|
|
123
|
|
|
$this->assertSame($factory, $this->resource->getFactory()); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function testRepository() |
127
|
|
|
{ |
128
|
|
|
$this->resource->setRepository($repository = $this->createRepositoryClassMock()); |
|
|
|
|
129
|
|
|
|
130
|
|
|
$this->assertSame($repository, $this->resource->getRepository()); |
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function testForm() |
134
|
|
|
{ |
135
|
|
|
$this->resource->setForm($form = $this->createFormClassMock()); |
|
|
|
|
136
|
|
|
|
137
|
|
|
$this->assertSame($form, $this->resource->getForm()); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function testChoiceForm() |
141
|
|
|
{ |
142
|
|
|
$this->resource->setChoiceForm($choiceForm = $this->createFormClassMock()); |
|
|
|
|
143
|
|
|
|
144
|
|
|
$this->assertSame($choiceForm, $this->resource->getChoiceForm()); |
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testDomainManager() |
148
|
|
|
{ |
149
|
|
|
$this->resource->setDomainManager($domainManager = $this->createDomainManagerClassMock()); |
|
|
|
|
150
|
|
|
|
151
|
|
|
$this->assertSame($domainManager, $this->resource->getDomainManager()); |
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testController() |
155
|
|
|
{ |
156
|
|
|
$this->resource->setController($controller = $this->createControllerClassMock()); |
|
|
|
|
157
|
|
|
|
158
|
|
|
$this->assertSame($controller, $this->resource->getController()); |
|
|
|
|
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function testIdPropertyPath() |
162
|
|
|
{ |
163
|
|
|
$this->resource->setIdPropertyPath($idPropertyPath = 'id'); |
|
|
|
|
164
|
|
|
|
165
|
|
|
$this->assertSame($idPropertyPath, $this->resource->getIdPropertyPath()); |
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function testLabelPropertyPath() |
169
|
|
|
{ |
170
|
|
|
$this->resource->setLabelPropertyPath($labelPropertyPath = 'label'); |
|
|
|
|
171
|
|
|
|
172
|
|
|
$this->assertSame($labelPropertyPath, $this->resource->getLabelPropertyPath()); |
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function testTranslation() |
176
|
|
|
{ |
177
|
|
|
$this->resource->setTranslation($translation = $this->createResourceMock()); |
|
|
|
|
178
|
|
|
|
179
|
|
|
$this->assertSame($translation, $this->resource->getTranslation()); |
|
|
|
|
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
|
|
private function createFactoryClassMock() |
186
|
|
|
{ |
187
|
|
|
return $this->getMockClass(FactoryInterface::class); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
|
|
private function createRepositoryClassMock() |
194
|
|
|
{ |
195
|
|
|
return $this->getMockClass(RepositoryInterface::class); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return string |
200
|
|
|
*/ |
201
|
|
|
private function createFormClassMock() |
202
|
|
|
{ |
203
|
|
|
return $this->getMockClass(FormInterface::class); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
|
|
private function createControllerClassMock() |
210
|
|
|
{ |
211
|
|
|
return $this->getMockClass(\stdClass::class); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|DomainManagerInterface |
216
|
|
|
*/ |
217
|
|
|
private function createDomainManagerClassMock() |
218
|
|
|
{ |
219
|
|
|
return $this->createMock(DomainManagerInterface::class); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface |
224
|
|
|
*/ |
225
|
|
|
private function createResourceMock() |
226
|
|
|
{ |
227
|
|
|
return $this->createMock(ResourceInterface::class); |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|