Completed
Push — ezp_30973 ( feb262...9f83f6 )
by
unknown
14:39
created

testCopyThrowsNotFoundExceptionContentNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\ContentHandlerTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content;
10
11
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
12
use eZ\Publish\SPI\Persistence\Content;
13
use eZ\Publish\SPI\Persistence\Content\Type;
14
use eZ\Publish\SPI\Persistence\Content\ContentInfo;
15
use eZ\Publish\SPI\Persistence\Content\Field;
16
use eZ\Publish\SPI\Persistence\Content\FieldValue;
17
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
18
use eZ\Publish\SPI\Persistence\Content\CreateStruct;
19
use eZ\Publish\SPI\Persistence\Content\UpdateStruct;
20
use eZ\Publish\SPI\Persistence\Content\Relation;
21
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct;
22
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct as LocationCreateStruct;
23
use eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler;
24
use eZ\Publish\Core\Persistence\Legacy\Content\Handler;
25
use eZ\Publish\API\Repository\Values\Content\Relation as RelationValue;
26
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
27
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
28
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway;
29
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter;
30
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway as ContentGateway;
31
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway as ContentTypeGateway;
32
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway;
33
use eZ\Publish\Core\Persistence\Legacy\Content\Mapper;
34
use eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler;
35
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler as ContentTypeHandler;
36
use ReflectionException;
37
38
/**
39
 * Test case for Content Handler.
40
 */
