Completed
Push — master ( 7e6070...203e38 )
by Gerrit
02:38
created

shouldForwardLoadOperation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
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\DataLoader;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\RDMBundle\DataLoader\DataLoaderLazyLoadProxy;
15
use Symfony\Component\DependencyInjection\ContainerInterface;
16
use Doctrine\ORM\EntityManagerInterface;
17
use Addiks\RDMBundle\Tests\Hydration\EntityExample;
18
use Addiks\RDMBundle\DataLoader\DataLoaderInterface;
19
use Doctrine\ORM\Mapping\ClassMetadata;
20
21
final class DataLoaderLazyLoadProxyTest extends TestCase
22
{
23
24
    /**
25
     * @var DataLoaderLazyLoadProxy
26
     */
27
    private $dataLoaderProxy;
28
29
    /**
30
     * @var DataLoaderInterface
31
     */
32
    private $innerDataLoader;
33
34
    /**
35
     * @var ContainerInterface
36
     */
37
    private $container;
38
39 View Code Duplication
    public function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        $this->container = $this->createMock(ContainerInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Symfo...tainerInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Symfony\Component...ion\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...
42
        $this->innerDataLoader = $this->createMock(DataLoaderInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...LoaderInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\...er\DataLoaderInterface> of property $innerDataLoader.

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
44
        $this->container->method('get')->will($this->returnValueMap([
45
            ["some_service", ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->innerDataLoader],
46
        ]));
47
48
        $this->dataLoaderProxy = new DataLoaderLazyLoadProxy($this->container, "some_service");
0 ignored issues
show
Documentation introduced by
$this->container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...ion\ContainerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
    }
50
51
    /**
52
     * @test
53
     */
54
    public function shouldForwardLoadOperation()
55
    {
56
        /** @var EntityExample $entity */
57
        $entity = $this->createMock(EntityExample::class);
58
59
        /** @var EntityManagerInterface $entityManager */
60
        $entityManager = $this->createMock(EntityManagerInterface::class);
61
62
        $this->innerDataLoader->expects($this->once())->method('loadDBALDataForEntity')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\...er\DataLoaderInterface>.

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...
63
            $this->equalTo($entity),
64
            $this->equalTo($entityManager)
65
        );
66
67
        $this->dataLoaderProxy->loadDBALDataForEntity($entity, $entityManager);
68
    }
69
70
    /**
71
     * @test
72
     */
73
    public function shouldForwardStoreOperation()
74
    {
75
        /** @var EntityExample $entity */
76
        $entity = $this->createMock(EntityExample::class);
77
78
        /** @var EntityManagerInterface $entityManager */
79
        $entityManager = $this->createMock(EntityManagerInterface::class);
80
81
        $this->innerDataLoader->expects($this->once())->method('storeDBALDataForEntity')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\...er\DataLoaderInterface>.

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
            $this->equalTo($entity),
83
            $this->equalTo($entityManager)
84
        );
85
86
        $this->dataLoaderProxy->storeDBALDataForEntity($entity, $entityManager);
87
    }
88
89
    /**
90
     * @test
91
     */
92
    public function shouldForwardRemoveOperation()
93
    {
94
        /** @var EntityExample $entity */
95
        $entity = $this->createMock(EntityExample::class);
96
97
        /** @var EntityManagerInterface $entityManager */
98
        $entityManager = $this->createMock(EntityManagerInterface::class);
99
100
        $this->innerDataLoader->expects($this->once())->method('removeDBALDataForEntity')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\...er\DataLoaderInterface>.

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...
101
            $this->equalTo($entity),
102
            $this->equalTo($entityManager)
103
        );
104
105
        $this->dataLoaderProxy->removeDBALDataForEntity($entity, $entityManager);
106
    }
107
108
    /**
109
     * @test
110
     */
111
    public function shouldForwardPrepareOperation()
112
    {
113
        /** @var EntityManagerInterface $entityManager */
114
        $entityManager = $this->createMock(EntityManagerInterface::class);
115
116
        /** @var ClassMetadata $classMetadata */
117
        $classMetadata = $this->createMock(ClassMetadata::class);
118
119
        $this->innerDataLoader->expects($this->once())->method('prepareOnMetadataLoad')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\...er\DataLoaderInterface>.

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...
120
            $this->equalTo($entityManager),
121
            $this->equalTo($classMetadata)
122
        );
123
124
        $this->dataLoaderProxy->prepareOnMetadataLoad($entityManager, $classMetadata);
125
    }
126
127
}
128