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

Form/Element/ObjectSelectTest.php (4 issues)

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\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']);
0 ignored issues
show
Are you sure the assignment to $element is correct as $this->createPartialMock...ray('setValueOptions')) (which targets PHPUnit\Framework\TestCase::createPartialMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
82
83
        $options = [];
84
85
        $proxy = $this->createMock('DoctrineModule\Form\Element\Proxy');
0 ignored issues
show
Are you sure the assignment to $proxy is correct as $this->createMock('Doctr...\Form\\Element\\Proxy') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
86
        $proxy->expects($this->exactly(2))
87
              ->method('getValueOptions')
88
              ->will($this->returnValue($options));
89
90
        $element->expects($this->never())
91
                ->method('setValueOptions');
92
93
        $this->setProxyViaReflection($proxy, $element);
94
        $element->getInputSpecification();
95
        $this->assertEquals($options, $element->getValueOptions());
96
    }
97
98
    public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty() : void
99
    {
100
        $options = ['foo' => 'bar'];
101
102
        $proxy = $this->createMock('DoctrineModule\Form\Element\Proxy');
0 ignored issues
show
Are you sure the assignment to $proxy is correct as $this->createMock('Doctr...\Form\\Element\\Proxy') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
103
        $proxy->expects($this->once())
104
              ->method('getValueOptions')
105
              ->will($this->returnValue($options));
106
107
        $this->setProxyViaReflection($proxy);
108
109
        $this->assertEquals($options, $this->element->getValueOptions());
110
        $this->assertEquals($options, $this->element->getValueOptions());
111
    }
112
113
    public function testOptionsCanBeSetSingle() : void
114
    {
115
        $proxy = $this->createMock('DoctrineModule\Form\Element\Proxy');
0 ignored issues
show
Are you sure the assignment to $proxy is correct as $this->createMock('Doctr...\Form\\Element\\Proxy') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

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