41
class ContentHandlerTest extends TestCase
42
{
43
    /**
44
     * Content handler to test.
45
     *
46
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Handler
47
     */
48
    protected $contentHandler;
49
50
    /**
51
     * Gateway mock.
52
     *
53
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Gateway
54
     */
55
    protected $gatewayMock;
56
57
    /**
58
     * Location gateway mock.
59
     *
60
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
61
     */
62
    protected $locationGatewayMock;
63
64
    /**
65
     * Type gateway mock.
66
     *
67
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
68
     */
69
    protected $typeGatewayMock;
70
71
    /**
72
     * Mapper mock.
73
     *
74
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
75
     */
76
    protected $mapperMock;
77
78
    /**
79
     * Field handler mock.
80
     *
81
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
82
     */
83
    protected $fieldHandlerMock;
84
85
    /**
86
     * Location handler mock.
87
     *
88
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
89
     */
90
    protected $treeHandlerMock;
91
92
    /**
93
     * Slug converter mock.
94
     *
95
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
96
     */
97
    protected $slugConverterMock;
98
99
    /**
100
     * Location handler mock.
101
     *
102
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
103
     */
104
    protected $urlAliasGatewayMock;
105
106
    /**
107
     * ContentType handler mock.
108
     *
109
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
110
     */
111
    protected $contentTypeHandlerMock;
112
113
    /**
114
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::create
115
     *
116
     * @todo Current method way to complex to test, refactor!
117
     */
118
    public function testCreate()
119
    {
120
        $handler = $this->getContentHandler();
121
122
        $mapperMock = $this->getMapperMock();
123
        $gatewayMock = $this->getGatewayMock();
124
        $fieldHandlerMock = $this->getFieldHandlerMock();
125
        $locationMock = $this->getLocationGatewayMock();
126
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
127
        $contentTypeMock = $this->createMock(Type::class);
128
        $createStruct = $this->getCreateStructFixture();
129
130
        $contentTypeHandlerMock->expects($this->once())
131
            ->method('load')
132
            ->with($createStruct->typeId)
133
            ->will($this->returnValue($contentTypeMock));
134
135
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
136
            ->method('createVersionInfoFromCreateStruct')
137
            ->with(
138
                $this->isInstanceOf(
139
                    CreateStruct::class
140
                )
141
            )->will(
142
                $this->returnValue(
143
                    new VersionInfo(
144
                        [
145
                            'names' => [],
146
                            'contentInfo' => new ContentInfo(),
147
                        ]
148
                    )
149
                )
150
            );
151
152
        $gatewayMock->expects($this->once())
153
            ->method('insertContentObject')
154
            ->with(
155
                $this->isInstanceOf(CreateStruct::class)
156
            )->will($this->returnValue(23));
157
158
        $gatewayMock->expects($this->once())
159
            ->method('insertVersion')
160
            ->with(
161
                $this->isInstanceOf(VersionInfo::class),
162
                $this->isType('array')
163
            )->will($this->returnValue(1));
164
165
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

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
            ->method('createNewFields')
167
            ->with(
168
                $this->isInstanceOf(Content::class),
169
                $this->isInstanceOf(Type::class)
170
            );
171
172
        $locationMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

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
            ->method('createNodeAssignment')
174
            ->with(
175
                $this->isInstanceOf(
176
                    LocationCreateStruct::class
177
                ),
178
                $this->equalTo(42),
179
                $this->equalTo(3) // Location\Gateway::NODE_ASSIGNMENT_OP_CODE_CREATE
180
            );
181
182
        $res = $handler->create($createStruct);
183
184
        // @todo Make subsequent tests
185
186
        $this->assertInstanceOf(
187
            Content::class,
188
            $res,
189
            'Content not created'
190
        );
191
        $this->assertEquals(
192
            23,
193
            $res->versionInfo->contentInfo->id,
194
            'Content ID not set correctly'
195
        );
196
        $this->assertInstanceOf(
197
            VersionInfo::class,
198
            $res->versionInfo,
199
            'Version infos not created'
200
        );
201
        $this->assertEquals(
202
            1,
203
            $res->versionInfo->id,
204
            'Version ID not set correctly'
205
        );
206
        $this->assertCount(
207
            2,
208
            $res->fields,
209
            'Fields not set correctly in version'
210
        );
211
    }
212
213
    /**
214
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::publish
215
     */
216
    public function testPublishFirstVersion()
217
    {
218
        $handler = $this->getPartlyMockedHandler(['loadVersionInfo']);
219
220
        $gatewayMock = $this->getGatewayMock();
221
        $mapperMock = $this->getMapperMock();
222
        $locationMock = $this->getLocationGatewayMock();
223
        $fieldHandlerMock = $this->getFieldHandlerMock();
224
        $metadataUpdateStruct = new MetadataUpdateStruct();
225
226
        $handler->expects($this->at(0))
227
            ->method('loadVersionInfo')
228
            ->with(23, 1)
229
            ->will(
230
                $this->returnValue(
231
                    new VersionInfo(['contentInfo' => new ContentInfo(['currentVersionNo' => 1])])
232
                )
233
            );
234
235
        $contentRows = [['ezcontentobject_version_version' => 1]];
236
237
        $gatewayMock->expects($this->once())
238
            ->method('load')
239
            ->with(
240
                $this->equalTo(23),
241
                $this->equalTo(1),
242
                $this->equalTo(null)
243
            )->willReturn($contentRows);
244
245
        $gatewayMock->expects($this->once())
246
            ->method('loadVersionedNameData')
247
            ->with(
248
                $this->equalTo([['id' => 23, 'version' => 1]])
249
            )->will(
250
                $this->returnValue([22])
251
            );
252
253
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
254
            ->method('extractContentFromRows')
255
            ->with($this->equalTo($contentRows), $this->equalTo([22]))
256
            ->will($this->returnValue([$this->getContentFixtureForDraft()]));
257
258
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

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...
259
            ->method('loadExternalFieldData')
260
            ->with($this->isInstanceOf(Content::class));
261
262
        $gatewayMock
263
            ->expects($this->once())
264
            ->method('updateContent')
265
            ->with(23, $metadataUpdateStruct);
266
267
        $locationMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

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...
268
            ->expects($this->once())
269
            ->method('createLocationsFromNodeAssignments')
270
            ->with(23, 1);
271
272
        $locationMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

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...
273
            ->expects($this->once())
274
            ->method('updateLocationsContentVersionNo')
275
            ->with(23, 1);
276
277
        $gatewayMock
278
            ->expects($this->once())
279
            ->method('setPublishedStatus')
280
            ->with(23, 1);
281
282
        $handler->publish(23, 1, $metadataUpdateStruct);
0 ignored issues
show
Bug introduced by
The method publish() 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...
283
    }
284
285
    /**
286
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::publish
287
     */
288
    public function testPublish()
289
    {
290
        $handler = $this->getPartlyMockedHandler(['loadVersionInfo', 'setStatus']);
291
292
        $gatewayMock = $this->getGatewayMock();
293
        $mapperMock = $this->getMapperMock();
294
        $locationMock = $this->getLocationGatewayMock();
295
        $fieldHandlerMock = $this->getFieldHandlerMock();
296
        $metadataUpdateStruct = new MetadataUpdateStruct();
297
298
        $handler->expects($this->at(0))
299
            ->method('loadVersionInfo')
300
            ->with(23, 2)
301
            ->will(
302
                $this->returnValue(
303
                    new VersionInfo(['contentInfo' => new ContentInfo(['currentVersionNo' => 1])])
304
                )
305
            );
306
307
        $handler
308
            ->expects($this->at(1))
309
            ->method('setStatus')
310
            ->with(23, VersionInfo::STATUS_ARCHIVED, 1);
311
312
        $contentRows = [['ezcontentobject_version_version' => 2]];
313
314
        $gatewayMock->expects($this->once())
315
            ->method('load')
316
            ->with(
317
                $this->equalTo(23),
318
                $this->equalTo(2),
319
                $this->equalTo(null)
320
            )
321
            ->willReturn($contentRows);
322
323
        $gatewayMock->expects($this->once())
324
            ->method('loadVersionedNameData')
325
            ->with(
326
                $this->equalTo([['id' => 23, 'version' => 2]])
327
            )->will(
328
                $this->returnValue([22])
329
            );
330
331
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
332
            ->method('extractContentFromRows')
333
            ->with($this->equalTo($contentRows), $this->equalTo([22]))
334
            ->will($this->returnValue([$this->getContentFixtureForDraft()]));
335
336
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

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...
337
            ->method('loadExternalFieldData')
338
            ->with($this->isInstanceOf(Content::class));
339
340
        $gatewayMock
341
            ->expects($this->once())
342
            ->method('updateContent')
343
            ->with(23, $metadataUpdateStruct, $this->isInstanceOf(VersionInfo::class));
344
345
        $locationMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

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...
346
            ->expects($this->once())
347
            ->method('createLocationsFromNodeAssignments')
348
            ->with(23, 2);
349
350
        $locationMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

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...
351
            ->expects($this->once())
352
            ->method('updateLocationsContentVersionNo')
353
            ->with(23, 2);
354
355
        $gatewayMock
356
            ->expects($this->once())
357
            ->method('setPublishedStatus')
358
            ->with(23, 2);
359
360
        $handler->publish(23, 2, $metadataUpdateStruct);
0 ignored issues
show
Bug introduced by
The method publish() 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...
361
    }
362
363
    /**
364
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::createDraftFromVersion
365
     */
366
    public function testCreateDraftFromVersion()
367
    {
368
        $handler = $this->getPartlyMockedHandler(['load']);
369
370
        $mapperMock = $this->getMapperMock();
371
        $gatewayMock = $this->getGatewayMock();
372
        $fieldHandlerMock = $this->getFieldHandlerMock();
373
374
        $handler->expects($this->once())
375
            ->method('load')
376
            ->with(23, 2)
377
            ->will($this->returnValue($this->getContentFixtureForDraft()));
378
379
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
380
            ->method('createVersionInfoForContent')
381
            ->with(
382
                $this->isInstanceOf(Content::class),
383
                $this->equalTo(3),
384
                $this->equalTo(14)
385
            )->will(
386
                $this->returnValue(
387
                    new VersionInfo(
388
                        [
389
                            'names' => [],
390
                            'versionNo' => 3,
391
                        ]
392
                    )
393
                )
394
            );
395
396
        $gatewayMock->expects($this->once())
397
            ->method('insertVersion')
398
            ->with(
399
                $this->isInstanceOf(VersionInfo::class),
400
                $this->getContentFixtureForDraft()->fields
401
            )->will($this->returnValue(42));
402
403
        $gatewayMock->expects($this->once())
404
            ->method('getLastVersionNumber')
405
            ->with($this->equalTo(23))
406
            ->will($this->returnValue(2));
407
408
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

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...
409
            ->method('createExistingFieldsInNewVersion')
410
            ->with($this->isInstanceOf(Content::class));
411
412
        $relationData = [
413
            [
414
                'ezcontentobject_link_contentclassattribute_id' => 0,
415
                'ezcontentobject_link_to_contentobject_id' => 42,
416
                'ezcontentobject_link_relation_type' => 1,
417
            ],
418
        ];
419
420
        $gatewayMock->expects($this->once())
421
            ->method('loadRelations')
422
            ->with(
423
                $this->equalTo(23),
424
                $this->equalTo(2)
425
            )
426
            ->will($this->returnValue($relationData));
427
428
        $relationStruct = new RelationCreateStruct(
429
            [
430
                'sourceContentId' => 23,
431
                'sourceContentVersionNo' => 3,
432
                'sourceFieldDefinitionId' => 0,
433
                'destinationContentId' => 42,
434
                'type' => 1,
435
            ]
436
        );
437
438
        $gatewayMock->expects($this->once())
439
            ->method('insertRelation')
440
            ->with($this->equalTo($relationStruct));
441
442
        $result = $handler->createDraftFromVersion(23, 2, 14);
0 ignored issues
show
Bug introduced by
The method createDraftFromVersion() 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...
443
444
        $this->assertInstanceOf(
445
            Content::class,
446
            $result
447
        );
448
        $this->assertEquals(
449
            42,
450
            $result->versionInfo->id
451
        );
452
    }
453
454
    /**
455
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::load
456
     */
457
    public function testLoad()
458
    {
459
        $handler = $this->getContentHandler();
460
461
        $gatewayMock = $this->getGatewayMock();
462
        $mapperMock = $this->getMapperMock();
463
        $fieldHandlerMock = $this->getFieldHandlerMock();
464
465
        $contentRows = [['ezcontentobject_version_version' => 2]];
466
467
        $gatewayMock->expects($this->once())
468
            ->method('load')
469
            ->with(
470
                $this->equalTo(23),
471
                $this->equalTo(2),
472
                $this->equalTo(['eng-GB'])
473
            )->will(
474
                $this->returnValue($contentRows)
475
            );
476
477
        $gatewayMock->expects($this->once())
478
            ->method('loadVersionedNameData')
479
            ->with(
480
                $this->equalTo([['id' => 23, 'version' => 2]])
481
            )->will(
482
                $this->returnValue([22])
483
            );
484
485
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
486
            ->method('extractContentFromRows')
487
            ->with($this->equalTo($contentRows), $this->equalTo([22]))
488
            ->will($this->returnValue([$this->getContentFixtureForDraft()]));
489
490
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

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...
491
            ->method('loadExternalFieldData')
492
            ->with($this->isInstanceOf(Content::class));
493
494
        $result = $handler->load(23, 2, ['eng-GB']);
495
496
        $this->assertEquals(
497
            $result,
498
            $this->getContentFixtureForDraft()
499
        );
500
    }
501
502
    /**
503
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadContentList
504
     */
505
    public function testLoadContentList()
506
    {
507
        $handler = $this->getContentHandler();
508
509
        $gatewayMock = $this->getGatewayMock();
510
        $mapperMock = $this->getMapperMock();
511
        $fieldHandlerMock = $this->getFieldHandlerMock();
512
        $contentRows = [
513
            ['ezcontentobject_id' => 2, 'ezcontentobject_version_version' => 2],
514
            ['ezcontentobject_id' => 3, 'ezcontentobject_version_version' => 1],
515
        ];
516
        $gatewayMock->expects($this->once())
517
            ->method('loadContentList')
518
            ->with([2, 3], ['eng-GB', 'eng-US'])
519
            ->willReturn($contentRows);
520
521
        $nameDataRows = [
522
            ['ezcontentobject_name_contentobject_id' => 2, 'ezcontentobject_name_content_version' => 2],
523
            ['ezcontentobject_name_contentobject_id' => 3, 'ezcontentobject_name_content_version' => 1],
524
        ];
525
526
        $gatewayMock->expects($this->once())
527
            ->method('loadVersionedNameData')
528
            ->with($this->equalTo([['id' => 2, 'version' => 2], ['id' => 3, 'version' => 1]]))
529
            ->willReturn($nameDataRows);
530
531
        $expected = [
532
            2 => $this->getContentFixtureForDraft(2, 2),
533
            3 => $this->getContentFixtureForDraft(3, 1),
534
        ];
535
        $mapperMock->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
536
            ->method('extractContentFromRows')
537
            ->with($this->equalTo([$contentRows[0]]), $this->equalTo([$nameDataRows[0]]))
538
            ->willReturn([$expected[2]]);
539
540
        $mapperMock->expects($this->at(1))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
541
            ->method('extractContentFromRows')
542
            ->with($this->equalTo([$contentRows[1]]), $this->equalTo([$nameDataRows[1]]))
543
            ->willReturn([$expected[3]]);
544
545
        $fieldHandlerMock->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

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...
546
            ->method('loadExternalFieldData')
547
            ->with($this->isInstanceOf(Content::class));
548
549
        $result = $handler->loadContentList([2, 3], ['eng-GB', 'eng-US']);
550
551
        $this->assertEquals(
552
            $expected,
553
            $result
554
        );
555
    }
556
557
    /**
558
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadContentInfoByRemoteId
559
     */
560 View Code Duplication
    public function testLoadContentInfoByRemoteId()
561
    {
562
        $contentInfoData = [new ContentInfo()];
563
        $this->getGatewayMock()->expects($this->once())
564
            ->method('loadContentInfoByRemoteId')
565
            ->with(
566
                $this->equalTo('15b256dbea2ae72418ff5facc999e8f9')
567
            )->will(
568
                $this->returnValue([42])
569
            );
570
571
        $this->getMapperMock()->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
572
            ->method('extractContentInfoFromRow')
573
            ->with($this->equalTo([42]))
574
            ->will($this->returnValue($contentInfoData));
575
576
        $this->assertSame(
577
            $contentInfoData,
578
            $this->getContentHandler()->loadContentInfoByRemoteId('15b256dbea2ae72418ff5facc999e8f9')
579
        );
580
    }
581
582
    /**
583
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::load
584
     */
585
    public function testLoadErrorNotFound()
586
    {
587
        $this->expectException(\eZ\Publish\Core\Base\Exceptions\NotFoundException::class);
588
589
        $handler = $this->getContentHandler();
590
591
        $gatewayMock = $this->getGatewayMock();
592
593
        $gatewayMock->expects($this->once())
594
            ->method('load')
595
            ->will(
596
                $this->returnValue([])
597
            );
598
599
        $result = $handler->load(23, 2, ['eng-GB']);
0 ignored issues
show
Unused Code introduced by
$result 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...
600
    }
601
602
    /**
603
     * Returns a Content for {@link testCreateDraftFromVersion()}.
604
     *
605
     * @param int $id Optional id
606
     * @param int $versionNo Optional version number
607
     *
608
     * @return \eZ\Publish\SPI\Persistence\Content
609
     */
610
    protected function getContentFixtureForDraft(int $id = 23, int $versionNo = 2)
611
    {
612
        $content = new Content();
613
        $content->versionInfo = new VersionInfo();
614
        $content->versionInfo->versionNo = $versionNo;
615
616
        $content->versionInfo->contentInfo = new ContentInfo(['id' => $id]);
617
618
        $field = new Field();
619
        $field->versionNo = $versionNo;
620
621
        $content->fields = [$field];
622
623
        return $content;
624
    }
625
626
    /**
627
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateContent
628
     */
629
    public function testUpdateContent()
630
    {
631
        $handler = $this->getPartlyMockedHandler(['load', 'loadContentInfo']);
632
633
        $gatewayMock = $this->getGatewayMock();
634
        $fieldHandlerMock = $this->getFieldHandlerMock();
635
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
636
        $contentTypeMock = $this->createMock(Type::class);
637
        $contentStub = new Content(
638
            [
639
                'versionInfo' => new VersionInfo(
640
                    [
641
                        'contentInfo' => new ContentInfo(
642
                            [
643
                                'contentTypeId' => 4242,
644
                            ]
645
                        ),
646
                    ]
647
                ),
648
            ]
649
        );
650
651
        $contentTypeHandlerMock->expects($this->once())
652
            ->method('load')
653
            ->with($contentStub->versionInfo->contentInfo->contentTypeId)
654
            ->will($this->returnValue($contentTypeMock));
655
656
        $gatewayMock->expects($this->once())
657
            ->method('updateContent')
658
            ->with(14, $this->isInstanceOf(MetadataUpdateStruct::class));
659
        $gatewayMock->expects($this->once())
660
            ->method('updateVersion')
661
            ->with(14, 4, $this->isInstanceOf(UpdateStruct::class));
662
663
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

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...
664
            ->method('updateFields')
665
            ->with(
666
                $this->isInstanceOf(Content::class),
667
                $this->isInstanceOf(UpdateStruct::class),
668
                $this->isInstanceOf(Type::class)
669
            );
670
671
        $handler->expects($this->at(0))
672
            ->method('load')
673
            ->with(14, 4)
674
            ->will($this->returnValue($contentStub));
675
676
        $handler->expects($this->at(1))
677
            ->method('load')
678
            ->with(14, 4);
679
680
        $handler->expects($this->at(2))
681
            ->method('loadContentInfo')
682
            ->with(14);
683
684
        $resultContent = $handler->updateContent(
0 ignored issues
show
Bug introduced by
The method updateContent() 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...
Unused Code introduced by
$resultContent 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...
685
            14, // ContentId
686
            4, // VersionNo
687
            new UpdateStruct(
688
                [
689
                    'creatorId' => 14,
690
                    'modificationDate' => time(),
691
                    'initialLanguageId' => 2,
692
                    'fields' => [
693
                        new Field(
694
                            [
695
                                'id' => 23,
696
                                'fieldDefinitionId' => 42,
697
                                'type' => 'some-type',
698
                                'value' => new FieldValue(),
699
                            ]
700
                        ),
701
                        new Field(
702
                            [
703
                                'id' => 23,
704
                                'fieldDefinitionId' => 43,
705
                                'type' => 'some-type',
706
                                'value' => new FieldValue(),
707
                            ]
708
                        ),
709
                    ],
710
                ]
711
            )
712
        );
713
714
        $resultContentInfo = $handler->updateMetadata(
0 ignored issues
show
Bug introduced by
The method updateMetadata() 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...
Unused Code introduced by
$resultContentInfo 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...
715
            14, // ContentId
716
            new MetadataUpdateStruct(
717
                [
718
                    'ownerId' => 14,
719
                    'name' => 'Some name',
720
                    'modificationDate' => time(),
721
                    'alwaysAvailable' => true,
722
                ]
723
            )
724
        );
725
    }
726
727
    /**
728
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata
729
     */
730
    public function testUpdateMetadata()
731
    {
732
        $handler = $this->getPartlyMockedHandler(['load', 'loadContentInfo']);
733
734
        $gatewayMock = $this->getGatewayMock();
735
        $fieldHandlerMock = $this->getFieldHandlerMock();
0 ignored issues
show
Unused Code introduced by
$fieldHandlerMock 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...
736
        $updateStruct = new MetadataUpdateStruct(
737
            [
738
                'ownerId' => 14,
739
                'name' => 'Some name',
740
                'modificationDate' => time(),
741
                'alwaysAvailable' => true,
742
            ]
743
        );
744
745
        $gatewayMock->expects($this->once())
746
            ->method('updateContent')
747
            ->with(14, $updateStruct);
748
749
        $handler->expects($this->once())
750
            ->method('loadContentInfo')
751
            ->with(14)
752
            ->will(
753
                $this->returnValue(
754
                    $this->createMock(ContentInfo::class)
755
                )
756
            );
757
758
        $resultContentInfo = $handler->updateMetadata(
0 ignored issues
show
Bug introduced by
The method updateMetadata() 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...
759
            14, // ContentId
760
            $updateStruct
761
        );
762
        self::assertInstanceOf(ContentInfo::class, $resultContentInfo);
763
    }
764
765
    /**
766
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata
767
     */
768
    public function testUpdateMetadataUpdatesPathIdentificationString()
769
    {
770
        $handler = $this->getPartlyMockedHandler(['load', 'loadContentInfo']);
771
        $locationGatewayMock = $this->getLocationGatewayMock();
772
        $slugConverterMock = $this->getSlugConverterMock();
773
        $urlAliasGatewayMock = $this->getUrlAliasGatewayMock();
774
        $gatewayMock = $this->getGatewayMock();
775
        $updateStruct = new MetadataUpdateStruct(['mainLanguageId' => 2]);
776
777
        $gatewayMock->expects($this->once())
778
            ->method('updateContent')
779
            ->with(14, $updateStruct);
780
781
        $locationGatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

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...
782
            ->method('loadLocationDataByContent')
783
            ->with(14)
784
            ->will(
785
                $this->returnValue(
786
                    [
787
                        [
788
                            'node_id' => 100,
789
                            'parent_node_id' => 200,
790
                        ],
791
                    ]
792
                )
793
            );
794
795
        $urlAliasGatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\UrlAlias\Gateway>.

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...
796
            ->method('loadLocationEntries')
797
            ->with(100, false, 2)
798
            ->will(
799
                $this->returnValue(
800
                    [
801
                        [
802
                            'text' => 'slug',
803
                        ],
804
                    ]
805
                )
806
            );
807
808
        $slugConverterMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...UrlAlias\SlugConverter>.

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...
809
            ->method('convert')
810
            ->with('slug', 'node_100', 'urlalias_compat')
811
            ->will($this->returnValue('transformed_slug'));
812
813
        $locationGatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

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...
814
            ->method('updatePathIdentificationString')
815
            ->with(100, 200, 'transformed_slug');
816
817
        $handler->expects($this->once())
818
            ->method('loadContentInfo')
819
            ->with(14)
820
            ->will(
821
                $this->returnValue(
822
                    $this->createMock(ContentInfo::class)
823
                )
824
            );
825
826
        $handler->updateMetadata(
0 ignored issues
show
Bug introduced by
The method updateMetadata() 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...
827
            14, // ContentId
828
            $updateStruct
829
        );
830
    }
831
832
    /**
833
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadRelations
834
     */
835
    public function testLoadRelations()
836
    {
837
        $handler = $this->getContentHandler();
838
839
        $gatewayMock = $this->getGatewayMock();
840
        $mapperMock = $this->getMapperMock();
841
842
        $gatewayMock->expects($this->once())
843
            ->method('loadRelations')
844
            ->with(
845
                $this->equalTo(23),
846
                $this->equalTo(null),
847
                $this->equalTo(null)
848
            )->will(
849
                $this->returnValue([42])
850
            );
851
852
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
853
            ->method('extractRelationsFromRows')
854
            ->with($this->equalTo([42]))
855
            ->will($this->returnValue($this->getRelationFixture()));
856
857
        $result = $handler->loadRelations(23);
858
859
        $this->assertEquals(
860
            $result,
861
            $this->getRelationFixture()
862
        );
863
    }
864
865
    /**
866
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadReverseRelations
867
     */
868
    public function testLoadReverseRelations()
869
    {
870
        $handler = $this->getContentHandler();
871
872
        $gatewayMock = $this->getGatewayMock();
873
        $mapperMock = $this->getMapperMock();
874
875
        $gatewayMock->expects($this->once())
876
            ->method('loadReverseRelations')
877
            ->with(
878
                $this->equalTo(23),
879
                $this->equalTo(null)
880
            )->will(
881
                $this->returnValue([42])
882
            );
883
884
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
885
            ->method('extractRelationsFromRows')
886
            ->with($this->equalTo([42]))
887
            ->will($this->returnValue($this->getRelationFixture()));
888
889
        $result = $handler->loadReverseRelations(23);
890
891
        $this->assertEquals(
892
            $result,
893
            $this->getRelationFixture()
894
        );
895
    }
896
897
    public function testAddRelation()
898
    {
899
        // expected relation object after creation
900
        $expectedRelationObject = new Relation();
901
        $expectedRelationObject->id = 42; // mocked value, not a real one
902
        $expectedRelationObject->sourceContentId = 23;
903
        $expectedRelationObject->sourceContentVersionNo = 1;
904
        $expectedRelationObject->destinationContentId = 66;
905
        $expectedRelationObject->type = RelationValue::COMMON;
906
907
        // relation create struct
908
        $relationCreateStruct = new Relation\CreateStruct();
909
        $relationCreateStruct->destinationContentId = 66;
910
        $relationCreateStruct->sourceContentId = 23;
911
        $relationCreateStruct->sourceContentVersionNo = 1;
912
        $relationCreateStruct->type = RelationValue::COMMON;
913
914
        $handler = $this->getContentHandler();
915
916
        $gatewayMock = $this->getGatewayMock();
917
        $mapperMock = $this->getMapperMock();
918
919
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
920
            ->method('createRelationFromCreateStruct')
921
            // @todo Connected with the todo above
922
            ->with($this->equalTo($relationCreateStruct))
923
            ->will($this->returnValue($expectedRelationObject));
924
925
        $gatewayMock->expects($this->once())
926
            ->method('insertRelation')
927
            ->with($this->equalTo($relationCreateStruct))
928
            ->will(
929
                // @todo Should this return a row as if it was selected from the database, the id... ? Check with other, similar create methods
930
                $this->returnValue(42)
931
            );
932
933
        $result = $handler->addRelation($relationCreateStruct);
934
935
        $this->assertEquals(
936
            $result,
937
            $expectedRelationObject
938
        );
939
    }
940
941
    /**
942
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::removeRelation
943
     */
944
    public function testRemoveRelation()
945
    {
946
        $gatewayMock = $this->getGatewayMock();
947
948
        $gatewayMock->expects($this->once())
949
            ->method('deleteRelation')
950
            ->with($this->equalTo(1, RelationValue::COMMON));
951
952
        $this->getContentHandler()->removeRelation(1, RelationValue::COMMON);
953
    }
954
955
    protected function getRelationFixture()
956
    {
957
        $relation = new Relation();
958
        $relation->sourceContentId = 23;
959
        $relation->sourceContentVersionNo = 1;
960
        $relation->destinationContentId = 69;
961
962
        return $relation;
963
    }
964
965
    /**
966
     * Returns a CreateStruct fixture.
967
     *
968
     * @return \eZ\Publish\SPI\Persistence\Content\CreateStruct
969
     */
970
    public function getCreateStructFixture()
971
    {
972
        $struct = new CreateStruct();
973
974
        $struct->typeId = 4242;
975
976
        $firstField = new Field();
977
        $firstField->type = 'some-type';
978
        $firstField->value = new FieldValue();
979
980
        $secondField = clone $firstField;
981
982
        $struct->fields = [
983
            $firstField, $secondField,
984
        ];
985
986
        $struct->locations = [
987
            new LocationCreateStruct(
988
                ['parentId' => 42]
989
            ),
990
        ];
991
992
        $struct->name = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-GB' => 'This is a test name') of type array<string,string,{"eng-GB":"string"}> is incompatible with the declared type array<integer,string> of property $name.

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...
993
            'eng-GB' => 'This is a test name',
994
        ];
995
996
        return $struct;
997
    }
