Completed
Push — master ( f61101...67e7bb )
by Eric
35:57 queued 27:57
created

ResourceTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 17
nc 1
nop 0
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 $driver;
36
37
    /**
38
     * @var string
39
     */
40
    private $driverManager;
41
42
    /**
43
     * @var string
44
     */
45
    private $driverMappingPath;
46
47
    /**
48
     * @var string
49
     */
50
    private $driverMappingFormat;
51
52
    /**
53
     * @var string
54
     */
55
    private $name;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
56
57
    /**
58
     * @var string[]
59
     */
60
    private $interfaces;
61
62
    /**
63
     * @var string
64
     */
65
    private $model;
66
67
    /**
68
     * @var string
69
     */
70
    private $repository;
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    protected function setUp()
76
    {
77
        $this->name = 'name';
78
        $this->driver = ResourceInterface::DRIVER_DOCTRINE_MONGODB;
79
        $this->driverManager = 'my.manager';
80
        $this->driverMappingPath = __DIR__;
81
        $this->driverMappingFormat = ResourceInterface::DRIVER_MAPPING_FORMAT_XML;
82
        $this->interfaces = [\ArrayAccess::class, \Countable::class];
0 ignored issues
show
Documentation Bug introduced by
It seems like array(\ArrayAccess::class, \Countable::class) of type array<integer,?> is incompatible with the declared type array<integer,string> of property $interfaces.

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..

Loading history...
83
        $this->model = \ArrayIterator::class;
84
85
        $this->resource = new Resource(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Lug\Component\Resou...del, $this->repository) of type object<Lug\Component\Resource\Model\Resource> is incompatible with the declared type resource of property $resource.

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..

Loading history...
86
            $this->name,
87
            $this->driver,
88
            $this->driverManager,
89
            $this->driverMappingPath,
90
            $this->driverMappingFormat,
91
            $this->interfaces,
92
            $this->model,
93
            $this->repository
94
        );
95
    }
96
97
    public function testInheritance()
98
    {
99
        $this->assertInstanceOf(ResourceInterface::class, $this->resource);
100
    }
101
102
    public function testDefaultState()
103
    {
104
        $this->assertSame($this->name, $this->resource->getName());
0 ignored issues
show
Bug introduced by
The method getName cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
105
        $this->assertSame($this->driver, $this->resource->getDriver());
0 ignored issues
show
Bug introduced by
The method getDriver cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
106
        $this->assertSame($this->driverManager, $this->resource->getDriverManager());
0 ignored issues
show
Bug introduced by
The method getDriverManager cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
107
        $this->assertSame($this->driverMappingPath, $this->resource->getDriverMappingPath());
0 ignored issues
show
Bug introduced by
The method getDriverMappingPath cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
108
        $this->assertSame($this->driverMappingFormat, $this->resource->getDriverMappingFormat());
0 ignored issues
show
Bug introduced by
The method getDriverMappingFormat cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
109
        $this->assertSame($this->interfaces, $this->resource->getInterfaces());
0 ignored issues
show
Bug introduced by
The method getInterfaces cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
110
        $this->assertSame($this->model, $this->resource->getModel());
0 ignored issues
show
Bug introduced by
The method getModel cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
111
        $this->assertSame($this->repository, $this->resource->getRepository());
0 ignored issues
show
Bug introduced by
The method getRepository cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
112
        $this->assertNull($this->resource->getFactory());
0 ignored issues
show
Bug introduced by
The method getFactory cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
113
        $this->assertNull($this->resource->getForm());
0 ignored issues
show
Bug introduced by
The method getForm cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
114
        $this->assertNull($this->resource->getChoiceForm());
0 ignored issues
show
Bug introduced by
The method getChoiceForm cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
115
        $this->assertNull($this->resource->getDomainManager());
0 ignored issues
show
Bug introduced by
The method getDomainManager cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
116
        $this->assertNull($this->resource->getController());
0 ignored issues
show
Bug introduced by
The method getController cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
117
        $this->assertNull($this->resource->getIdPropertyPath());
0 ignored issues
show
Bug introduced by
The method getIdPropertyPath cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
118
        $this->assertNull($this->resource->getLabelPropertyPath());
0 ignored issues
show
Bug introduced by
The method getLabelPropertyPath cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
119
        $this->assertNull($this->resource->getTranslation());
0 ignored issues
show
Bug introduced by
The method getTranslation cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
120
    }
