Completed
Push — master ( 28a6ee...eae980 )
by Eric
9s
created

ResourceTest::testDriverManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
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 $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...
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];
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...
54
        $this->model = \ArrayIterator::class;
55
56
        $this->resource = new Resource($this->name, $this->interfaces, $this->model);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Lug\Component\Resou...terfaces, $this->model) 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...
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());
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...
67
        $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...
68
        $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...
69
        $this->assertNull($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...
70
        $this->assertNull($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...
71
        $this->assertNull($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...
72
        $this->assertNull($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...
73
        $this->assertNull($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...
74
        $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...
75
        $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...
76
        $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...
77
        $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...
78
        $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...
79
        $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...
80
        $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...
81
        $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...
82
    }
83
84
    public function testDriver()
85
    {
86
        $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...
87
88
        $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...
89
    }
90
91
    public function testDriverManager()
92
    {
93
        $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...
94
95
        $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...
96
    }
97
98
    public function testDriverMappingPath()
99
    {
100
        $this->resource->setDriverMappingPath($driverMappingPath = __DIR__);
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...
101
102
        $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...
103
    }
104
105
    public function testDriverMappingFormat()
106
    {
107
        $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...
108
109
        $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...
110
    }
111
112
    public function testModel()
113
    {
114
        $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...
115
116
        $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...
117
    }
118
119
    public function testFactory()
120
    {
121
        $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...
122
123
        $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...
124
    }
125
126
    public function testRepository()
127
    {
128
        $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...
129
130
        $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...
131
    }
132
133
    public function testForm()
134
    {
135
        $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...
136
137
        $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...
138
    }
139
140
    public function testChoiceForm()
141
    {
142
        $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...
143
144
        $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...
145
    }
146
147
    public function testDomainManager()
148
    {
149
        $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...
150
151
        $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...
152
    }
153
154
    public function testController()
155
    {
156
        $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...
157
158
        $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...
159
    }
160
161
    public function testIdPropertyPath()
162
    {
163
        $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...
164
165
        $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...
166
    }
167
168
    public function testLabelPropertyPath()
169
    {
170
        $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...
171
172
        $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...
173
    }
174
175
    public function testTranslation()
176
    {
177
        $this->resource->setTranslation($translation = $this->createResourceMock());
0 ignored issues
show
Bug introduced by
The method setTranslation 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...
178
179
        $this->assertSame($translation, $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...
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