998
999
    /**
1000
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadDraftsForUser
1001
     */
1002
    public function testLoadDraftsForUser()
1003
    {
1004
        $handler = $this->getContentHandler();
1005
        $rows = [['ezcontentobject_version_contentobject_id' => 42, 'ezcontentobject_version_version' => 2]];
1006
1007
        $gatewayMock = $this->getGatewayMock();
1008
        $mapperMock = $this->getMapperMock();
1009
1010
        $gatewayMock->expects($this->once())
1011
            ->method('listVersionsForUser')
1012
            ->with($this->equalTo(23))
1013
            ->will($this->returnValue($rows));
1014
1015
        $gatewayMock->expects($this->once())
1016
            ->method('loadVersionedNameData')
1017
            ->with($this->equalTo([['id' => 42, 'version' => 2]]))
1018
            ->will($this->returnValue([]));
1019
1020
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
1021
            ->method('extractVersionInfoListFromRows')
1022
            ->with($this->equalTo($rows), $this->equalTo([]))
1023
            ->will($this->returnValue([new VersionInfo()]));
1024
1025
        $res = $handler->loadDraftsForUser(23);
1026
1027
        $this->assertEquals(
1028
            [new VersionInfo()],
1029
            $res
1030
        );
1031
    }
1032
1033
    public function testListVersions()