121
122
    public function testInitialState()
123
    {
124
        $translation = $this->createResourceMock();
125
126
        $this->resource = new Resource(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Lug\Component\Resou... 'label', $translation) of type object<Lug\Component\Resource\Model\Resource> is incompatible with the declared type resource of property $resource.

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..

Loading history...
127
            $this->name,
128
            $this->driver,
129
            $this->driverManager,
130
            $this->driverMappingPath,
131
            $this->driverMappingFormat,
132
            $this->interfaces,
133
            $this->model,
134
            $this->repository,
135
            $factory = $this->createFactoryClassMock(),
136
            $form = $this->createFormClassMock(),
137
            $choiceForm = $this->createFormClassMock(),
138
            $domainManager = $this->createDomainManagerClassMock(),
139
            $controller = $this->createControllerClassMock(),
140
            $idPropertyPath = 'id',
141
            $labelPropertyPath = 'label',
142
            $translation
143
        );
144
145
        $this->assertSame($this->name, $this->resource->getName());
146
        $this->assertSame($this->driver, $this->resource->getDriver());
147
        $this->assertSame($this->driverManager, $this->resource->getDriverManager());
148
        $this->assertSame($this->driverMappingPath, $this->resource->getDriverMappingPath());
149
        $this->assertSame($this->driverMappingFormat, $this->resource->getDriverMappingFormat());
150
        $this->assertSame($this->interfaces, $this->resource->getInterfaces());
151
        $this->assertSame($this->model, $this->resource->getModel());
152
        $this->assertSame($this->repository, $this->resource->getRepository());
153
        $this->assertSame($factory, $this->resource->getFactory());
154
        $this->assertSame($form, $this->resource->getForm());
155
        $this->assertSame($choiceForm, $this->resource->getChoiceForm());
156
        $this->assertSame($domainManager, $this->resource->getDomainManager());
157
        $this->assertSame($controller, $this->resource->getController());
158
        $this->assertSame($idPropertyPath, $this->resource->getIdPropertyPath());
159
        $this->assertSame($labelPropertyPath, $this->resource->getLabelPropertyPath());
160
        $this->assertSame($translation, $this->resource->getTranslation());
161
    }
162
163
    public function testDriver()
164
    {
165
        $this->resource->setDriver($driver = ResourceInterface::DRIVER_DOCTRINE_ORM);
0 ignored issues
show
Bug introduced by
The method setDriver cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
166
167
        $this->assertSame($driver, $this->resource->getDriver());
0 ignored issues
show
Bug introduced by
The method getDriver cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
168
    }
169
170
    public function testDriverManager()
171
    {
172
        $this->resource->setDriverManager($driverManager = 'default');
0 ignored issues
show
Bug introduced by
The method setDriverManager cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
173
174
        $this->assertSame($driverManager, $this->resource->getDriverManager());
0 ignored issues
show
Bug introduced by
The method getDriverManager cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
175
    }
176
177
    public function testDriverMappingPath()
178
    {
179
        $this->resource->setDriverMappingPath($driverMappingPath = __DIR__.'/default');
0 ignored issues
show
Bug introduced by
The method setDriverMappingPath cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
180
181
        $this->assertSame($driverMappingPath, $this->resource->getDriverMappingPath());
0 ignored issues
show
Bug introduced by
The method getDriverMappingPath cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
182
    }
183
184
    public function testDriverMappingFormat()
185
    {
186
        $this->resource->setDriverMappingFormat($driverMappingFormat = ResourceInterface::DRIVER_MAPPING_FORMAT_YAML);
0 ignored issues
show
Bug introduced by
The method setDriverMappingFormat cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
187
188
        $this->assertSame($driverMappingFormat, $this->resource->getDriverMappingFormat());
0 ignored issues
show
Bug introduced by
The method getDriverMappingFormat cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
189
    }
190
191
    public function testModel()
192
    {
193
        $this->resource->setModel($model = ArrayCollection::class);
0 ignored issues
show
Bug introduced by
The method setModel cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
194
195
        $this->assertSame($model, $this->resource->getModel());
0 ignored issues
show
Bug introduced by
The method getModel cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
196
    }
