ListMappingTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 212
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 70
c 2
b 1
f 1
dl 0
loc 212
rs 10
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldWakeUpInnerMapping() 0 10 1
A shouldResolveListValue() 0 34 1
A shouldThrowExceptionOnFailedAssertion() 0 8 1
A shouldCollectDBALColumns() 0 3 1
A shouldAssertValue() 0 6 1
A shouldRevertMultidimensionalListValue() 0 32 1
A shouldHaveOrigin() 0 3 1
A shouldRevertListValue() 0 34 1
A shouldHaveDBALColumn() 0 3 1
A shouldHaveEntryMapping() 0 3 1
A setUp() 0 6 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;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\RDMBundle\Mapping\ListMapping;
15
use Doctrine\DBAL\Schema\Column;
16
use Addiks\RDMBundle\Mapping\MappingInterface;
17
use Addiks\RDMBundle\Hydration\HydrationContextInterface;
18
use Addiks\RDMBundle\Exception\FailedRDMAssertionException;
19
use Symfony\Component\DependencyInjection\ContainerInterface;
20
21
final class ListMappingTest extends TestCase
22
{
23
24
    /**
25
     * @var SubjectClass
0 ignored issues
show
Bug introduced by
The type Addiks\SubjectClass was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
     */
27
    private $mapping;
28
29
    /**
30
     * @var Column
31
     */
32
    private $column;
33
34
    /**
35
     * @var MappingInterface
36
     */
37
    private $entryMapping;
38
39
    public function setUp(): void
40
    {
41
        $this->column = $this->createMock(Column::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Doctri...L\Schema\Column::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Doctrine\DBAL\Schema\Column of property $column.

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

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->mapping = new ListMapping($this->column, $this->entryMapping, "some origin");
0 ignored issues
show
Documentation Bug introduced by
It seems like new Addiks\RDMBundle\Map...Mapping, 'some origin') of type Addiks\RDMBundle\Mapping\ListMapping is incompatible with the declared type Addiks\SubjectClass of property $mapping.

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...
45
    }
46
47
    /**
48
     * @test
49
     */
50
    public function shouldHaveDBALColumn()
51
    {
52
        $this->assertSame($this->column, $this->mapping->getDBALColumn());
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function shouldHaveEntryMapping()
59
    {
60
        $this->assertSame($this->entryMapping, $this->mapping->getEntryMapping());
61
    }
62
63
    /**
64
     * @test
65
     */
66
    public function shouldHaveOrigin()
67
    {
68
        $this->assertSame("some origin", $this->mapping->describeOrigin());
69
    }
70
71
    /**
72
     * @test
73
     */
74
    public function shouldCollectDBALColumns()
75
    {
76
        $this->assertSame([$this->column], $this->mapping->collectDBALColumns());
77
    }
78
79
    /**
80
     * @test
81
     */
82
    public function shouldResolveListValue()
83
    {
84
        /** @var HydrationContextInterface $context */
85
        $context = $this->createMock(HydrationContextInterface::class);
86
87
        $this->column->method('getName')->willReturn('some_column');
0 ignored issues
show
Bug introduced by
The method method() does not exist on Doctrine\DBAL\Schema\Column. ( Ignorable by Annotation )

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

87
        $this->column->/** @scrutinizer ignore-call */ 
88
                       method('getName')->willReturn('some_column');

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...
88
89
        /** @var array $dataFromAdditionalColumns */
90
        $dataFromAdditionalColumns = [
91
            'some_column' => '{"a":"LOREM","b":"IPSUM","c":"DOLOR","d":"SIT","e":"AMET"}',
92
        ];
93
94
        $this->entryMapping->method('resolveValue')->will($this->returnCallback(
0 ignored issues
show
Bug introduced by
The method method() does not exist on Addiks\RDMBundle\Mapping\MappingInterface. ( Ignorable by Annotation )

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

94
        $this->entryMapping->/** @scrutinizer ignore-call */ 
95
                             method('resolveValue')->will($this->returnCallback(

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...
95
            function ($context, $data) {
96
                return strtolower($data['']);
97
            }
98
        ));
99
100
        /** @var mixed $expectedResult */
101
        $expectedResult = [
102
            'a' => 'lorem',
103
            'b' => 'ipsum',
104
            'c' => 'dolor',
105
            'd' => 'sit',
106
            'e' => 'amet'
107
        ];
108
109
        /** @var mixed $actualResult */
110
        $actualResult = $this->mapping->resolveValue(
111
            $context,
112
            $dataFromAdditionalColumns
113
        );
114
115
        $this->assertEquals($expectedResult, $actualResult);
116
    }
117
118
    /**
119
     * @test
120
     */
121
    public function shouldRevertListValue()
122
    {
123
        /** @var HydrationContextInterface $context */
124
        $context = $this->createMock(HydrationContextInterface::class);
125
126
        $this->column->method('getName')->willReturn('some_column');
127
128
        $this->entryMapping->method('revertValue')->will($this->returnCallback(
129
            function ($context, $line) {
130
                return ['' => strtoupper($line)];
131
            }
132
        ));
133
134
        /** @var mixed $valueFromEntityField */
135
        $valueFromEntityField = [
136
            'lorem',
137
            'ipsum',
138
            'dolor',
139
            'sit',
140
            'amet',
141
        ];
142
143
        /** @var mixed $expectedResult */
144
        $expectedResult = [
145
            'some_column' => '["LOREM","IPSUM","DOLOR","SIT","AMET"]',
146
        ];
147
148
        /** @var mixed $actualResult */
149
        $actualResult = $this->mapping->revertValue(
150
            $context,
151
            $valueFromEntityField
152
        );
153
154
        $this->assertEquals($expectedResult, $actualResult);
155
    }
156
157
    /**
158
     * @test
159
     */
160
    public function shouldRevertMultidimensionalListValue()
161
    {
162
        /** @var HydrationContextInterface $context */
163
        $context = $this->createMock(HydrationContextInterface::class);
164
165
        $this->column->method('getName')->willReturn('some_column');
166
167
        $this->entryMapping->method('revertValue')->will($this->returnCallback(
168
            function ($context, $data) {
169
                return $data;
170
            }
171
        ));
172
173
        /** @var mixed $valueFromEntityField */
174
        $valueFromEntityField = [
175
            ['a' => 123, 'b' => true],
176
            ['a' => 456, 'b' => false],
177
            []
178
        ];
179
180
        /** @var mixed $expectedResult */
181
        $expectedResult = [
182
            'some_column' => '[{"a":123,"b":true},{"a":456,"b":false}]',
183
        ];
184
185
        /** @var mixed $actualResult */
186
        $actualResult = $this->mapping->revertValue(
187
            $context,
188
            $valueFromEntityField
189
        );
190
191
        $this->assertEquals($expectedResult, $actualResult);
192
    }
193
194
    /**
195
     * @test
196
     */
197
    public function shouldAssertValue()
198
    {
199
        $this->assertNull($this->mapping->assertValue(
200
            $this->createMock(HydrationContextInterface::class),
201
            [],
202
            null
203
        ));
204
    }
205
206
    /**
207
     * @test
208
     */
209
    public function shouldThrowExceptionOnFailedAssertion()
210
    {
211
        $this->expectException(FailedRDMAssertionException::class);
212
213
        $this->mapping->assertValue(
214
            $this->createMock(HydrationContextInterface::class),
215
            [],
216
            "Lorem ipsum!"
217
        );
218
    }
219
220
    /**
221
     * @test
222
     */
223
    public function shouldWakeUpInnerMapping()
224
    {
225
        /** @var ContainerInterface $container */
226
        $container = $this->createMock(ContainerInterface::class);
227
228
        $this->entryMapping->expects($this->once())->method("wakeUpMapping")->with(
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Addiks\RDMBundle\Mapping\MappingInterface. ( Ignorable by Annotation )

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

228
        $this->entryMapping->/** @scrutinizer ignore-call */ 
229
                             expects($this->once())->method("wakeUpMapping")->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...
229
            $this->equalTo($container)
230
        );
231
232
        $this->mapping->wakeUpMapping($container);
233
    }
234
235
}
236