EntityHydratorLazyLoadProxyTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 66
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldForwardEntityHydration() 0 14 1
A setUp() 0 10 1
A shouldForwardEntityHydrationAssertion() 0 14 1
1
<?php
2
/**
3
 * Copyright (C) 2017  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\RDMBundle\Tests\Hydration;
12
13
use PHPUnit\Framework\TestCase;
14
use Doctrine\ORM\EntityManagerInterface;
15
use Symfony\Component\DependencyInjection\ContainerInterface;
16
use Addiks\RDMBundle\Hydration\EntityHydratorLazyLoadProxy;
17
use Addiks\RDMBundle\Tests\Hydration\EntityExample;
18
use Addiks\RDMBundle\Hydration\EntityHydratorInterface;
19
20
final class EntityHydratorLazyLoadProxyTest extends TestCase
21
{
22
23
    /**
24
     * @var EntityHydratorLazyLoadProxy
25
     */
26
    private $hydratorProxy;
27
28
    /**
29
     * @var ContainerInterface
30
     */
31
    private $container;
32
33
    /**
34
     * @var EntityHydratorInterface
35
     */
36
    private $innerHydrator;
37
38
    public function setUp(): void
39
    {
40
        $this->innerHydrator = $this->createMock(EntityHydratorInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Addiks...dratorInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Addiks\RDMBundle\Hydration\EntityHydratorInterface of property $innerHydrator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
42
        $this->container = $this->createMock(ContainerInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Symfon...tainerInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Symfony\Component\Depend...tion\ContainerInterface of property $container.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
        $this->container->method("get")->will($this->returnValueMap([
44
            ["some_service_id", ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->innerHydrator]
45
        ]));
46
47
        $this->hydratorProxy = new EntityHydratorLazyLoadProxy($this->container, "some_service_id");
48
    }
49
50
    /**
51
     * @test
52
     */
53
    public function shouldForwardEntityHydration()
54
    {
55
        /** @var EntityExample $entity */
56
        $entity = $this->createMock(EntityExample::class);
57
58
        /** @var EntityManagerInterface $entityManager */
59
        $entityManager = $this->createMock(EntityManagerInterface::class);
60
61
        $this->innerHydrator->expects($this->once())->method("hydrateEntity")->with(
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Addiks\RDMBundle\Hydration\EntityHydratorInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
        $this->innerHydrator->/** @scrutinizer ignore-call */ 
62
                              expects($this->once())->method("hydrateEntity")->with(

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...
62
            $this->equalTo($entity),
63
            $this->equalTo($entityManager)
64
        );
65
66
        $this->hydratorProxy->hydrateEntity($entity, $entityManager);
67
    }
68
69
    /**
70
     * @test
71
     */
72
    public function shouldForwardEntityHydrationAssertion()
73
    {
74
        /** @var EntityExample $entity */
75
        $entity = $this->createMock(EntityExample::class);
76
77
        /** @var EntityManagerInterface $entityManager */
78
        $entityManager = $this->createMock(EntityManagerInterface::class);
79
80
        $this->innerHydrator->expects($this->once())->method("assertHydrationOnEntity")->with(
81
            $this->equalTo($entity),
82
            $this->equalTo($entityManager)
83
        );
84
85
        $this->hydratorProxy->assertHydrationOnEntity($entity, $entityManager);
86
    }
87
88
}
89