1034
    {
1035
        $handler = $this->getContentHandler();
1036
1037
        $treeHandlerMock = $this->getTreeHandlerMock();
1038
1039
        $treeHandlerMock
1040
            ->expects($this->once())
1041
            ->method('listVersions')
1042
            ->with(23)
1043
            ->will($this->returnValue([new VersionInfo()]));
1044
1045
        $versions = $handler->listVersions(23);
1046
1047
        $this->assertEquals(
1048
            [new VersionInfo()],
1049
            $versions
1050
        );
1051
    }
1052
1053
    public function testRemoveRawContent()
1054
    {
1055
        $handler = $this->getContentHandler();
1056
        $treeHandlerMock = $this->getTreeHandlerMock();
1057
1058
        $treeHandlerMock
1059
            ->expects($this->once())
1060
            ->method('removeRawContent')
1061
            ->with(23);
1062
1063
        $handler->removeRawContent(23);
1064
    }
1065
1066
    /**
1067
     * Test for the deleteContent() method.
1068
     *
1069
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1070
     */
1071
    public function testDeleteContentWithLocations()
1072
    {
1073
        $handlerMock = $this->getPartlyMockedHandler(['getAllLocationIds']);
1074
        $gatewayMock = $this->getGatewayMock();
1075
        $treeHandlerMock = $this->getTreeHandlerMock();
1076
1077
        $gatewayMock->expects($this->once())
1078
            ->method('getAllLocationIds')
1079
            ->with($this->equalTo(23))
1080
            ->will($this->returnValue([42, 24]));
1081
        $treeHandlerMock->expects($this->exactly(2))
1082
            ->method('removeSubtree')
1083
            ->with(
1084
                $this->logicalOr(
1085
                    $this->equalTo(42),
1086
                    $this->equalTo(24)
1087
                )
1088
            );
1089
1090
        $handlerMock->deleteContent(23);
0 ignored issues
show
Bug introduced by
The method deleteContent() 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...
1091
    }
