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

Form/Element/ProxyAwareElementTestCase.php (14 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 DoctrineModuleTest\Form\Element\TestAsset\FormObject;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use PHPUnit\Framework\TestCase;
11
use ReflectionProperty;
12
use function array_shift;
13
use function func_get_args;
14
use function get_class;
15
16
class ProxyAwareElementTestCase extends TestCase
17
{
18
    /** @var MockObject */
19
    protected $element;
20
21
    protected function prepareProxy() : void
22
    {
23
        $objectClass = 'DoctrineModuleTest\Form\Element\TestAsset\FormObject';
24
        $objectOne   = new FormObject();
25
        $objectTwo   = new FormObject();
26
27
        $objectOne->setId(1)
28
            ->setUsername('object one username')
29
            ->setPassword('object one password')
30
            ->setEmail('object one email')
31
            ->setFirstname('object one firstname')
32
            ->setSurname('object one surname');
33
34
        $objectTwo->setId(2)
35
            ->setUsername('object two username')
36
            ->setPassword('object two password')
37
            ->setEmail('object two email')
38
            ->setFirstname('object two firstname')
39
            ->setSurname('object two surname');
40
41
        $result       = new ArrayCollection([$objectOne, $objectTwo]);
42
        $this->values = $result;
0 ignored issues
show
The property values does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
44
        $metadata = $this->createMock('Doctrine\Persistence\Mapping\ClassMetadata');
0 ignored issues
show
Are you sure the assignment to $metadata is correct as $this->createMock('Doctr...apping\\ClassMetadata') (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...
45
        $metadata
0 ignored issues
show
The method expects cannot be called on $metadata (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
46
            ->expects($this->any())
0 ignored issues
show
The method any() does not seem to exist on object<DoctrineModuleTes...xyAwareElementTestCase>.

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...
47
            ->method('getIdentifierValues')
48
            ->will(
49
                $this->returnCallback(
0 ignored issues
show
The method returnCallback() does not seem to exist on object<DoctrineModuleTes...xyAwareElementTestCase>.

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...
50
                    static function () use ($objectOne, $objectTwo) {
51
                        $input = func_get_args();
52
                        $input = array_shift($input);
53
54
                        if ($input === $objectOne) {
55
                            return ['id' => 1];
56
                        }
57
58
                        if ($input === $objectTwo) {
59
                            return ['id' => 2];
60
                        }
61
62
                        return [];
63
                    }
64
                )
65
            );
66
67
        $objectRepository = $this->createMock('Doctrine\Persistence\ObjectRepository');
0 ignored issues
show
Are you sure the assignment to $objectRepository is correct as $this->createMock('Doctr...nce\\ObjectRepository') (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...
68
        $objectRepository->expects($this->any())
0 ignored issues
show
The method expects cannot be called on $objectRepository (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
69
            ->method('findAll')
70
            ->will($this->returnValue($result));
71
72
        $objectManager = $this->createMock('Doctrine\Persistence\ObjectManager');
0 ignored issues
show
Are you sure the assignment to $objectManager is correct as $this->createMock('Doctr...stence\\ObjectManager') (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...
73
        $objectManager->expects($this->any())
0 ignored issues
show
The method expects cannot be called on $objectManager (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
74
            ->method('getClassMetadata')
75
            ->with($this->equalTo($objectClass))
0 ignored issues
show
The method equalTo() does not seem to exist on object<DoctrineModuleTes...xyAwareElementTestCase>.

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...
76
            ->will($this->returnValue($metadata));
77
78
        $objectManager
0 ignored issues
show
The method expects cannot be called on $objectManager (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
79
            ->expects($this->any())
0 ignored issues
show
The method any() does not seem to exist on object<DoctrineModuleTes...xyAwareElementTestCase>.

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...
80
            ->method('getRepository')
81
            ->with($this->equalTo($objectClass))
0 ignored issues
show
The method equalTo() does not seem to exist on object<DoctrineModuleTes...xyAwareElementTestCase>.

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...
82
            ->will($this->returnValue($objectRepository));
83
84
        $this->element->getProxy()->setOptions([
0 ignored issues
show
The method getProxy() 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...
85
            'object_manager' => $objectManager,
86
            'target_class'   => $objectClass,
87
        ]);
88
89
        $this->metadata = $metadata;
90
    }
91
92
    /**
93
     * Proxy should stay read only, use with care
94
     */
95
    protected function setProxyViaReflection(MockObject $proxy, ?MockObject $element = null) : void
96
    {
97
        if (! $element) {
98
            $element = $this->element;
99
        }
100
101
        $prop = new ReflectionProperty(get_class($this->element), 'proxy');
102
        $prop->setAccessible(true);
103
        $prop->setValue($element, $proxy);
104
    }
105
}
106