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

Form/Element/ObjectRadioTest.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 DoctrineModule\Form\Element\ObjectRadio;
8
use function get_class;
9
10
/**
11
 * Tests for the ObjectRadio element
12
 *
13
 * @covers \DoctrineModule\Form\Element\ObjectRadio
14
 */
15
class ObjectRadioTest extends ProxyAwareElementTestCase
16
{
17
    /** @var ObjectRadio */
18
    protected $element;
19
20
    /**
21
     * {@inheritDoc}.
22
     */
23
    protected function setUp() : void
24
    {
25
        parent::setUp();
26
        $this->element = new ObjectRadio();
27
    }
28
29
    public function testGetValueOptionsDoesntCauseInfiniteLoopIfProxyReturnsEmptyArrayAndValidatorIsInitialized() : void
30
    {
31
        $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...
32
33
        $options = [];
34
35
        $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...
36
        $proxy->expects($this->exactly(2))
37
            ->method('getValueOptions')
38
            ->will($this->returnValue($options));
39
40
        $element->expects($this->never())
41
            ->method('setValueOptions');
42
43
        $this->setProxyViaReflection($proxy, $element);
44
        $element->getInputSpecification();
45
        $this->assertEquals($options, $element->getValueOptions());
46
    }
47
48
    public function testGetValueOptionsDoesntInvokeProxyIfOptionsNotEmpty() : void
49
    {
50
        $options = ['foo' => 'bar'];
51
52
        $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...
53
        $proxy->expects($this->once())
54
            ->method('getValueOptions')
55
            ->will($this->returnValue($options));
56
57
        $this->setProxyViaReflection($proxy);
58
59
        $this->assertEquals($options, $this->element->getValueOptions());
60
        $this->assertEquals($options, $this->element->getValueOptions());
61
    }
62
63
    public function testOptionsCanBeSetSingle() : void
64
    {
65
        $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...
66
        $proxy->expects($this->once())->method('setOptions')->with(['is_method' => true]);
67
68
        $this->setProxyViaReflection($proxy);
69
70
        $this->element->setOption('is_method', true);
71
    }
72
}
73