1092
1093
    /**
1094
     * Test for the deleteContent() method.
1095
     *
1096
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1097
     */
1098
    public function testDeleteContentWithoutLocations()
1099
    {
1100
        $handlerMock = $this->getPartlyMockedHandler(['removeRawContent']);
1101
        $gatewayMock = $this->getGatewayMock();
1102
1103
        $gatewayMock->expects($this->once())
1104
            ->method('getAllLocationIds')
1105
            ->with($this->equalTo(23))
1106
            ->will($this->returnValue([]));
1107
        $handlerMock->expects($this->once())
1108
            ->method('removeRawContent')
1109
            ->with($this->equalTo(23));
1110
1111
        $handlerMock->deleteContent(23);
0 ignored issues
show
Bug introduced by
The method deleteContent() 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...
1112
    }
1113
1114
    /**
1115
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteVersion
1116
     */
1117
    public function testDeleteVersion()
1118
    {
1119
        $handler = $this->getContentHandler();
1120
1121
        $gatewayMock = $this->getGatewayMock();
1122
        $mapperMock = $this->getMapperMock();
1123
        $locationHandlerMock = $this->getLocationGatewayMock();
1124
        $fieldHandlerMock = $this->getFieldHandlerMock();
1125
1126
        $rows = [['ezcontentobject_version_version' => 2]];
1127
1128
        // Load VersionInfo to delete fields
1129
        $gatewayMock->expects($this->once())
1130
            ->method('loadVersionInfo')
1131
            ->with($this->equalTo(225), $this->equalTo(2))
1132
            ->willReturn($rows);
1133
1134
        $gatewayMock->expects($this->once())
1135
            ->method('loadVersionedNameData')
1136
            ->with($this->equalTo([['id' => 225, 'version' => 2]]))
1137
            ->will($this->returnValue([22]));
1138
1139
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
1140
            ->method('extractVersionInfoListFromRows')
1141
            ->with($this->equalTo($rows), $this->equalTo([22]))
1142
            ->will($this->returnValue([new VersionInfo()]));
1143
1144
        $locationHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

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...
1145
            ->method('deleteNodeAssignment')
1146
            ->with(
1147
                $this->equalTo(225),
1148
                $this->equalTo(2)
1149
            );
1150
1151
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

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...
1152
            ->method('deleteFields')
1153
            ->with(
1154
                $this->equalTo(225),
1155
                $this->isInstanceOf(VersionInfo::class)
1156
            );
1157
        $gatewayMock->expects($this->once())
1158
            ->method('deleteRelations')
1159
            ->with(
1160
                $this->equalTo(225),
1161
                $this->equalTo(2)
1162
            );
1163
        $gatewayMock->expects($this->once())
1164
            ->method('deleteVersions')
1165
            ->with(
1166
                $this->equalTo(225),
1167
                $this->equalTo(2)
1168
            );
1169
        $gatewayMock->expects($this->once())
1170
            ->method('deleteNames')
1171
            ->with(
1172
                $this->equalTo(225),
1173
                $this->equalTo(2)
1174
            );
1175
1176
        $handler->deleteVersion(225, 2);
1177
    }
