Passed
Push — master ( 50749f...7b5f02 )
by Gerrit
12:36
created

ArrayMappingTest::shouldHaveOrigin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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\Mapping;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\RDMBundle\Mapping\ArrayMapping;
15
use Addiks\RDMBundle\Mapping\MappingInterface;
16
use Doctrine\DBAL\Schema\Column;
17
use Addiks\RDMBundle\Hydration\HydrationContextInterface;
18
use Addiks\RDMBundle\Tests\Hydration\EntityExample;
19
use Addiks\RDMBundle\Exception\FailedRDMAssertionExceptionInterface;
20
use Symfony\Component\DependencyInjection\ContainerInterface;
21
22
final class ArrayMappingTest extends TestCase
23
{
24
25
    /**
26
     * @var ArrayMapping
27
     */
28
    private $arrayMapping;
29
30
    /**
31
     * @var MappingInterface
32
     */
33
    private $mappingA;
34
35
    /**
36
     * @var MappingInterface
37
     */
38
    private $mappingB;
39
40
    public function setUp(): void
41
    {
42
        $this->mappingA = $this->createMock(MappingInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...appingInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\Mapping\MappingInterface> of property $mappingA.

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->mappingB = $this->createMock(MappingInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...appingInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\Mapping\MappingInterface> of property $mappingB.

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...
44
45
        $this->arrayMapping = new ArrayMapping([
46
            'foo' => $this->mappingA,
47
            'bar' => $this->mappingB,
48
        ], "Some Origin");
49
    }
50
51
    /**
52
     * @test
53
     */
54
    public function shouldHaveOrigin()
55
    {
56
        $this->assertEquals("Some Origin", $this->arrayMapping->describeOrigin());
57
    }
58
59
    /**
60
     * @test
61
     */
62
    public function shouldStoreEntryMappings()
63
    {
64
        $this->assertEquals([
65
            'foo' => $this->mappingA,
66
            'bar' => $this->mappingB,
67
        ], $this->arrayMapping->getEntryMappings());
68
    }
69
70
    /**
71
     * @test
72
     */
73
    public function shouldCollectDBALColumns()
74
    {
75
        /** @var Column $columnA */
76
        $columnA = $this->createMock(Column::class);
77
78
        /** @var Column $columnB */
79
        $columnB = $this->createMock(Column::class);
80
81
        $this->mappingA->method('collectDBALColumns')->willReturn([
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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
            'lorem' => $columnA,
83
        ]);
84
85
        $this->mappingB->method('collectDBALColumns')->willReturn([
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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...
86
            'ipsum' => $columnB,
87
        ]);
88
89
        $this->assertEquals([
90
            'lorem' => $columnA,
91
            'ipsum' => $columnB
92
        ], $this->arrayMapping->collectDBALColumns());
93
    }
94
95
    /**
96
     * @test
97
     */
98
    public function shouldResolveValueToArray()
99
    {
100
        /** @var HydrationContextInterface $context */
101
        $context = $this->createMock(HydrationContextInterface::class);
102
        $context->method('getEntityClass')->willReturn(EntityExample::class);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...rationContextInterface>.

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...
103
104
        /** @var mixed $dataFromAdditionalColumns */
105
        $dataFromAdditionalColumns = array(
106
            'lorem' => 'ipsum',
107
            'dolor' => 'sit',
108
        );
109
110
        /** @var array<mixed> $expectedResult */
111
        $expectedResult = [
112
            'foo' => 'bar',
113
            'bar' => 3.1415
114
        ];
115
116
        $this->mappingA->expects($this->once())->method('resolveValue')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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...
117
            $this->equalTo($context),
118
            $this->equalTo($dataFromAdditionalColumns)
119
        )->willReturn('bar');
120
121
        $this->mappingB->expects($this->once())->method('resolveValue')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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...
122
            $this->equalTo($context),
123
            $this->equalTo($dataFromAdditionalColumns)
124
        )->willReturn(3.1415);
125
126
        /** @var mixed $actualResult */
127
        $actualResult = $this->arrayMapping->resolveValue($context, $dataFromAdditionalColumns);
128
129
        $this->assertEquals($expectedResult, $actualResult);
130
    }
131
132
    /**
133
     * @test
134
     */
135
    public function shouldRevertValueFromArray()
136
    {
137
        /** @var HydrationContextInterface $context */
138
        $context = $this->createMock(HydrationContextInterface::class);
139
        $context->method('getEntityClass')->willReturn(EntityExample::class);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...rationContextInterface>.

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...
140
141
        /** @var mixed $valueFromEntityField */
142
        $valueFromEntityField = array(
143
            'foo' => 'bar',
144
            'bar' => 3.1415
145
        );
146
147
        /** @var array<string, string> $expectedResult */
148
        $expectedResult = array(
149
            'lorem' => 'ipsum',
150
            'dolor' => 'sit',
151
        );
152
153
        $this->mappingA->expects($this->once())->method('revertValue')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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...
154
            $this->equalTo($context),
155
            $this->equalTo('bar')
156
        )->willReturn(['lorem' => 'ipsum']);
157
158
        $this->mappingB->expects($this->once())->method('revertValue')->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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...
159
            $this->equalTo($context),
160
            $this->equalTo(3.1415)
161
        )->willReturn(['dolor' => 'sit']);
162
163
        /** @var mixed $actualResult */
164
        $actualResult = $this->arrayMapping->revertValue($context, $valueFromEntityField);
165
166
        $this->assertEquals($expectedResult, $actualResult);
167
    }
168
169
    /**
170
     * @test
171
     */
172 View Code Duplication
    public function shouldNotRevertForNonArray()
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...
173
    {
174
        /** @var HydrationContextInterface $context */
175
        $context = $this->createMock(HydrationContextInterface::class);
176
        $context->method('getEntityClass')->willReturn(EntityExample::class);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...rationContextInterface>.

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...
177
178
        $this->mappingA->expects($this->never())->method('revertValue');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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...
179
        $this->mappingB->expects($this->never())->method('revertValue');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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...
180
181
        /** @var mixed $actualResult */
182
        $actualResult = $this->arrayMapping->revertValue($context, "a non-array");
183
184
        $this->assertEquals([], $actualResult);
185
    }
186
187
    /**
188
     * @test
189
     */
190
    public function shouldAssertValue()
191
    {
192
        $this->expectException(FailedRDMAssertionExceptionInterface::class);
193
194
        /** @var HydrationContextInterface $context */
195
        $context = $this->createMock(HydrationContextInterface::class);
196
        $context->method('getEntityClass')->willReturn(EntityExample::class);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...rationContextInterface>.

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...
197
198
        $this->arrayMapping->assertValue($context, [], "foo");
199
    }
200
201
    /**
202
     * @test
203
     */
204 View Code Duplication
    public function shouldWakeUpInnerMapping()
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...
205
    {
206
        /** @var ContainerInterface $container */
207
        $container = $this->createMock(ContainerInterface::class);
208
209
        $this->mappingA->expects($this->once())->method("wakeUpMapping")->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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...
210
            $this->equalTo($container)
211
        );
212
213
        $this->mappingB->expects($this->once())->method("wakeUpMapping")->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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...
214
            $this->equalTo($container)
215
        );
216
217
        $this->arrayMapping->wakeUpMapping($container);
218
    }
219
220
}
221