These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace DoctrineModuleTest\Form\Element; |
||
6 | |||
7 | use Doctrine\Common\Collections\ArrayCollection; |
||
8 | use DoctrineModule\Form\Element\ObjectSelect; |
||
9 | use function get_class; |
||
10 | |||
11 | /** |
||
12 | * Tests for the ObjectSelect element |
||
13 | * |
||
14 | * @link http://www.doctrine-project.org/ |
||
15 | * |
||
16 | * @covers \DoctrineModule\Form\Element\ObjectSelect |
||
17 | */ |
||
18 | class ObjectSelectTest extends ProxyAwareElementTestCase |
||
19 | { |
||
20 | /** @var ArrayCollection */ |
||
21 | protected $values; |
||
22 | |||
23 | /** @var ObjectSelect */ |
||
24 | protected $element; |
||
25 | |||
26 | /** |
||
27 | * {@inheritDoc}. |
||
28 | */ |
||
29 | protected function setUp() : void |
||
30 | { |
||
31 | parent::setUp(); |
||
32 | $this->element = new ObjectSelect(); |
||
33 | |||
34 | $this->prepareProxy(); |
||
35 | } |
||
36 | |||
37 | public function testSetValueWithCollection() : void |
||
38 | { |
||
39 | $this->element->setAttribute('multiple', true); |
||
40 | |||
41 | $this->element->setValue( |
||
42 | $this->values |
||
43 | ); |
||
44 | |||
45 | $this->assertEquals( |
||
46 | [1, 2], |
||
47 | $this->element->getValue() |
||
48 | ); |
||
49 | } |
||
50 | |||
51 | public function testSetValueWithArray() : void |
||
52 | { |
||
53 | $this->element->setAttribute('multiple', true); |
||
54 | |||
55 | $this->element->setValue( |
||
56 | $this->values->toArray() |
||
57 | ); |
||
58 | |||
59 | $this->assertEquals( |
||
60 | [1, 2], |
||
61 | $this->element->getValue() |
||
62 | ); |
||
63 | } |
||
64 | |||
65 | public function testSetValueSingleValue() : void |
||
66 | { |
||
67 | $value = $this->values->toArray(); |
||
68 | |||
69 | $this->element->setValue( |
||
70 | $value[0] |
||
71 | ); |
||
72 | |||
73 | $this->assertEquals( |
||
74 | 1, |
||
75 | $this->element->getValue() |
||
76 | ); |
||
77 | } |
||
78 | |||
79 | public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArrayAndValidatorIsInitialized() : void |
||
80 | { |
||
81 | $element = $this->createPartialMock(get_class($this->element), ['setValueOptions']); |
||
82 | |||
83 | $options = []; |
||
84 | |||
85 | $proxy = $this->createMock('DoctrineModule\Form\Element\Proxy'); |
||
86 | $proxy->expects($this->exactly(2)) |
||
0 ignored issues
–
show
|
|||
87 | ->method('getValueOptions') |
||
88 | ->will($this->returnValue($options)); |
||
0 ignored issues
–
show
The method
returnValue() does not seem to exist on object<DoctrineModuleTes...ement\ObjectSelectTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
89 | |||
90 | $element->expects($this->never()) |
||
0 ignored issues
–
show
|
|||
91 | ->method('setValueOptions'); |
||
92 | |||
93 | $this->setProxyViaReflection($proxy, $element); |
||
0 ignored issues
–
show
$proxy is of type null , but the function expects a object<PHPUnit\Framework\MockObject\MockObject> .
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);
Loading history...
|
|||
94 | $element->getInputSpecification(); |
||
0 ignored issues
–
show
|
|||
95 | $this->assertEquals($options, $element->getValueOptions()); |
||
0 ignored issues
–
show
|
|||
96 | } |
||
97 | |||
98 | public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty() : void |
||
99 | { |
||
100 | $options = ['foo' => 'bar']; |
||
101 | |||
102 | $proxy = $this->createMock('DoctrineModule\Form\Element\Proxy'); |
||
103 | $proxy->expects($this->once()) |
||
0 ignored issues
–
show
|
|||
104 | ->method('getValueOptions') |
||
105 | ->will($this->returnValue($options)); |
||
0 ignored issues
–
show
The method
returnValue() does not seem to exist on object<DoctrineModuleTes...ement\ObjectSelectTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
106 | |||
107 | $this->setProxyViaReflection($proxy); |
||
0 ignored issues
–
show
$proxy is of type null , but the function expects a object<PHPUnit\Framework\MockObject\MockObject> .
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);
Loading history...
|
|||
108 | |||
109 | $this->assertEquals($options, $this->element->getValueOptions()); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<DoctrineModuleTes...ement\ObjectSelectTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
110 | $this->assertEquals($options, $this->element->getValueOptions()); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<DoctrineModuleTes...ement\ObjectSelectTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
111 | } |
||
112 | |||
113 | public function testOptionsCanBeSetSingle() : void |
||
114 | { |
||
115 | $proxy = $this->createMock('DoctrineModule\Form\Element\Proxy'); |
||
116 | $proxy->expects($this->once())->method('setOptions')->with(['is_method' => true]); |
||
117 | |||
118 | $this->setProxyViaReflection($proxy); |
||
119 | |||
120 | $this->element->setOption('is_method', true); |
||
121 | } |
||
122 | } |
||
123 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.