1178
1179
    /**
1180
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1181
     */
1182
    public function testCopySingleVersion()
1183
    {
1184
        $handler = $this->getPartlyMockedHandler(['load', 'internalCreate']);
1185
        $gatewayMock = $this->getGatewayMock();
1186
        $mapperMock = $this->getMapperMock();
1187
1188
        $handler->expects(
1189
            $this->once()
1190
        )->method(
1191
            'load'
1192
        )->with(
1193
            $this->equalTo(23),
1194
            $this->equalTo(32)
1195
        )->will(
1196
            $this->returnValue(new Content())
1197
        );
1198
1199
        $mapperMock->expects(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
1200
            $this->once()
1201
        )->method(
1202
            'createCreateStructFromContent'
1203
        )->with(
1204
            $this->isInstanceOf(Content::class)
1205
        )->will(
1206
            $this->returnValue(new CreateStruct())
1207
        );
1208
1209
        $handler->expects(
1210
            $this->once()
1211
        )->method(
1212
            'internalCreate'
1213
        )->with(
1214
            $this->isInstanceOf(CreateStruct::class),
1215
            $this->equalTo(32)
1216
        )->will(
1217
            $this->returnValue(
1218
                new Content(
1219
                    [
1220
                        'versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo(['id' => 24])]),
1221
                    ]
1222
                )
1223
            )
1224
        );
1225
1226
        $gatewayMock->expects($this->once())
1227
            ->method('copyRelations')
1228
            ->with(
1229
                $this->equalTo(23),
1230
                $this->equalTo(24),
1231
                $this->equalTo(32)
1232
            )
1233
            ->will($this->returnValue(null));
1234
1235
        $result = $handler->copy(23, 32);
0 ignored issues
show
Bug introduced by
The method copy() 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...
1236
1237
        $this->assertInstanceOf(
1238
            Content::class,
1239
            $result
1240
        );
1241
    }
1242
1243
    /**
1244
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1245
     */
1246
    public function testCopyAllVersions()
