This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the ONGR package. |
||
5 | * |
||
6 | * (c) NFQ Technologies UAB <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace ONGR\SettingsBundle\Tests\Unit\Service; |
||
13 | |||
14 | use Doctrine\Common\Cache\PhpFileCache; |
||
15 | use ONGR\CookiesBundle\Cookie\Model\GenericCookie; |
||
16 | use ONGR\ElasticsearchBundle\Result\DocumentIterator; |
||
17 | use ONGR\ElasticsearchBundle\Service\Manager; |
||
18 | use ONGR\ElasticsearchBundle\Service\Repository; |
||
19 | use ONGR\ElasticsearchDSL\Search; |
||
20 | use ONGR\SettingsBundle\Document\Setting; |
||
21 | use ONGR\SettingsBundle\Service\SettingsManager; |
||
22 | |||
23 | class SettingsManagerTest extends \PHPUnit_Framework_TestCase |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var Manager|\PHPUnit_Framework_MockObject_MockObject |
||
28 | */ |
||
29 | private $manager; |
||
30 | |||
31 | /** |
||
32 | * @var Repository|\PHPUnit_Framework_MockObject_MockObject |
||
33 | */ |
||
34 | private $repository; |
||
35 | |||
36 | /** |
||
37 | * @var PhpFileCache|\PHPUnit_Framework_MockObject_MockObject |
||
38 | */ |
||
39 | private $cache; |
||
40 | |||
41 | /** |
||
42 | * @var GenericCookie|\PHPUnit_Framework_MockObject_MockObject |
||
43 | */ |
||
44 | private $cookie; |
||
45 | |||
46 | public function setUp() |
||
47 | { |
||
48 | $this->manager = $this->getMockBuilder('ONGR\ElasticsearchBundle\Service\Manager') |
||
49 | ->disableOriginalConstructor() |
||
50 | ->setMethods(['persist', 'commit']) |
||
51 | ->getMock(); |
||
52 | $this->cache = $this->getMockBuilder('Doctrine\Common\Cache\PhpFileCache') |
||
53 | ->disableOriginalConstructor() |
||
54 | ->setMethods(['contains', 'fetch', 'save', 'delete']) |
||
55 | ->getMock(); |
||
56 | $this->cookie = $this->getMockBuilder('ONGR\CookiesBundle\Cookie\Model\GenericCookie') |
||
57 | ->disableOriginalConstructor() |
||
58 | ->setMethods(['getValue']) |
||
59 | ->getMock(); |
||
60 | $this->repository = $this->getMockBuilder('ONGR\ElasticsearchBundle\Service\Repository') |
||
61 | ->disableOriginalConstructor() |
||
62 | ->setMethods( |
||
63 | [ |
||
64 | 'findOneBy', |
||
65 | 'remove', |
||
66 | 'createSearch', |
||
67 | 'findDocuments', |
||
68 | 'getClassName', |
||
69 | 'getManager', |
||
70 | 'getAggregation', |
||
71 | ] |
||
72 | ) |
||
73 | ->getMock(); |
||
74 | |||
75 | $this->repository->expects($this->any())->method('getClassName')->willReturn(Setting::class); |
||
76 | $this->repository->expects($this->any())->method('getManager')->willReturn($this->manager); |
||
77 | $this->repository->expects($this->any())->method('createSearch')->willReturn(new Search()); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Test get cache getter. |
||
82 | */ |
||
83 | public function testGetCache() |
||
84 | { |
||
85 | $manager = new SettingsManager( |
||
86 | $this->repository, |
||
87 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
88 | ); |
||
89 | $manager->setCache($this->cache); |
||
90 | |||
91 | $this->assertInstanceOf('Doctrine\Common\Cache\PhpFileCache', $manager->getCache()); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Test get cookie getter. |
||
96 | */ |
||
97 | public function testGetActiveProfilesCookie() |
||
98 | { |
||
99 | $manager = new SettingsManager( |
||
100 | $this->repository, |
||
101 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
102 | ); |
||
103 | $manager->setActiveProfilesCookie($this->cookie); |
||
104 | |||
105 | $this->assertInstanceOf('ONGR\CookiesBundle\Cookie\Model\GenericCookie', $manager->getActiveProfilesCookie()); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Test get cookie getter. |
||
110 | */ |
||
111 | public function testGetActiveProfilesSettingName() |
||
112 | { |
||
113 | $manager = new SettingsManager( |
||
114 | $this->repository, |
||
115 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
116 | ); |
||
117 | $manager->setActiveProfilesSettingName('ongr'); |
||
118 | |||
119 | $this->assertEquals('ongr', $manager->getActiveProfilesSettingName()); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Test setting create function. |
||
124 | */ |
||
125 | public function testCreate() |
||
126 | { |
||
127 | $data = [ |
||
128 | 'name' => 'acme', |
||
129 | 'type' => 'string', |
||
130 | 'value' => 'foo', |
||
131 | ]; |
||
132 | |||
133 | $this->manager->expects($this->once())->method('persist')->with($this->callback(function ($obj) { |
||
0 ignored issues
–
show
|
|||
134 | return $obj instanceof Setting; |
||
135 | }))->willReturn(null); |
||
136 | $this->manager->expects($this->once())->method('persist')->willReturn(null); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Manager .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
137 | |||
138 | $manager = new SettingsManager( |
||
139 | $this->repository, |
||
140 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
141 | ); |
||
142 | $document = $manager->create($data); |
||
143 | |||
144 | foreach ($data as $key => $value) { |
||
145 | $this->assertEquals($value, $document->{'get' . ucfirst($key)}()); |
||
146 | } |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * @expectedException \LogicException |
||
151 | * @expectedExceptionMessage Missing one of the mandatory field! |
||
152 | */ |
||
153 | public function testCreateMandatoryParameters() |
||
154 | { |
||
155 | $data = ['bar' => 'foo']; |
||
156 | |||
157 | $manager = new SettingsManager( |
||
158 | $this->repository, |
||
159 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
160 | ); |
||
161 | $manager->create($data); |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * @expectedException \LogicException |
||
166 | * @expectedExceptionMessage Setting acme already exists. |
||
167 | */ |
||
168 | public function testCreateWhenSettingExists() |
||
169 | { |
||
170 | $data = [ |
||
171 | 'name' => 'acme', |
||
172 | 'type' => 'string', |
||
173 | 'value' => 'foo', |
||
174 | ]; |
||
175 | |||
176 | $this->repository->expects($this->once())->method('findOneBy')->willReturn(new Setting()); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
177 | |||
178 | $manager = new SettingsManager( |
||
179 | $this->repository, |
||
180 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
181 | ); |
||
182 | $manager->create($data); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * Tests setting create without value set. Should be set to 0 by default. |
||
187 | */ |
||
188 | public function testWithoutDataValueSet() |
||
189 | { |
||
190 | $data = [ |
||
191 | 'name' => 'acme', |
||
192 | 'type' => 'string', |
||
193 | ]; |
||
194 | |||
195 | $manager = new SettingsManager( |
||
196 | $this->repository, |
||
197 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
198 | ); |
||
199 | $document = $manager->create($data); |
||
200 | |||
201 | $this->assertEquals(0, $document->getValue()); |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * Tests setting update. |
||
206 | */ |
||
207 | public function testUpdate() |
||
208 | { |
||
209 | $setting = new Setting(); |
||
210 | $setting->setName('acme'); |
||
211 | $setting->setValue('foo'); |
||
212 | |||
213 | $this->repository->expects($this->once())->method('findOneBy')->willReturn($setting); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
214 | $manager = new SettingsManager( |
||
215 | $this->repository, |
||
216 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
217 | ); |
||
218 | $manager->setCache($this->cache); |
||
219 | |||
220 | $document = $manager->update('acme', ['value' => 'bar']); |
||
221 | $this->assertEquals('acme', $document->getName()); |
||
222 | $this->assertEquals('bar', $document->getValue()); |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * @expectedException \LogicException |
||
227 | * @expectedExceptionMessage Setting acme not exist. |
||
228 | */ |
||
229 | View Code Duplication | public function testUpdateWhenSettingNotExists() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
230 | { |
||
231 | $this->repository->expects($this->once())->method('findOneBy')->willReturn(null); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
232 | |||
233 | $manager = new SettingsManager( |
||
234 | $this->repository, |
||
235 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
236 | ); |
||
237 | $manager->setCache($this->cache); |
||
238 | $manager->update('acme', ['value' => 'foo']); |
||
239 | } |
||
240 | |||
241 | /** |
||
242 | * Tests setting delete. |
||
243 | */ |
||
244 | View Code Duplication | public function testDelete() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
245 | { |
||
246 | $setting = new Setting(); |
||
247 | $setting->setId('acme'); |
||
248 | $setting->setName('acme'); |
||
249 | |||
250 | $this->repository->expects($this->any()) |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
251 | ->method('findOneBy')->with($this->equalTo(['name.name' => 'acme']))->willReturn($setting); |
||
252 | $manager = new SettingsManager( |
||
253 | $this->repository, |
||
254 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
255 | ); |
||
256 | $manager->setCache($this->cache); |
||
257 | |||
258 | $manager->delete('acme'); |
||
259 | } |
||
260 | |||
261 | View Code Duplication | public function testHas() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
262 | { |
||
263 | $setting = new Setting(); |
||
264 | $setting->setName('acme'); |
||
265 | $setting->setValue('foo'); |
||
266 | |||
267 | $this->repository->expects($this->once()) |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
268 | ->method('findOneBy')->with($this->equalTo(['name.name' => 'acme']))->willReturn($setting); |
||
269 | $manager = new SettingsManager( |
||
270 | $this->repository, |
||
271 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
272 | ); |
||
273 | |||
274 | $result = $manager->has('acme'); |
||
275 | |||
276 | $this->assertTrue($result); |
||
277 | } |
||
278 | |||
279 | /** |
||
280 | * Test has method when there is no setting. |
||
281 | */ |
||
282 | View Code Duplication | public function testHasWhenThereIsNoSetting() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
283 | { |
||
284 | $this->repository->expects($this->once()) |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
285 | ->method('findOneBy')->with($this->equalTo(['name.name' => 'acme']))->willReturn(null); |
||
286 | $manager = new SettingsManager( |
||
287 | $this->repository, |
||
288 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
289 | ); |
||
290 | |||
291 | $result = $manager->has('acme'); |
||
292 | |||
293 | $this->assertFalse($result); |
||
294 | } |
||
295 | |||
296 | /** |
||
297 | * Tests setting update. |
||
298 | */ |
||
299 | View Code Duplication | public function testGetValue() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
300 | { |
||
301 | $setting = new Setting(); |
||
302 | $setting->setName('acme'); |
||
303 | $setting->setValue('foo'); |
||
304 | |||
305 | $this->repository->expects($this->once())->method('findOneBy')->willReturn($setting); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
306 | $manager = new SettingsManager( |
||
307 | $this->repository, |
||
308 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
309 | ); |
||
310 | |||
311 | $result = $manager->getValue('acme'); |
||
312 | $this->assertEquals('foo', $result); |
||
313 | } |
||
314 | |||
315 | /** |
||
316 | * Tests setting update. |
||
317 | */ |
||
318 | View Code Duplication | public function testGetValueWhenThereIsNoSetting() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
319 | { |
||
320 | $this->repository->expects($this->once())->method('findOneBy')->willReturn(null); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
321 | $manager = new SettingsManager( |
||
322 | $this->repository, |
||
323 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
324 | ); |
||
325 | |||
326 | $result = $manager->getValue('acme', 'bar'); |
||
0 ignored issues
–
show
'bar' is of type string , but the function expects a boolean|null .
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: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
327 | $this->assertEquals('bar', $result); |
||
328 | } |
||
329 | |||
330 | /** |
||
331 | * Returns document iterator with pre-loaded aggregations. |
||
332 | * |
||
333 | * @return DocumentIterator |
||
334 | */ |
||
335 | private function getDocumentIterator() |
||
336 | { |
||
337 | $rawData = [ |
||
338 | 'aggregations' => [ |
||
339 | 'filter' => [ |
||
340 | 'profiles' => [ |
||
341 | 'buckets' => [ |
||
342 | [ |
||
343 | 'key' => 'default', |
||
344 | 'doc_count' => 2, |
||
345 | 'documents' => [ |
||
346 | 'hits' => [ |
||
347 | 'total' => 2, |
||
348 | 'max_score' => 1, |
||
349 | 'hits' => [ |
||
350 | [ |
||
351 | '_index' => 'settings', |
||
352 | '_type' => 'setting', |
||
353 | '_id' => 'kk', |
||
354 | '_score' => 1, |
||
355 | '_source' => [ |
||
356 | 'name' => 'foo', |
||
357 | 'profile' => [ |
||
358 | 'bar' |
||
359 | ], |
||
360 | 'type' => 'bool', |
||
361 | 'value' => 1 |
||
362 | ] |
||
363 | ], |
||
364 | [ |
||
365 | '_index' => 'settings', |
||
366 | '_type' => 'setting', |
||
367 | '_id' => 'xx', |
||
368 | '_score' => 1, |
||
369 | '_source' => [ |
||
370 | 'name' => 'kk', |
||
371 | 'profile' => [ |
||
372 | 'kk' |
||
373 | ], |
||
374 | 'type' => 'bool', |
||
375 | 'value' => 1 |
||
376 | ] |
||
377 | ] |
||
378 | ] |
||
379 | ] |
||
380 | ], |
||
381 | 'key' => 'foo', |
||
382 | 'doc_count' => 1, |
||
383 | 'documents' => [ |
||
384 | 'hits' => [ |
||
385 | 'total' => 1, |
||
386 | 'max_score' => 1, |
||
387 | 'hits' => [ |
||
388 | [ |
||
389 | '_index' => 'settings', |
||
390 | '_type' => 'setting', |
||
391 | '_id' => 'kk', |
||
392 | '_score' => 1, |
||
393 | '_source' => [ |
||
394 | 'name' => 'foo', |
||
395 | 'profile' => [ |
||
396 | 'bar' |
||
397 | ], |
||
398 | 'type' => 'bool', |
||
399 | 'value' => 1 |
||
400 | ] |
||
401 | ] |
||
402 | ] |
||
403 | ] |
||
404 | ], |
||
405 | 'key' => 'kk', |
||
406 | 'doc_count' => 1, |
||
407 | 'documents' => [ |
||
408 | 'hits' => [ |
||
409 | 'total' => 1, |
||
410 | 'max_score' => 1, |
||
411 | 'hits' => [ |
||
412 | [ |
||
413 | '_index' => 'settings', |
||
414 | '_type' => 'setting', |
||
415 | '_id' => 'kk', |
||
416 | '_score' => 1, |
||
417 | '_source' => [ |
||
418 | 'name' => 'foo', |
||
419 | 'profile' => [ |
||
420 | 'bar' |
||
421 | ], |
||
422 | 'type' => 'bool', |
||
423 | 'value' => 1 |
||
424 | ] |
||
425 | ] |
||
426 | ] |
||
427 | ] |
||
428 | ] |
||
429 | ] |
||
430 | ] |
||
431 | ] |
||
432 | ] |
||
433 | ] |
||
434 | ]; |
||
435 | |||
436 | return new DocumentIterator($rawData, $this->manager); |
||
437 | } |
||
438 | |||
439 | /** |
||
440 | * Tests setting update. |
||
441 | */ |
||
442 | public function testGetCachedValue() |
||
443 | { |
||
444 | |||
445 | $activeProfilesSetting = 'active_profiles'; |
||
446 | |||
447 | $this->repository->expects($this->any())->method('findOneBy')->willReturnCallback( |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
448 | function ($arg) use ($activeProfilesSetting) { |
||
449 | $settingName = $arg['name.name']; |
||
450 | $setting = new Setting(); |
||
451 | switch ($settingName) { |
||
452 | case 'active_profiles': |
||
453 | $setting->setName($activeProfilesSetting); |
||
454 | $setting->setValue(['bar', 'foo']); |
||
0 ignored issues
–
show
array('bar', 'foo') is of type array<integer,string,{"0":"string","1":"string"}> , but the function expects a string .
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: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
455 | return $setting; |
||
456 | break; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
457 | case 'acme': |
||
458 | $setting->setName('acme'); |
||
459 | $setting->setValue('foo'); |
||
460 | $setting->setProfile(['foo', 'default']); |
||
461 | break; |
||
462 | } |
||
463 | return $setting; |
||
464 | } |
||
465 | ); |
||
466 | |||
467 | $this->repository->expects($this->any())->method('findDocuments')->willReturn($this->getDocumentIterator()); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
468 | $this->cookie->expects($this->any())->method('getValue')->willReturn(['foo']); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\CookiesBundle\Cookie\Model\GenericCookie .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
469 | |||
470 | $manager = new SettingsManager( |
||
471 | $this->repository, |
||
472 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
473 | ); |
||
474 | $manager->setCache($this->cache); |
||
475 | $manager->setActiveProfilesSettingName($activeProfilesSetting); |
||
476 | $manager->setActiveProfilesCookie($this->cookie); |
||
477 | $manager->setActiveProfilesList(['default']); |
||
478 | |||
479 | $result = $manager->getCachedValue('acme'); |
||
480 | $this->assertEquals('foo', $result); |
||
481 | } |
||
482 | |||
483 | /** |
||
484 | * Tests setting update. |
||
485 | */ |
||
486 | public function testGetCachedValueFromCache() |
||
487 | { |
||
488 | |||
489 | $activeProfilesSetting = 'active_profiles'; |
||
490 | |||
491 | $this->repository->expects($this->any())->method('execute')->willReturn($this->getDocumentIterator()); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
492 | $this->cookie->expects($this->any())->method('getValue')->willReturn(['foo']); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\CookiesBundle\Cookie\Model\GenericCookie .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
493 | $this->cache->expects($this->any())->method('contains')->willReturn(true); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in Doctrine\Common\Cache\PhpFileCache .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
494 | $this->cache->expects($this->any())->method('fetch')->willReturnCallback( |
||
495 | function ($arg) use ($activeProfilesSetting) { |
||
496 | if ($arg == $activeProfilesSetting) { |
||
497 | return ['foo']; |
||
498 | } |
||
499 | return ['value' => 'foo', 'profiles' => ['foo']]; |
||
500 | } |
||
501 | ); |
||
502 | |||
503 | $manager = new SettingsManager( |
||
504 | $this->repository, |
||
505 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
506 | ); |
||
507 | $manager->setCache($this->cache); |
||
508 | $manager->setActiveProfilesSettingName($activeProfilesSetting); |
||
509 | $manager->setActiveProfilesCookie($this->cookie); |
||
510 | |||
511 | $result = $manager->getCachedValue('acme'); |
||
512 | $this->assertEquals('foo', $result); |
||
513 | } |
||
514 | |||
515 | /** |
||
516 | * Tests setting update. |
||
517 | */ |
||
518 | public function testGetCachedValueWithoutActiveProfiles() |
||
519 | { |
||
520 | $activeProfilesSetting = 'active_profiles'; |
||
521 | $this->repository->expects($this->any())->method('execute')->willReturn($this->getDocumentIterator()); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
522 | $this->cookie->expects($this->any())->method('getValue')->willReturn(['foo']); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\CookiesBundle\Cookie\Model\GenericCookie .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
523 | $this->cache->expects($this->any())->method('contains')->willReturn(true); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in Doctrine\Common\Cache\PhpFileCache .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
524 | $this->cache->expects($this->any())->method('fetch')->willReturn(['value' => 'foo', 'profiles' => ['foo']]); |
||
525 | |||
526 | $manager = new SettingsManager( |
||
527 | $this->repository, |
||
528 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
529 | ); |
||
530 | $manager->setCache($this->cache); |
||
531 | $manager->setActiveProfilesSettingName($activeProfilesSetting); |
||
532 | $manager->setActiveProfilesCookie($this->cookie); |
||
533 | |||
534 | $result = $manager->getCachedValue('acme', false); |
||
535 | $this->assertEquals('foo', $result); |
||
536 | } |
||
537 | |||
538 | /** |
||
539 | * Tests if there is no setting. |
||
540 | */ |
||
541 | public function testGetCachedValueWhenItsNotExist() |
||
542 | { |
||
543 | $activeProfilesSetting = 'active_profiles'; |
||
544 | $this->repository->expects($this->any())->method('execute')->willReturn($this->getDocumentIterator()); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
545 | $manager = new SettingsManager( |
||
546 | $this->repository, |
||
547 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
548 | ); |
||
549 | $manager->setCache($this->cache); |
||
550 | $manager->setActiveProfilesSettingName($activeProfilesSetting); |
||
551 | |||
552 | $value = $manager->getCachedValue('acme'); |
||
553 | $this->assertNull($value); |
||
554 | } |
||
555 | |||
556 | public function testGetAllActiveProfilesNameList() |
||
557 | { |
||
558 | $document = new Setting(); |
||
559 | $document->setName('active_profiles'); |
||
560 | $document->setValue(['kk']); |
||
0 ignored issues
–
show
array('kk') is of type array<integer,string,{"0":"string"}> , but the function expects a string .
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: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
561 | $this->repository->expects($this->any())->method('findOneBy')->willReturn($document); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
562 | $this->repository->expects($this->any())->method('findDocuments')->willReturn($this->getDocumentIterator()); |
||
563 | $manager = new SettingsManager( |
||
564 | $this->repository, |
||
565 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
566 | ); |
||
567 | $manager->setCache($this->cache); |
||
568 | |||
569 | $value = $manager->getActiveProfiles(); |
||
570 | $this->assertEquals(['kk'], $value); |
||
571 | } |
||
572 | |||
573 | public function testGetActiveExperimentsFromRepository() |
||
574 | { |
||
575 | $activeExperimentsSettingName = 'foo'; |
||
576 | $experimentName = 'bar'; |
||
577 | $cache = $this->cache; |
||
578 | $cache->expects($this->any())->method('contains')->willReturn(false); |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in Doctrine\Common\Cache\PhpFileCache .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
579 | $activeExperiments = new Setting; |
||
580 | $activeExperiments->setName($activeExperimentsSettingName); |
||
581 | $activeExperiments->setValue([$experimentName]); |
||
0 ignored issues
–
show
array($experimentName) is of type array<integer,string,{"0":"string"}> , but the function expects a string .
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: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
582 | $repository = $this->repository; |
||
583 | $repository->expects($this->any())->method('findOneBy') |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
584 | ->with(['name.name' => $activeExperimentsSettingName])->willReturn($activeExperiments); |
||
585 | $manager = new SettingsManager( |
||
586 | $repository, |
||
0 ignored issues
–
show
It seems like
$repository defined by $this->repository on line 582 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, ONGR\SettingsBundle\Serv...sManager::__construct() does only seem to accept object<ONGR\Elasticsearc...dle\Service\Repository> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
587 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
588 | ); |
||
589 | $manager->setActiveExperimentsSettingName($activeExperimentsSettingName); |
||
590 | $manager->setCache($cache); |
||
0 ignored issues
–
show
It seems like
$cache defined by $this->cache on line 577 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, ONGR\SettingsBundle\Serv...ingsManager::setCache() does only seem to accept object<Doctrine\Common\Cache\CacheProvider> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
591 | |||
592 | $activeExperiments = $manager->getActiveExperiments(); |
||
593 | |||
594 | $this->assertEquals([$experimentName], $activeExperiments); |
||
595 | } |
||
596 | |||
597 | View Code Duplication | public function testGetActiveExperimentsFromCache() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
598 | { |
||
599 | $activeExperimentsSettingName = 'foo'; |
||
600 | $experimentName = 'bar'; |
||
601 | $cache = $this->cache; |
||
602 | $cache->expects($this->any())->method('contains') |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in Doctrine\Common\Cache\PhpFileCache .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
603 | ->with($activeExperimentsSettingName)->willReturn(true); |
||
604 | $cache->expects($this->any())->method('fetch') |
||
605 | ->with($activeExperimentsSettingName)->willReturn(['value' => [$experimentName]]); |
||
606 | $manager = new SettingsManager( |
||
607 | $this->repository, |
||
608 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
609 | ); |
||
610 | $manager->setActiveExperimentsSettingName($activeExperimentsSettingName); |
||
611 | $manager->setCache($cache); |
||
0 ignored issues
–
show
It seems like
$cache defined by $this->cache on line 601 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, ONGR\SettingsBundle\Serv...ingsManager::setCache() does only seem to accept object<Doctrine\Common\Cache\CacheProvider> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
612 | |||
613 | $activeExperiments = $manager->getActiveExperiments(); |
||
614 | |||
615 | $this->assertEquals([$experimentName], $activeExperiments); |
||
616 | } |
||
617 | |||
618 | View Code Duplication | public function testGetActiveExperimentsCreateNew() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
619 | { |
||
620 | $activeExperimentsSettingName = 'foo'; |
||
621 | $cache = $this->cache; |
||
622 | $cache->expects($this->any())->method('contains') |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in Doctrine\Common\Cache\PhpFileCache .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
623 | ->with($activeExperimentsSettingName)->willReturn(false); |
||
624 | $repository = $this->repository; |
||
625 | $repository->expects($this->any())->method('findOneBy') |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
626 | ->with(['name.name' => $activeExperimentsSettingName])->willReturn(null); |
||
627 | $manager = new SettingsManager( |
||
628 | $repository, |
||
0 ignored issues
–
show
It seems like
$repository defined by $this->repository on line 624 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, ONGR\SettingsBundle\Serv...sManager::__construct() does only seem to accept object<ONGR\Elasticsearc...dle\Service\Repository> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
629 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
630 | ); |
||
631 | $manager->setActiveExperimentsSettingName($activeExperimentsSettingName); |
||
632 | $manager->setCache($cache); |
||
0 ignored issues
–
show
It seems like
$cache defined by $this->cache on line 621 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, ONGR\SettingsBundle\Serv...ingsManager::setCache() does only seem to accept object<Doctrine\Common\Cache\CacheProvider> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
633 | |||
634 | $activeExperiments = $manager->getActiveExperiments(); |
||
635 | |||
636 | $this->assertEquals([], $activeExperiments); |
||
637 | } |
||
638 | |||
639 | public function testToggleExperiment() |
||
640 | { |
||
641 | $activeExperimentsSettingName = 'active_profiles'; |
||
642 | $activeExperimentsSetting = new Setting(); |
||
643 | $activeExperimentsSetting->setName($activeExperimentsSettingName); |
||
644 | $repository = $this->repository; |
||
645 | $repository->expects($this->any())->method('findOneBy') |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
646 | ->with(['name.name' => $activeExperimentsSettingName])->willReturn($activeExperimentsSetting); |
||
647 | $manager = new SettingsManager( |
||
648 | $repository, |
||
0 ignored issues
–
show
It seems like
$repository defined by $this->repository on line 644 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, ONGR\SettingsBundle\Serv...sManager::__construct() does only seem to accept object<ONGR\Elasticsearc...dle\Service\Repository> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
649 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
650 | ); |
||
651 | $manager->setCache($this->cache); |
||
652 | $manager->setActiveExperimentsSettingName($activeExperimentsSettingName); |
||
653 | $manager->toggleExperiment('foo'); |
||
654 | $this->assertEquals(['foo'], $activeExperimentsSetting->getValue()); |
||
655 | } |
||
656 | |||
657 | /** |
||
658 | * @expectedException \LogicException |
||
659 | * @expectedExceptionMessage The setting `active_profiles` is not set |
||
660 | */ |
||
661 | public function testGetCachedExperimentException() |
||
662 | { |
||
663 | $activeExperimentsSettingName = 'active_profiles'; |
||
664 | $repository = $this->repository; |
||
665 | $repository->expects($this->any())->method('findOneBy') |
||
0 ignored issues
–
show
The method
expects does only exist in PHPUnit_Framework_MockObject_MockObject , but not in ONGR\ElasticsearchBundle\Service\Repository .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
666 | ->with(['name.name' => $activeExperimentsSettingName])->willReturn(null); |
||
667 | $manager = new SettingsManager( |
||
668 | $repository, |
||
0 ignored issues
–
show
It seems like
$repository defined by $this->repository on line 664 can also be of type object<PHPUnit_Framework_MockObject_MockObject> ; however, ONGR\SettingsBundle\Serv...sManager::__construct() does only seem to accept object<ONGR\Elasticsearc...dle\Service\Repository> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
669 | $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface') |
||
670 | ); |
||
671 | $manager->setActiveExperimentsSettingName($activeExperimentsSettingName); |
||
672 | $manager->toggleExperiment('foo'); |
||
673 | } |
||
674 | } |
||
675 |
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: