Completed
Push — 7.5 ( 22ec60...932e58 )
by André
23:01
created

TrashHandlerTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 586
Duplicated Lines 21.5 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 126
loc 586
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 7

11 Methods

Rating   Name   Duplication   Size   Complexity  
B testTrashSubtree() 0 70 1
B testTrashSubtreeReturnsNull() 0 57 1
B testTrashSubtreeUpdatesMainLocation() 0 89 1
A testRecover() 0 16 1
A testLoadTrashItem() 0 17 1
A getTrashHandler() 11 11 1
B testEmptyTrash() 0 84 3
B testDeleteTrashItemNoMoreLocations() 58 58 1
B testDeleteTrashItemStillHaveLocations() 57 57 1
A testFindTrashItemsWhenEmpty() 0 26 1
A testFindTrashItemsWithLimits() 0 30 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\Trash\TrashHandlerTest 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\Location;
10
11
use eZ\Publish\API\Repository\Values\Content\Trash\TrashItemDeleteResult;
12
use eZ\Publish\API\Repository\Values\Content\Trash\TrashItemDeleteResultList;
13
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
14
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler;
15
use eZ\Publish\SPI\Persistence\Content\Location\Trash\TrashResult;
16
use eZ\Publish\SPI\Persistence\Content\Location\Trashed;
17
use eZ\Publish\Core\Persistence\Legacy\Content as CoreContent;
18
19
/**
20
 * Test case for TrashHandlerTest.
21
 */
22
class TrashHandlerTest extends TestCase
23
{
24
    /**
25
     * Mocked location handler instance.
26
     *
27
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Handler
28
     */
29
    protected $locationHandler;
30
31
    /**
32
     * Mocked location gateway instance.
33
     *
34
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
35
     */
36
    protected $locationGateway;
37
38
    /**
39
     * Mocked location mapper instance.
40
     *
41
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper
42
     */
43
    protected $locationMapper;
44
45
    /**
46
     * Mocked content handler instance.
47
     *
48
     * @var \PHPUnit\Framework\MockObject\MockObject
49
     */
50
    protected $contentHandler;
51
52 View Code Duplication
    protected function getTrashHandler()
53
    {
54
        $dbHandler = $this->getDatabaseHandler();
0 ignored issues
show
Unused Code introduced by
$dbHandler 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...
55
56
        return new Handler(
57
            $this->locationHandler = $this->createMock(CoreContent\Location\Handler::class),
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...ocation\Handler::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...ntent\Location\Handler> of property $locationHandler.

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...
58
            $this->locationGateway = $this->createMock(CoreContent\Location\Gateway::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 $locationGateway.

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...
59
            $this->locationMapper = $this->createMock(CoreContent\Location\Mapper::class),
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...Location\Mapper::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...ontent\Location\Mapper> of property $locationMapper.

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...
60
            $this->contentHandler = $this->createMock(CoreContent\Handler::class)
61
        );
62
    }
63
64
    /**
65
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::trashSubtree
66
     */
67
    public function testTrashSubtree()
68
    {
69
        $handler = $this->getTrashHandler();
70
71
        $this->locationGateway
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...
72
            ->expects($this->at(0))
73
            ->method('getSubtreeContent')
74
            ->with(20)
75
            ->will(
76
                $this->returnValue(
77
                    [
78
                        [
79
                            'contentobject_id' => 10,
80
                            'node_id' => 20,
81
                            'main_node_id' => 30,
82
                            'parent_node_id' => 40,
83
                        ],
84
                        [
85
                            'contentobject_id' => 11,
86
                            'node_id' => 21,
87
                            'main_node_id' => 31,
88
                            'parent_node_id' => 41,
89
                        ],
90
                    ]
91
                )
92
            );
93
94
        $this->locationGateway
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...
95
            ->expects($this->at(1))
96
            ->method('countLocationsByContentId')
97
            ->with(10)
98
            ->will($this->returnValue(1));
99
100
        $this->locationGateway
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...
101
            ->expects($this->at(2))
102
            ->method('trashLocation')
103
            ->with(20);
104
105
        $this->locationGateway
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...
106
            ->expects($this->at(3))
107
            ->method('countLocationsByContentId')
108
            ->with(11)
109
            ->will($this->returnValue(2));
110
111
        $this->locationGateway
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...
112
            ->expects($this->at(4))
113
            ->method('removeLocation')
114
            ->with(21);
115
116
        $this->locationHandler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
117
            ->expects($this->once())
118
            ->method('markSubtreeModified')
119
            ->with(40);
120
121
        $this->locationGateway
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...
122
            ->expects($this->at(5))
123
            ->method('loadTrashByLocation')
124
            ->with(20)
125
            ->will($this->returnValue($array = ['data…']));
126
127
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
128
            ->expects($this->once())
129
            ->method('createLocationFromRow')
130
            ->with($array, null, new Trashed())
131
            ->will($this->returnValue(new Trashed(['id' => 20])));
132
133
        $trashedObject = $handler->trashSubtree(20);
134
        self::assertInstanceOf(Trashed::class, $trashedObject);
135
        self::assertSame(20, $trashedObject->id);
136
    }
137
138
    /**
139
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::trashSubtree
140
     */
141
    public function testTrashSubtreeReturnsNull()
142
    {
143
        $handler = $this->getTrashHandler();
144
145
        $this->locationGateway
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...
146
            ->expects($this->at(0))
147
            ->method('getSubtreeContent')
148
            ->with(20)
149
            ->will(
150
                $this->returnValue(
151
                    [
152
                        [
153
                            'contentobject_id' => 10,
154
                            'node_id' => 20,
155
                            'main_node_id' => 30,
156
                            'parent_node_id' => 40,
157
                        ],
158
                        [
159
                            'contentobject_id' => 11,
160
                            'node_id' => 21,
161
                            'main_node_id' => 31,
162
                            'parent_node_id' => 41,
163
                        ],
164
                    ]
165
                )
166
            );
167
168
        $this->locationGateway
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...
169
            ->expects($this->at(1))
170
            ->method('countLocationsByContentId')
171
            ->with(10)
172
            ->will($this->returnValue(2));
173
174
        $this->locationGateway
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...
175
            ->expects($this->at(2))
176
            ->method('removeLocation')
177
            ->with(20);
178
179
        $this->locationGateway
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...
180
            ->expects($this->at(3))
181
            ->method('countLocationsByContentId')
182
            ->with(11)
183
            ->will($this->returnValue(1));
184
185
        $this->locationGateway
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...
186
            ->expects($this->at(4))
187
            ->method('trashLocation')
188
            ->with(21);
189
190
        $this->locationHandler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Handler>.

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...
191
            ->expects($this->once())
192
            ->method('markSubtreeModified')
193
            ->with(40);
194
195
        $returnValue = $handler->trashSubtree(20);
196
        self::assertNull($returnValue);
197
    }
198
199
    /**
200
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::trashSubtree
201
     */
202
    public function testTrashSubtreeUpdatesMainLocation()
203
    {
204
        $handler = $this->getTrashHandler();
205
206
        $this->locationGateway
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...
207
            ->expects($this->at(0))
208
            ->method('getSubtreeContent')
209
            ->with(20)
210
            ->will(
211
                $this->returnValue(
212
                    [
213
                        [
214
                            'contentobject_id' => 10,
215
                            'node_id' => 20,
216
                            'main_node_id' => 30,
217
                            'parent_node_id' => 40,
218
                        ],
219
                        [
220
                            'contentobject_id' => 11,
221
                            'node_id' => 21,
222
                            'main_node_id' => 21,
223
                            'parent_node_id' => 41,
224
                        ],
225
                    ]
226
                )
227
            );
228
229
        $this->locationGateway
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...
230
            ->expects($this->at(1))
231
            ->method('countLocationsByContentId')
232
            ->with(10)
233
            ->will($this->returnValue(1));
234
235
        $this->locationGateway
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...
236
            ->expects($this->at(2))
237
            ->method('trashLocation')
238
            ->with(20);
239
240
        $this->locationGateway
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...
241
            ->expects($this->at(3))
242
            ->method('countLocationsByContentId')
243
            ->with(11)
244
            ->will($this->returnValue(2));
245
246
        $this->locationGateway
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...
247
            ->expects($this->at(4))
248
            ->method('removeLocation')
249
            ->with(21);
250
251
        $this->locationGateway
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...
252
            ->expects($this->at(5))
253
            ->method('getFallbackMainNodeData')
254
            ->with(11, 21)
255
            ->will(
256
                $this->returnValue(
257
                    [
258
                        'node_id' => 100,
259
                        'contentobject_version' => 101,
260
                        'parent_node_id' => 102,
261
                    ]
262
                )
263
            );
264
265
        $this->locationHandler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Handler>.

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...
266
            ->expects($this->once())
267
            ->method('changeMainLocation')
268
            ->with(11, 100, 101, 102);
269
270
        $this->locationHandler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Handler>.

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...
271
            ->expects($this->once())
272
            ->method('markSubtreeModified')
273
            ->with(40);
274
275
        $this->locationGateway
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...
276
            ->expects($this->at(6))
277
            ->method('loadTrashByLocation')
278
            ->with(20)
279
            ->will($this->returnValue($array = ['data…']));
280
281
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
282
            ->expects($this->once())
283
            ->method('createLocationFromRow')
284
            ->with($array, null, new Trashed())
285
            ->will($this->returnValue(new Trashed(['id' => 20])));
286
287
        $trashedObject = $handler->trashSubtree(20);
288
        self::assertInstanceOf(Trashed::class, $trashedObject);
289
        self::assertSame(20, $trashedObject->id);
290
    }
291
292
    /**
293
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::recover
294
     */
295
    public function testRecover()
296
    {
297
        $handler = $this->getTrashHandler();
298
299
        $this->locationGateway
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...
300
            ->expects($this->at(0))
301
            ->method('untrashLocation')
302
            ->with(69, 23)
303
            ->will(
304
                $this->returnValue(
305
                    new Trashed(['id' => 70])
306
                )
307
            );
308
309
        self::assertSame(70, $handler->recover(69, 23));
310
    }
311
312
    /**
313
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::loadTrashItem
314
     */
315
    public function testLoadTrashItem()
316
    {
317
        $handler = $this->getTrashHandler();
318
319
        $this->locationGateway
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...
320
            ->expects($this->at(0))
321
            ->method('loadTrashByLocation')
322
            ->with(69)
323
            ->will($this->returnValue($array = ['data…']));
324
325
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
326
            ->expects($this->at(0))
327
            ->method('createLocationFromRow')
328
            ->with($array, null, new Trashed());
329
330
        $handler->loadTrashItem(69);
331
    }
332
333
    /**
334
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::emptyTrash
335
     */
336
    public function testEmptyTrash()
337
    {
338
        $handler = $this->getTrashHandler();
339
340
        $expectedTrashed = [
341
            [
342
                'node_id' => 69,
343
                'path_string' => '/1/2/69/',
344
                'contentobject_id' => 67,
345
            ],
346
            [
347
                'node_id' => 70,
348
                'path_string' => '/1/2/70/',
349
                'contentobject_id' => 68,
350
            ],
351
        ];
352
353
        // Index for locationGateway calls
354
        $i = 0;
355
        // Index for contentHandler calls
356
        $iContent = 0;
357
        // Index for locationMapper calls
358
        $iLocation = 0;
359
360
        $this->locationGateway
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...
361
            ->expects($this->at($i++))
362
            ->method('countTrashed')
363
            ->willReturn(2);
364
365
        $this->locationGateway
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...
366
            ->expects($this->at($i++))
367
            ->method('listTrashed')
368
            ->will(
369
                $this->returnValue($expectedTrashed)
370
            );
371
372
        $trashedItemIds = [];
373
        $trashedContentIds = [];
374
375
        foreach ($expectedTrashed as $trashedElement) {
376
            $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
377
                ->expects($this->at($iLocation++))
378
                ->method('createLocationFromRow')
379
                ->will(
380
                    $this->returnValue(
381
                        new Trashed(
382
                            [
383
                                'id' => $trashedElement['node_id'],
384
                                'contentId' => $trashedElement['contentobject_id'],
385
                                'pathString' => $trashedElement['path_string'],
386
                            ]
387
                        )
388
                    )
389
                );
390
            $this->locationGateway
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...
391
                ->expects($this->at($i++))
392
                ->method('removeElementFromTrash')
393
                ->with($trashedElement['node_id']);
394
395
            $this->locationGateway
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...
396
                ->expects($this->at($i++))
397
                ->method('countLocationsByContentId')
398
                ->with($trashedElement['contentobject_id'])
399
                ->will($this->returnValue(0));
400
401
            $this->contentHandler
402
                ->expects($this->at($iContent++))
403
                ->method('deleteContent')
404
                ->with($trashedElement['contentobject_id']);
405
406
            $trashedItemIds[] = $trashedElement['node_id'];
407
            $trashedContentIds[] = $trashedElement['contentobject_id'];
408
        }
409
410
        $returnValue = $handler->emptyTrash();
411
412
        $this->assertInstanceOf(TrashItemDeleteResultList::class, $returnValue);
413
414
        foreach ($returnValue->items as $key => $trashItemDeleteResult) {
415
            $this->assertEquals($trashItemDeleteResult->trashItemId, $trashedItemIds[$key]);
416
            $this->assertEquals($trashItemDeleteResult->contentId, $trashedContentIds[$key]);
417
            $this->assertTrue($trashItemDeleteResult->contentRemoved);
418
        }
419
    }
420
421
    /**
422
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::deleteTrashItem
423
     */
424 View Code Duplication
    public function testDeleteTrashItemNoMoreLocations()
425
    {
426
        $handler = $this->getTrashHandler();
427
428
        $trashItemId = 69;
429
        $contentId = 67;
430
        $this->locationGateway
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...
431
            ->expects($this->once())
432
            ->method('loadTrashByLocation')
433
            ->with($trashItemId)
434
            ->will(
435
                $this->returnValue(
436
                    [
437
                        'node_id' => $trashItemId,
438
                        'contentobject_id' => $contentId,
439
                        'path_string' => '/1/2/69',
440
                    ]
441
                )
442
            );
443
444
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
445
            ->expects($this->once())
446
            ->method('createLocationFromRow')
447
            ->will(
448
                $this->returnValue(
449
                    new Trashed(
450
                        [
451
                            'id' => $trashItemId,
452
                            'contentId' => $contentId,
453
                            'pathString' => '/1/2/69',
454
                        ]
455
                    )
456
                )
457
            );
458
459
        $this->locationGateway
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...
460
            ->expects($this->once())
461
            ->method('removeElementFromTrash')
462
            ->with($trashItemId);
463
464
        $this->locationGateway
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...
465
            ->expects($this->once())
466
            ->method('countLocationsByContentId')
467
            ->with($contentId)
468
            ->will($this->returnValue(0));
469
470
        $this->contentHandler
471
            ->expects($this->once())
472
            ->method('deleteContent')
473
            ->with($contentId);
474
475
        $trashItemDeleteResult = $handler->deleteTrashItem($trashItemId);
476
477
        $this->assertInstanceOf(TrashItemDeleteResult::class, $trashItemDeleteResult);
478
        $this->assertEquals($trashItemId, $trashItemDeleteResult->trashItemId);
479
        $this->assertEquals($contentId, $trashItemDeleteResult->contentId);
480
        $this->assertTrue($trashItemDeleteResult->contentRemoved);
481
    }
482
483
    /**
484
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::deleteTrashItem
485
     */
486 View Code Duplication
    public function testDeleteTrashItemStillHaveLocations()
487
    {
488
        $handler = $this->getTrashHandler();
489
490
        $trashItemId = 69;
491
        $contentId = 67;
492
        $this->locationGateway
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...
493
            ->expects($this->once())
494
            ->method('loadTrashByLocation')
495
            ->with($trashItemId)
496
            ->will(
497
                $this->returnValue(
498
                    [
499
                        'node_id' => $trashItemId,
500
                        'contentobject_id' => $contentId,
501
                        'path_string' => '/1/2/69',
502
                    ]
503
                )
504
            );
505
506
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
507
            ->expects($this->once())
508
            ->method('createLocationFromRow')
509
            ->will(
510
                $this->returnValue(
511
                    new Trashed(
512
                        [
513
                            'id' => $trashItemId,
514
                            'contentId' => $contentId,
515
                            'pathString' => '/1/2/69',
516
                        ]
517
                    )
518
                )
519
            );
520
521
        $this->locationGateway
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...
522
            ->expects($this->once())
523
            ->method('removeElementFromTrash')
524
            ->with($trashItemId);
525
526
        $this->locationGateway
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...
527
            ->expects($this->once())
528
            ->method('countLocationsByContentId')
529
            ->with($contentId)
530
            ->will($this->returnValue(1));
531
532
        $this->contentHandler
533
            ->expects($this->never())
534
            ->method('deleteContent');
535
536
        $trashItemDeleteResult = $handler->deleteTrashItem($trashItemId);
537
538
        $this->assertInstanceOf(TrashItemDeleteResult::class, $trashItemDeleteResult);
539
        $this->assertEquals($trashItemId, $trashItemDeleteResult->trashItemId);
540
        $this->assertEquals($contentId, $trashItemDeleteResult->contentId);
541
        $this->assertFalse($trashItemDeleteResult->contentRemoved);
542
    }
543
544
    /**
545
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::findTrashItems
546
     */
547
    public function testFindTrashItemsWhenEmpty()
548
    {
549
        $handler = $this->getTrashHandler();
550
551
        $this->locationGateway
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...
552
            ->expects($this->once())
553
            ->method('countTrashed')
554
            ->willReturn(0);
555
556
        $this->locationGateway
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...
557
            ->expects($this->never())
558
            ->method('listTrashed');
559
560
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
561
            ->expects($this->never())
562
            ->method($this->anything());
563
564
        $trashResult = $handler->findTrashItems();
565
566
        $this->assertInstanceOf(TrashResult::class, $trashResult);
567
        $this->assertEquals(0, $trashResult->totalCount);
568
        $this->assertIsArray($trashResult->items);
569
        $this->assertEmpty($trashResult->items);
570
        $this->assertIsIterable($trashResult);
571
        $this->assertCount(0, $trashResult);// Can't assert as empty, however we can count it.
572
    }
573
574
    /**
575
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::findTrashItems
576
     */
577
    public function testFindTrashItemsWithLimits()
578
    {
579
        $handler = $this->getTrashHandler();
580
581
        $this->locationGateway
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...
582
            ->expects($this->once())
583
            ->method('countTrashed')
584
            ->willReturn(2);
585
586
        $this->locationGateway
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...
587
            ->expects($this->once())
588
            ->method('listTrashed')
589
            ->with(1, 1, null)
590
            ->willReturn([['fake data']]);
591
592
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
593
            ->expects($this->once())
594
            ->method('createLocationFromRow')
595
            ->with(['fake data'])
596
            ->willReturn(new \stdClass());
597
598
        $trashResult = $handler->findTrashItems(null, 1, 1);
599
600
        $this->assertInstanceOf(TrashResult::class, $trashResult);
601
        $this->assertEquals(2, $trashResult->totalCount);
602
        $this->assertIsArray($trashResult->items);
603
        $this->assertCount(1, $trashResult->items);
604
        $this->assertIsIterable($trashResult);
605
        $this->assertCount(1, $trashResult);
606
    }
607
}
608