1247
    {
1248
        $handler = $this->getPartlyMockedHandler(
1249
            [
1250
                'loadContentInfo',
1251
                'load',
1252
                'internalCreate',
1253
                'listVersions',
1254
            ]
1255
        );
1256
        $gatewayMock = $this->getGatewayMock();
1257
        $mapperMock = $this->getMapperMock();
1258
        $fieldHandlerMock = $this->getFieldHandlerMock();
1259
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
1260
        $contentTypeMock = $this->createMock(Type::class);
1261
        $time = time();
1262
        $createStructStub = new CreateStruct(
1263
            [
1264
                'modified' => $time,
1265
                'typeId' => 4242,
1266
            ]
1267
        );
1268
1269
        $contentTypeHandlerMock->expects($this->once())
1270
            ->method('load')
1271
            ->with($createStructStub->typeId)
1272
            ->will($this->returnValue($contentTypeMock));
1273
1274
        $handler->expects($this->once())
1275
            ->method('loadContentInfo')
1276
            ->with($this->equalTo(23))
1277
            ->will($this->returnValue(new ContentInfo(['currentVersionNo' => 2])));
1278
1279
        $handler->expects($this->at(1))
1280
            ->method('load')
1281
            ->with($this->equalTo(23), $this->equalTo(2))
1282
            ->will($this->returnValue(new Content()));
1283
1284
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

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...
1285
            ->method('createCreateStructFromContent')
1286
            ->with($this->isInstanceOf(Content::class))
1287
            ->will(
1288
                $this->returnValue($createStructStub)
1289
            );
1290
1291
        $handler->expects($this->once())
1292
            ->method('internalCreate')
1293
            ->with(
1294
                $this->isInstanceOf(CreateStruct::class),
1295
                $this->equalTo(2)
1296
            )->will(
1297
                $this->returnValue(
1298
                    new Content(
1299
                        [
1300
                            'versionInfo' => new VersionInfo(
1301
                                [
1302
                                    'contentInfo' => new ContentInfo(['id' => 24]),
1303
                                ]
1304
                            ),
1305
                        ]
1306
                    )
1307
                )
1308
            );
1309
1310
        $handler->expects($this->once())
1311
            ->method('listVersions')
1312
            ->with($this->equalTo(23))
1313
            ->will(
1314
                $this->returnValue(
1315
                    [
1316
                        new VersionInfo(['versionNo' => 1]),
1317
                        new VersionInfo(['versionNo' => 2]),
1318
                    ]
1319
                )
1320
            );
1321
1322
        $versionInfo = new VersionInfo(
1323
            [
1324
                'names' => ['eng-US' => 'Test'],
1325
                'contentInfo' => new ContentInfo(
1326
                    [
1327
                        'id' => 24,
1328
                        'alwaysAvailable' => true,
1329
                    ]
1330
                ),
1331
            ]
1332
        );
1333
        $handler->expects($this->at(4))
1334
            ->method('load')
1335
            ->with($this->equalTo(23), $this->equalTo(1))
1336
            ->will(
1337
                $this->returnValue(
1338
                    new Content(
1339
                        [
1340
                            'versionInfo' => $versionInfo,
1341
                            'fields' => [],
1342
                        ]
1343
                    )
1344
                )
1345
            );
1346
1347
        $versionInfo->creationDate = $time;
1348
        $versionInfo->modificationDate = $time;
1349
        $gatewayMock->expects($this->once())
1350
            ->method('insertVersion')
1351
            ->with(
1352
                $this->equalTo($versionInfo),
1353
                $this->isType('array')
1354
            )->will($this->returnValue(42));
1355
1356
        $versionInfo = clone $versionInfo;
1357
        $versionInfo->id = 42;
1358
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

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...
1359
            ->method('createNewFields')
1360
            ->with(
1361
                $this->equalTo(
1362
                    new Content(
1363
                        [
1364
                            'versionInfo' => $versionInfo,
1365
                            'fields' => [],
1366
                        ]
1367
                    )
1368
                ),
1369
                $this->isInstanceOf(Type::class)
1370
            );
1371
1372
        $gatewayMock->expects($this->once())
1373
            ->method('setName')
1374
            ->with(
1375
                $this->equalTo(24),
1376
                $this->equalTo(1),
1377
                $this->equalTo('Test'),
1378
                $this->equalTo('eng-US')
1379
            );
1380
1381
        $gatewayMock->expects($this->once())
1382
            ->method('copyRelations')
1383
            ->with(
1384
                $this->equalTo(23),
1385
                $this->equalTo(24),
1386
                $this->equalTo(null)
1387
            )
1388
            ->will($this->returnValue(null));
1389
1390
        $result = $handler->copy(23);
0 ignored issues
show
Bug introduced by
The method copy() 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...
1391
1392
        $this->assertInstanceOf(
1393
            Content::class,
1394
            $result
1395
        );
1396
    }
1397
1398
    public function testCopyThrowsNotFoundExceptionContentNotFound()
1399
    {
1400
        $this->expectException(\eZ\Publish\Core\Base\Exceptions\NotFoundException::class);
1401
1402
        $handler = $this->getContentHandler();
1403
1404
        $treeHandlerMock = $this->getTreeHandlerMock();
1405
        $treeHandlerMock
1406
            ->expects($this->once())
1407
            ->method('loadContentInfo')
1408
            ->with($this->equalTo(23))
1409
            ->will(
1410
                $this->throwException(new NotFoundException('ContentInfo', 23))
1411
            );
1412
1413
        $handler->copy(23);
1414
    }
1415
1416
    /**
1417
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1418
     */
1419 View Code Duplication
    public function testCopyThrowsNotFoundExceptionVersionNotFound()
1420
    {
1421
        $this->expectException(\eZ\Publish\Core\Base\Exceptions\NotFoundException::class);
1422
1423
        $handler = $this->getContentHandler();
1424
1425
        $gatewayMock = $this->getGatewayMock();
1426
        $gatewayMock->expects($this->once())
1427
            ->method('load')
1428
            ->with($this->equalTo(23, 32))
1429
            ->will($this->returnValue([]));
1430
1431
        $result = $handler->copy(23, 32);
0 ignored issues
show
Unused Code introduced by
$result 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...
1432
    }
1433
1434
    /**
1435
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::setStatus
1436
     */
1437
    public function testSetStatus()
1438
    {
1439
        $handler = $this->getContentHandler();
1440
1441
        $mapperMock = $this->getMapperMock();
0 ignored issues
show
Unused Code introduced by
$mapperMock 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...
1442
        $gatewayMock = $this->getGatewayMock();
1443
1444
        $gatewayMock->expects($this->once())
1445
            ->method('setStatus')
1446
            ->with(23, 5, 2)
1447
            ->will($this->returnValue(true));
1448
1449
        $this->assertTrue(
1450
            $handler->setStatus(23, 2, 5)
1451
        );
1452
    }
1453
1454
    /**
1455
     * Returns the handler to test.
1456
     *
1457
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1458
     */
1459
    protected function getContentHandler()
1460
    {
1461
        if (!isset($this->contentHandler)) {
1462
            $this->contentHandler = new Handler(
1463
                $this->getGatewayMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getGatewayMock() targeting eZ\Publish\Core\Persiste...rTest::getGatewayMock() can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Publish\Core\Persiste...\Handler::__construct() does only seem to accept object<eZ\Publish\Core\P...Legacy\Content\Gateway>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1464
                $this->getLocationGatewayMock(),
1465
                $this->getMapperMock(),
1466
                $this->getFieldHandlerMock(),
1467
                $this->getSlugConverterMock(),
1468
                $this->getUrlAliasGatewayMock(),
1469
                $this->getContentTypeHandlerMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getContentTypeHandlerMock() targeting eZ\Publish\Core\Persiste...ontentTypeHandlerMock() can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Publish\Core\Persiste...\Handler::__construct() does only seem to accept object<eZ\Publish\SPI\Pe...e\Content\Type\Handler>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1470
                $this->getTreeHandlerMock()
0 ignored issues
show
Bug introduced by
It seems like $this->getTreeHandlerMock() targeting eZ\Publish\Core\Persiste...t::getTreeHandlerMock() can also be of type object<PHPUnit\Framework\MockObject\MockObject>; however, eZ\Publish\Core\Persiste...\Handler::__construct() does only seem to accept object<eZ\Publish\Core\P...cy\Content\TreeHandler>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1471
            );
1472
        }
1473
1474
        return $this->contentHandler;
1475
    }
1476
1477
    /**
1478
     * Returns the handler to test with $methods mocked.
1479
     *
1480
     * @param string[] $methods
1481
     *
1482
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1483
     */