197
198
    public function testFactory()
199
    {
200
        $this->resource->setFactory($factory = $this->createFactoryClassMock());
0 ignored issues
show
Bug introduced by
The method setFactory cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
201
202
        $this->assertSame($factory, $this->resource->getFactory());
0 ignored issues
show
Bug introduced by
The method getFactory cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
203
    }
204
205
    public function testRepository()
206
    {
207
        $this->resource->setRepository($repository = $this->createRepositoryClassMock());
0 ignored issues
show
Bug introduced by
The method setRepository cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
208
209
        $this->assertSame($repository, $this->resource->getRepository());
0 ignored issues
show
Bug introduced by
The method getRepository cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
210
    }
211
212
    public function testForm()
213
    {
214
        $this->resource->setForm($form = $this->createFormClassMock());
0 ignored issues
show
Bug introduced by
The method setForm cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
215
216
        $this->assertSame($form, $this->resource->getForm());
0 ignored issues
show
Bug introduced by
The method getForm cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
217
    }
218
219
    public function testChoiceForm()
220
    {
221
        $this->resource->setChoiceForm($choiceForm = $this->createFormClassMock());
0 ignored issues
show
Bug introduced by
The method setChoiceForm cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
222
223
        $this->assertSame($choiceForm, $this->resource->getChoiceForm());
0 ignored issues
show
Bug introduced by
The method getChoiceForm cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
224
    }
225
226
    public function testDomainManager()
227
    {
228
        $this->resource->setDomainManager($domainManager = $this->createDomainManagerClassMock());
0 ignored issues
show
Bug introduced by
The method setDomainManager cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
229
230
        $this->assertSame($domainManager, $this->resource->getDomainManager());
0 ignored issues
show
Bug introduced by
The method getDomainManager cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
231
    }
232
233
    public function testController()
234
    {
235
        $this->resource->setController($controller = $this->createControllerClassMock());
0 ignored issues
show
Bug introduced by
The method setController cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
236
237
        $this->assertSame($controller, $this->resource->getController());
0 ignored issues
show
Bug introduced by
The method getController cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
238
    }
239
240
    public function testIdPropertyPath()
241
    {
242
        $this->resource->setIdPropertyPath($idPropertyPath = 'id');
0 ignored issues
show
Bug introduced by
The method setIdPropertyPath cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
243
244
        $this->assertSame($idPropertyPath, $this->resource->getIdPropertyPath());
0 ignored issues
show
Bug introduced by
The method getIdPropertyPath cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
245
    }
246
247
    public function testLabelPropertyPath()
248
    {
249
        $this->resource->setLabelPropertyPath($labelPropertyPath = 'label');
0 ignored issues
show
Bug introduced by
The method setLabelPropertyPath cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
250
251
        $this->assertSame($labelPropertyPath, $this->resource->getLabelPropertyPath());
0 ignored issues
show
Bug introduced by
The method getLabelPropertyPath cannot be called on $this->resource (of type resource).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
252
    }
253
254
    /**
255
     * @return string
256
     */
257
    private function createFactoryClassMock()
258
    {
259
        return $this->getMockClass(FactoryInterface::class);
260
    }
261
262
    /**
263
     * @return string
264
     */
265
    private function createRepositoryClassMock()
266
    {
267
        return $this->getMockClass(RepositoryInterface::class);
268
    }
269
270
    /**
271
     * @return string
272
     */
273
    private function createFormClassMock()
274
    {
275
        return $this->getMockClass(FormInterface::class);
276
    }
277
278
    /**
279
     * @return string
280
     */
281
    private function createControllerClassMock()
282
    {
283
        return $this->getMockClass(\stdClass::class);
284
    }
285
286
    /**
287
     * @return \PHPUnit_Framework_MockObject_MockObject|DomainManagerInterface
288
     */
289
    private function createDomainManagerClassMock()
290
    {
291
        return $this->createMock(DomainManagerInterface::class);
292
    }
293
294
    /**
295
     * @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface
296
     */
297
    private function createResourceMock()
298
    {
299
        return $this->createMock(ResourceInterface::class);
300
    }
301
}
302