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

Test::shouldNotLoadEntityWithoutId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (C) 2018 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 Addiks\RDMBundle\DataLoader\SimpleSelectDataLoader;
14
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface;
15
use Addiks\RDMBundle\Tests\Hydration\EntityExample;
16
use Addiks\RDMBundle\Mapping\ChoiceMapping;
17
use Addiks\RDMBundle\ValueResolver\ValueResolverInterface;
18
use Doctrine\ORM\EntityManagerInterface;
19
use Doctrine\ORM\Mapping\ClassMetadata;
20
use Doctrine\DBAL\Connection;
21
use Doctrine\DBAL\Query\QueryBuilder;
22
use Doctrine\ORM\Query\Expr;
23
use Doctrine\DBAL\Driver\Statement;
24
use PHPUnit\Framework\TestCase;
25
use Doctrine\ORM\UnitOfWork;
26
use Addiks\RDMBundle\Tests\Hydration\ServiceExample;
27
use Addiks\RDMBundle\Mapping\MappingInterface;
28
use Addiks\RDMBundle\Mapping\EntityMappingInterface;
29
use Doctrine\DBAL\Schema\Column;
30
use Doctrine\ORM\Mapping\ClassMetadataFactory;
31
use Doctrine\DBAL\Types\Type;
32
33
final class SimpleSelectLoaderTest extends TestCase
34
{
35
36
    /**
37
     * @var SimpleSelectDataLoader
38
     */
39
    private $dataLoader;
40
41
    /**
42
     * @var MappingDriverInterface
43
     */
44
    private $mappingDriver;
45
46
    /**
47
     * @var ValueResolverInterface
48
     */
49
    private $valueResolver;
50
51
    /**
52
     * @var ClassMetadata
53
     */
54
    private $classMetaData;
55
56
    /**
57
     * @var Connection
58
     */
59
    private $connection;
60
61
    /**
62
     * @var QueryBuilder
63
     */
64
    private $queryBuilder;
65
66
    /**
67
     * @var Expr
68
     */
69
    private $expr;
70
71
    /**
72
     * @var Statement
73
     */
74
    private $statement;
75
76
    /**
77
     * @var EntityManagerInterface
78
     */
79
    private $entityManager;
80
81
    /**
82
     * @var UnitOfWork
83
     */
84
    private $unitOfWork;
85
86
    /**
87
     * @var EntityMappingInterface
88
     */
89
    private $entityMapping;
90
91
    /**
92
     * @var ChoiceMapping
93
     */
94
    private $mappings = array();
95
96
    public function setUp(): void
97
    {
98
        $this->mappingDriver = $this->createMock(MappingDriverInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...DriverInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\...MappingDriverInterface> of property $mappingDriver.

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...
99
        $this->connection = $this->createMock(Connection::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Doctr...DBAL\Connection::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\DBAL\Connection> of property $connection.

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...
100
        $this->queryBuilder = $this->createMock(QueryBuilder::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Doctr...ry\QueryBuilder::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\DBAL\Query\QueryBuilder> of property $queryBuilder.

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...
101
        $this->expr = $this->createMock(Expr::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Doctr...\ORM\Query\Expr::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\ORM\Query\Expr> of property $expr.

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...
102
        $this->statement = $this->createMock(Statement::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Doctr...river\Statement::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\DBAL\Driver\Statement> of property $statement.

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...
103
        $this->entityManager = $this->createMock(EntityManagerInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Doctr...anagerInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\ORM\EntityManagerInterface> of property $entityManager.

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...
104
        $this->unitOfWork = $this->createMock(UnitOfWork::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Doctr...\ORM\UnitOfWork::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\ORM\UnitOfWork> of property $unitOfWork.

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...
105
        $this->entityMapping = $this->createMock(EntityMappingInterface::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\...EntityMappingInterface> of property $entityMapping.

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...
106
107
        $this->dataLoader = new SimpleSelectDataLoader(
108
            $this->mappingDriver,
0 ignored issues
show
Documentation introduced by
$this->mappingDriver is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\RDMBundle\...MappingDriverInterface>.

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...
109
            1
0 ignored issues
show
Unused Code introduced by
The call to SimpleSelectDataLoader::__construct() has too many arguments starting with 1.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
110
        );
111
112
        $this->classMetaData = new ClassMetadata(EntityExample::class);
113
        $this->classMetaData->table = ['name' => 'some_table'];
114
        $this->classMetaData->identifier = ["id"];
115
        $this->classMetaData->fieldMappings = [
116
            "id" => [
117
                'columnName' => 'id'
118
            ]
119
        ];
120
121
        $this->mappings['foo'] = $this->createMock(MappingInterface::class);
122
        $this->mappings['bar'] = $this->createMock(MappingInterface::class);
123
124
        $this->mappingDriver->method("loadRDMMetadataForClass")->willReturn($this->entityMapping);
0 ignored issues
show
Bug introduced by
The method method() 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...
125
        $this->entityManager->method("getClassMetadata")->willReturn($this->classMetaData);
0 ignored issues
show
Bug introduced by
The method method() 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...
126
        $this->entityManager->method("getConnection")->willReturn($this->connection);
0 ignored issues
show
Bug introduced by
The method method() 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...
127
        $this->entityManager->method("getUnitOfWork")->willReturn($this->unitOfWork);
0 ignored issues
show
Bug introduced by
The method method() 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...
128
        $this->entityManager->method('getMetadataFactory')->willReturn($this->createMock(ClassMetadataFactory::class));
0 ignored issues
show
Bug introduced by
The method method() 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...
129
        $this->connection->method('createQueryBuilder')->willReturn($this->queryBuilder);
0 ignored issues
show
Bug introduced by
The method method() 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...
130
        $this->queryBuilder->method('expr')->willReturn($this->expr);
0 ignored issues
show
Bug introduced by
The method method() 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...
131
        $this->queryBuilder->method('execute')->willReturn($this->statement);
0 ignored issues
show
Bug introduced by
The method method() 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...
132
    }
133
134
    /**
135
     * @test
136
     */
137
    public function loadsDataFromDatabase()
138
    {
139
        /** @var array $expectedData */
140
        $expectedData = array(
141
            'foo_column' => 'Lorem ipsum',
142
            'bar_column' => 'dolor sit amet'
143
        );
144
145
        $this->classMetaData->identifier = ["id", "secondId"];
146
        $this->classMetaData->fieldMappings = [
147
            "id"  => ['columnName' => 'id'],
148
            "secondId"  => ['columnName' => 'secondId'],
149
            "faz" => ['columnName' => 'faz']
150
        ];
151
152
        $this->queryBuilder->expects($this->once())->method('from')->with($this->equalTo('some_table'));
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder>.

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...
153
        $this->queryBuilder->expects($this->exactly(2))->method('andWhere')->with($this->equalTo("*eq-return*"));
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder>.

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->queryBuilder->expects($this->exactly(2))->method('addSelect');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder>.

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...
155
        $this->queryBuilder->expects($this->once())->method('setMaxResults')->with($this->equalTo(1));
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder>.

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...
156
157
        $this->statement->method('fetch')->willReturn($expectedData);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Doctrine\DBAL\Driver\Statement>.

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...
158
159
        /** @var ServiceExample $fazService */
160
        $fazService = $this->createMock(ServiceExample::class);
161
162
        $entity = new EntityExample(null, null, null, $fazService, null, "second_id");
163
        $entity->id = "123";
164
165
        $this->expr->expects($this->exactly(2))->method("eq")->willReturn("*eq-return*")->withConsecutive(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\ORM\Query\Expr>.

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...
166
            ['id', '123'],
167
            ['secondId', "'second_id'"]
168
        );
169
170
        /** @var Column $columnA */
171
        $columnA = $this->createMock(Column::class);
172
        $columnA->method('getName')->willReturn("id");
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Doctrine\DBAL\Schema\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...
173
174
        /** @var Column $columnA */
175
        $columnB = $this->createMock(Column::class);
176
        $columnB->method('getName')->willReturn("secondId");
0 ignored issues
show
Bug introduced by
The method method() 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...
177
178
        $this->entityMapping->method('collectDBALColumns')->willReturn([
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...EntityMappingInterface>.

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
            $columnA,
180
            $columnB
181
        ]);
182
183
        /** @var array $actualData */
184
        $actualData = $this->dataLoader->loadDBALDataForEntity($entity, $this->entityManager);
185
186
        $this->assertEquals($expectedData, $actualData);
187
    }
188
189
    /**
190
     * @test
191
     */
192
    public function shouldNotLoadEntityWithoutId()
193
    {
194
        /** @var array $expectedData */
195
        $expectedData = array();
196
197
        $this->classMetaData->identifier = [];
198
199
        $this->queryBuilder->expects($this->never())->method('from');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\DBAL\Query\QueryBuilder>.

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...
200
201
        $this->statement->method('fetch')->willReturn($expectedData);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Doctrine\DBAL\Driver\Statement>.

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...
202
203
        $entity = new EntityExample();
204
        $entity->id = "some_id";
205
206
        $this->expr->method("eq")->willReturn("*eq-return*");
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Doctrine\ORM\Query\Expr>.

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...
207
208
        /** @var array $actualData */
209
        $actualData = $this->dataLoader->loadDBALDataForEntity($entity, $this->entityManager);
210
211
        $this->assertEquals($expectedData, $actualData);
212
    }
213
214
    /**
215
     * @test
216
     */
217
    public function storesDataInDatabase()
218
    {
219
        $this->mappings['faz'] = $this->createMock(MappingInterface::class);
220
221
        $this->setUp();
222
223
        $this->classMetaData->identifier = ["id", "faz"];
224
        $this->classMetaData->fieldMappings = [
225
            "id"  => ['columnName' => 'id'],
226
            "faz" => ['columnName' => 'faz']
227
        ];
228
229
        /** @var ServiceExample $fazService */
230
        $fazService = $this->createMock(ServiceExample::class);
231
232
        $entity = new EntityExample(null, null, null, $fazService);
233
        $entity->id = "some_id";
234
        $entity->foo = "some_ipsum_service";
0 ignored issues
show
Documentation Bug introduced by
It seems like 'some_ipsum_service' of type string is incompatible with the declared type object<Addiks\RDMBundle\...dration\ServiceExample> of property $foo.

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...
235
        $entity->bar = "some_dolor_service";
0 ignored issues
show
Documentation Bug introduced by
It seems like 'some_dolor_service' of type string is incompatible with the declared type object<Addiks\RDMBundle\...dration\ServiceExample> of property $bar.

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...
236
237
        $this->mappings['foo']->method("revertValue")->willReturn(["foo_column" => "ipsum"]);
238
        $this->mappings['bar']->method("revertValue")->willReturn(["bar_column" => "dolor"]);
239
        $this->mappings['faz']->method("revertValue")->willReturn(["faz_column" => "sit"]);
240
241
        $this->entityMapping->method('getEntityClassName')->willReturn(EntityExample::class);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...EntityMappingInterface>.

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...
242
        $this->entityMapping->method('getFieldMappings')->willReturn($this->mappings);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...EntityMappingInterface>.

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...
243
        $this->entityMapping->method('revertValue')->willReturn([
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...EntityMappingInterface>.

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...
244
            'foo_column' => 'ipsum',
245
            'bar_column' => 'dolor',
246
            'faz_column' => 'sit'
247
        ]);
248
249
        $this->connection->expects($this->once())->method("update")->with(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\DBAL\Connection>.

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...
250
            $this->equalTo("some_table"),
251
            $this->equalTo([
252
                'foo_column' => 'ipsum',
253
                'bar_column' => 'dolor',
254
                'faz_column' => 'sit'
255
            ]),
256
            $this->equalTo([
257
                'id'  => "some_id",
258
                'faz' => $fazService
259
            ])
260
        );
261
262
        $this->dataLoader->storeDBALDataForEntity($entity, $this->entityManager);
263
    }
264
265
    /**
266
     * @test
267
     */
268
    public function shouldNotUpdateIfDataDidNotChange()
269
    {
270
        $entity = new EntityExample();
271
        $entity->id = "some_id";
272
        $entity->foo = "some_ipsum_service";
0 ignored issues
show
Documentation Bug introduced by
It seems like 'some_ipsum_service' of type string is incompatible with the declared type object<Addiks\RDMBundle\...dration\ServiceExample> of property $foo.

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...
273
        $entity->bar = "some_dolor_service";
0 ignored issues
show
Documentation Bug introduced by
It seems like 'some_dolor_service' of type string is incompatible with the declared type object<Addiks\RDMBundle\...dration\ServiceExample> of property $bar.

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...
274
275
        $this->entityMapping->method('getEntityClassName')->willReturn(EntityExample::class);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...EntityMappingInterface>.

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...
276
        $this->entityMapping->method('getFieldMappings')->willReturn($this->mappings);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...EntityMappingInterface>.

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...
277
        $this->entityMapping->method('collectDBALColumns')->willReturn([
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...EntityMappingInterface>.

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...
278
            new Column("foo_column", Type::getType('string')),
279
            new Column("bar_column", Type::getType('string')),
280
        ]);
281
282
        $this->mappings['foo']->method("revertValue")->willReturn(["foo_column" => "ipsum"]);
283
        $this->mappings['bar']->method("revertValue")->willReturn(["bar_column" => "dolor"]);
284
285
        /** @var array $map */
286
        $map = array(
0 ignored issues
show
Unused Code introduced by
$map is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
287
            "some_ipsum_service" => ["foo_column" => "ipsum"],
288
            "some_dolor_service" => ["bar_column" => "dolor"],
289
        );
290
291
#        $this->valueResolver->method("revertValue")->will($this->returnCallback(
292
#            function ($fieldMapping, $context, $value) use ($map) {
293
#                return $map[$value];
294
#            }
295
#        ));
296
297
#        $this->valueResolver->method("revertValue")->will($this->returnValueMap([
298
#            [$this->mappings['foo'], $entity, "some_ipsum_service", ["foo_column" => "ipsum"]],
299
#            [$this->mappings['bar'], $entity, "some_dolor_service", ["bar_column" => "dolor"]],
300
#        ]));
301
302
        $this->connection->expects($this->never())->method("update");
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\DBAL\Connection>.

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...
303
304
        /** @var array $expectedData */
305
        $expectedData = [
306
            'foo_column' => 'ipsum',
307
            'bar_column' => 'dolor'
308
        ];
309
310
        $this->statement->method('fetch')->willReturn($expectedData);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Doctrine\DBAL\Driver\Statement>.

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...
311
312
        $this->dataLoader->loadDBALDataForEntity($entity, $this->entityManager);
313
        $this->dataLoader->storeDBALDataForEntity($entity, $this->entityManager);
314
    }
315
316
    /**
317
     * @test
318
     */
319
    public function shouldRemoveDBALForEntity()
320
    {
321
        $this->dataLoader->removeDBALDataForEntity(new EntityExample(), $this->entityManager);
322
        $this->assertTrue(true);
323
    }
324
325
    /**
326
     * @test
327
     */
328
    public function shouldPrepareOnMetadataLoad()
329
    {
330
        $this->dataLoader->prepareOnMetadataLoad($this->entityManager, $this->classMetaData);
331
        $this->assertTrue(true);
332
    }
333
334
}
335