Completed
Push — master ( e0017c...6b1304 )
by Tom
14s queued 11s
created

Form/Element/ObjectMultiCheckboxTest.php (1 issue)

mismatching argument types.

Documentation Minor

Upgrade to new PHP Analysis Engine

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\ObjectMultiCheckbox;
9
use function get_class;
10
11
/**
12
 * Tests for the ObjectMultiCheckbox element
13
 *
14
 * @link    http://www.doctrine-project.org/
15
 *
16
 * @covers  \DoctrineModule\Form\Element\ObjectMultiCheckbox
17
 */
18
class ObjectMultiCheckboxTest extends ProxyAwareElementTestCase
19
{
20
    /** @var ArrayCollection */
21
    protected $values;
22
23
    /** @var ObjectMultiCheckbox */
24
    protected $element;
25
26
    /**
27
     * {@inheritDoc}.
28
     */
29
    protected function setUp() : void
30
    {
31
        parent::setUp();
32
        $this->element = new ObjectMultiCheckbox();
33
34
        $this->prepareProxy();
35
    }
36
37
    public function testSetValueWithCollection() : void
38
    {
39
        $this->element->setValue(
40
            $this->values
41
        );
42
43
        $this->assertEquals(
44
            [1, 2],
45
            $this->element->getValue()
46
        );
47
    }
48
49
    public function testSetValueWithArray() : void
50
    {
51
        $this->element->setValue(
52
            $this->values->toArray()
53
        );
54
55
        $this->assertEquals(
56
            [1, 2],
57
            $this->element->getValue()
58
        );
59
    }
60
61
    public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArrayAndValidatorIsInitialized() : void
62
    {
63
        $element = $this->createPartialMock(get_class($this->element), ['setValueOptions']);
64
65
        $options = [];
66
67
        $proxy = $this->createMock('DoctrineModule\Form\Element\Proxy');
68
        $proxy->expects($this->exactly(2))
69
            ->method('getValueOptions')
70
            ->will($this->returnValue($options));
71
72
        $element->expects($this->never())
73
            ->method('setValueOptions');
74
75
        $this->setProxyViaReflection($proxy, $element);
76
        $element->getInputSpecification();
77
        $this->assertEquals($options, $element->getValueOptions());
78
    }
79
80
    public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty() : void
81
    {
82
        $options = ['foo' => 'bar'];
83
84
        $proxy = $this->createMock('DoctrineModule\Form\Element\Proxy');
85
        $proxy->expects($this->once())
86
            ->method('getValueOptions')
87
            ->will($this->returnValue($options));
88
89
        $this->setProxyViaReflection($proxy);
90
91
        $this->assertEquals($options, $this->element->getValueOptions());
92
        $this->assertEquals($options, $this->element->getValueOptions());
93
    }
94
95
    public function testOptionsCanBeSetSingle() : void
96
    {
97
        $proxy = $this->createMock('DoctrineModule\Form\Element\Proxy');
98
        $proxy->expects($this->once())->method('setOptions')->with(['is_method' => true]);
99
100
        $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...
101
102
        $this->element->setOption('is_method', true);
103
    }
104
}
105