1484
    protected function getPartlyMockedHandler(array $methods)
1485
    {
1486
        return $this->getMockBuilder(Handler::class)
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/pull/3687

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1487
            ->setMethods($methods)
1488
            ->setConstructorArgs(
1489
                [
1490
                    $this->getGatewayMock(),
1491
                    $this->getLocationGatewayMock(),
1492
                    $this->getMapperMock(),
1493
                    $this->getFieldHandlerMock(),
1494
                    $this->getSlugConverterMock(),
1495
                    $this->getUrlAliasGatewayMock(),
1496
                    $this->getContentTypeHandlerMock(),
1497
                    $this->getTreeHandlerMock(),
1498
                ]
1499
            )
1500
            ->getMock();
1501
    }
1502
1503
    /**
1504
     * Returns a TreeHandler mock.
1505
     *
1506
     * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
1507
     */
1508
    protected function getTreeHandlerMock()
1509
    {
1510
        if (!isset($this->treeHandlerMock)) {
1511
            $this->treeHandlerMock = $this->createMock(TreeHandler::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...ent\TreeHandler::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...cy\Content\TreeHandler> of property $treeHandlerMock.

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...
1512
        }
1513
1514
        return $this->treeHandlerMock;
1515
    }
1516
1517
    /**
1518
     * Returns a ContentTypeHandler mock.
1519
     *
1520
     * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
1521
     */
1522
    protected function getContentTypeHandlerMock()
1523
    {
1524
        if (!isset($this->contentTypeHandlerMock)) {
1525
            $this->contentTypeHandlerMock = $this->createMock(ContentTypeHandler::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...nt\Type\Handler::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...y\Content\Type\Handler> of property $contentTypeHandlerMock.

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...
1526
        }
1527
1528
        return $this->contentTypeHandlerMock;
1529
    }
1530
1531
    /**
1532
     * Returns a FieldHandler mock.
1533
     *
1534
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
1535
     */
1536
    protected function getFieldHandlerMock()
1537
    {
1538
        if (!isset($this->fieldHandlerMock)) {
1539
            $this->fieldHandlerMock = $this->createMock(FieldHandler::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...nt\FieldHandler::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...y\Content\FieldHandler> of property $fieldHandlerMock.

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...
1540
        }
1541
1542
        return $this->fieldHandlerMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->fieldHandlerMock; of type PHPUnit\Framework\MockOb...cy\Content\FieldHandler adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1542 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...st::getFieldHandlerMock of type eZ\Publish\Core\Persiste...cy\Content\FieldHandler.
Loading history...
1543
    }
1544
1545
    /**
1546
     * Returns a Mapper mock.
1547
     *
1548
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
1549
     */
1550
    protected function getMapperMock()
1551
    {
1552
        if (!isset($this->mapperMock)) {
1553
            $this->mapperMock = $this->createMock(Mapper::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...\Content\Mapper::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...\Legacy\Content\Mapper> of property $mapperMock.

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...
1554
        }
1555
1556
        return $this->mapperMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->mapperMock; of type PHPUnit\Framework\MockOb...e\Legacy\Content\Mapper adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1556 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...dlerTest::getMapperMock of type eZ\Publish\Core\Persistence\Legacy\Content\Mapper.
Loading history...
1557
    }
1558
1559
    /**
1560
     * Returns a Location Gateway mock.
1561
     *
1562
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
1563
     */
1564
    protected function getLocationGatewayMock()
1565
    {
1566
        if (!isset($this->locationGatewayMock)) {
1567
            $this->locationGatewayMock = $this->createMock(LocationGateway::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...ocation\Gateway::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...ntent\Location\Gateway> of property $locationGatewayMock.

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...
1568
        }
1569
1570
        return $this->locationGatewayMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->locationGatewayMock; of type PHPUnit\Framework\MockOb...ontent\Location\Gateway adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1570 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...:getLocationGatewayMock of type eZ\Publish\Core\Persiste...ontent\Location\Gateway.
Loading history...
1571
    }
1572
1573
    /**
1574
     * Returns a Content Type gateway mock.
1575
     *
1576
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
1577
     */
1578
    protected function getTypeGatewayMock()
1579
    {
1580
        if (!isset($this->typeGatewayMock)) {
1581
            $this->typeGatewayMock = $this->createMock(ContentTypeGateway::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...nt\Type\Gateway::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...y\Content\Type\Gateway> of property $typeGatewayMock.

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...
1582
        }
1583
1584
        return $this->typeGatewayMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->typeGatewayMock; of type PHPUnit\Framework\MockOb...cy\Content\Type\Gateway adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1584 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...est::getTypeGatewayMock of type eZ\Publish\Core\Persiste...cy\Content\Type\Gateway.
Loading history...
1585
    }
1586
1587
    /**
1588
     * Returns a mock object for the Content Gateway.
1589
     *
1590
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Gateway|\PHPUnit\Framework\MockObject\MockObject
1591
     */
1592
    protected function getGatewayMock()
1593
    {
1594
        if (!isset($this->gatewayMock)) {
1595
            try {
1596
                $this->gatewayMock = $this->getMockForAbstractClass(ContentGateway::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...Content\Gateway::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...Legacy\Content\Gateway> of property $gatewayMock.

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...
1597
            } catch (ReflectionException $e) {
1598
                self::fail($e);
1599
            }
1600
        }
1601
1602
        return $this->gatewayMock;
1603
    }
1604
1605
    /**
1606
     * Returns a mock object for the UrlAlias Handler.
1607
     *
1608
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
1609
     */
1610
    protected function getSlugConverterMock()
1611
    {
1612
        if (!isset($this->slugConverterMock)) {
1613
            $this->slugConverterMock = $this->createMock(SlugConverter::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...s\SlugConverter::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...UrlAlias\SlugConverter> of property $slugConverterMock.

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...
1614
        }
1615
1616
        return $this->slugConverterMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->slugConverterMock; of type PHPUnit\Framework\MockOb...\UrlAlias\SlugConverter adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1616 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...t::getSlugConverterMock of type eZ\Publish\Core\Persiste...\UrlAlias\SlugConverter.
Loading history...
1617
    }
1618
1619
    /**
1620
     * Returns a mock object for the UrlAlias Gateway.
1621
     *
1622
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
1623
     */
1624
    protected function getUrlAliasGatewayMock()
1625
    {
1626
        if (!isset($this->urlAliasGatewayMock)) {
1627
            $this->urlAliasGatewayMock = $this->getMockForAbstractClass(UrlAliasGateway::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...rlAlias\Gateway::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...ntent\UrlAlias\Gateway> of property $urlAliasGatewayMock.

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...
1628
        }
1629
1630
        return $this->urlAliasGatewayMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->urlAliasGatewayMock; of type PHPUnit\Framework\MockOb...ontent\UrlAlias\Gateway adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1630 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...:getUrlAliasGatewayMock of type eZ\Publish\Core\Persiste...ontent\UrlAlias\Gateway.
Loading history...
1631
    }
1632
}
1633