ObjectMultiCheckboxTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 87
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testSetValueWithCollection() 0 11 1
A testSetValueWithArray() 0 11 1
A testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArrayAndValidatorIsInitialized() 0 18 1
A testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty() 0 14 1
A testOptionsCanBeSetSingle() 0 9 1
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();
0 ignored issues
show
Bug introduced by
The method getInputSpecification() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
77
        $this->assertEquals($options, $element->getValueOptions());
0 ignored issues
show
Bug introduced by
The method getValueOptions() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
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);
101
102
        $this->element->setOption('is_method', true);
103
    }
104
}
105