1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains Test 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
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\Core\Persistence\Cache\Tests; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\SPI\Persistence\Content\ObjectState as SPIObjectState; |
14
|
|
|
use eZ\Publish\SPI\Persistence\Content\ObjectState\Group as SPIObjectStateGroup; |
15
|
|
|
use eZ\Publish\SPI\Persistence\Content\ObjectState\InputStruct as SPIInputStruct; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Test case for Persistence\Cache\ObjectStateHandler. |
19
|
|
|
*/ |
20
|
|
|
class ObjectStateHandlerTest extends HandlerTest |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\ObjectStateHandler::createGroup |
24
|
|
|
*/ |
25
|
|
|
public function testCreateGroup() |
26
|
|
|
{ |
27
|
|
|
$inputStruct = new SPIInputStruct( |
28
|
|
|
array('identifier' => 'test_state_group', 'name' => 'Test State Group') |
29
|
|
|
); |
30
|
|
|
$expectedGroup = new SPIObjectStateGroup( |
31
|
|
|
array( |
32
|
|
|
'id' => 1, |
33
|
|
|
'identifier' => 'test_state_group', |
34
|
|
|
'name' => 'Test State Group', |
35
|
|
|
) |
36
|
|
|
); |
37
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
38
|
|
|
|
39
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
40
|
|
|
$this->persistenceHandlerMock |
41
|
|
|
->expects($this->once()) |
42
|
|
|
->method('objectStateHandler') |
43
|
|
|
->will($this->returnValue($innerHandler)); |
44
|
|
|
|
45
|
|
|
$innerHandler |
46
|
|
|
->expects($this->once()) |
47
|
|
|
->method('createGroup') |
48
|
|
|
->with($inputStruct) |
49
|
|
|
->will( |
50
|
|
|
$this->returnValue($expectedGroup) |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$this->cacheMock |
54
|
|
|
->expects($this->once()) |
55
|
|
|
->method('clear') |
56
|
|
|
->with('objectstategroup', 'all') |
57
|
|
|
->will($this->returnValue(null)); |
58
|
|
|
|
59
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
60
|
|
|
$this->cacheMock |
61
|
|
|
->expects($this->once()) |
62
|
|
|
->method('getItem') |
63
|
|
|
->with('objectstategroup', 1) |
64
|
|
|
->will($this->returnValue($cacheItemMock)); |
65
|
|
|
|
66
|
|
|
$cacheItemMock |
67
|
|
|
->expects($this->once()) |
68
|
|
|
->method('set') |
69
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Group')); |
70
|
|
|
|
71
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
72
|
|
|
$group = $handler->createGroup($inputStruct); |
73
|
|
|
$this->assertEquals($group, $expectedGroup); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\ObjectStateHandler::loadGroup |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function testLoadGroup() |
80
|
|
|
{ |
81
|
|
|
$expectedGroup = new SPIObjectStateGroup( |
82
|
|
|
array( |
83
|
|
|
'id' => 1, |
84
|
|
|
'identifier' => 'test_state_group', |
85
|
|
|
'name' => 'Test State Group', |
86
|
|
|
) |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
90
|
|
|
$this->cacheMock |
91
|
|
|
->expects($this->once()) |
92
|
|
|
->method('getItem') |
93
|
|
|
->with('objectstategroup', 1) |
94
|
|
|
->will($this->returnValue($cacheItemMock)); |
95
|
|
|
$cacheItemMock |
96
|
|
|
->expects($this->once()) |
97
|
|
|
->method('get') |
98
|
|
|
->will($this->returnValue(null)); |
99
|
|
|
$cacheItemMock |
100
|
|
|
->expects($this->once()) |
101
|
|
|
->method('isMiss') |
102
|
|
|
->will($this->returnValue(true)); |
103
|
|
|
|
104
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
105
|
|
|
|
106
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
107
|
|
|
$this->persistenceHandlerMock |
108
|
|
|
->expects($this->once()) |
109
|
|
|
->method('objectStateHandler') |
110
|
|
|
->will($this->returnValue($innerHandlerMock)); |
111
|
|
|
|
112
|
|
|
$innerHandlerMock |
113
|
|
|
->expects($this->once()) |
114
|
|
|
->method('loadGroup') |
115
|
|
|
->with(1) |
116
|
|
|
->will($this->returnValue($expectedGroup)); |
117
|
|
|
|
118
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
119
|
|
|
$group = $handler->loadGroup(1); |
120
|
|
|
$this->assertEquals($group, $expectedGroup); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\ObjectStateHandler::loadGroup |
125
|
|
|
* @depends testLoadGroup |
126
|
|
|
*/ |
127
|
|
View Code Duplication |
public function testLoadGroupHasCache() |
128
|
|
|
{ |
129
|
|
|
$expectedGroup = new SPIObjectStateGroup( |
130
|
|
|
array( |
131
|
|
|
'id' => 1, |
132
|
|
|
'identifier' => 'test_state_group', |
133
|
|
|
'name' => 'Test State Group', |
134
|
|
|
) |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
138
|
|
|
$this->cacheMock |
139
|
|
|
->expects($this->once()) |
140
|
|
|
->method('getItem') |
141
|
|
|
->with('objectstategroup', 1) |
142
|
|
|
->will($this->returnValue($cacheItemMock)); |
143
|
|
|
$cacheItemMock |
144
|
|
|
->expects($this->once()) |
145
|
|
|
->method('get') |
146
|
|
|
->will($this->returnValue($expectedGroup)); |
147
|
|
|
|
148
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
149
|
|
|
$group = $handler->loadGroup(1); |
150
|
|
|
$this->assertEquals($group, $expectedGroup); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @covers eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::loadGroupByIdentifier |
155
|
|
|
*/ |
156
|
|
|
public function testLoadGroupByIdentifier() |
157
|
|
|
{ |
158
|
|
|
$expectedGroup = new SPIObjectStateGroup( |
159
|
|
|
array( |
160
|
|
|
'id' => 1, |
161
|
|
|
'identifier' => 'test_state_group', |
162
|
|
|
'name' => 'Test State Group', |
163
|
|
|
) |
164
|
|
|
); |
165
|
|
|
|
166
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
167
|
|
|
|
168
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
169
|
|
|
$this->persistenceHandlerMock |
170
|
|
|
->expects($this->once()) |
171
|
|
|
->method('objectStateHandler') |
172
|
|
|
->will($this->returnValue($innerHandlerMock)); |
173
|
|
|
|
174
|
|
|
$innerHandlerMock |
175
|
|
|
->expects($this->once()) |
176
|
|
|
->method('loadGroupByIdentifier') |
177
|
|
|
->with($expectedGroup->identifier) |
178
|
|
|
->will($this->returnValue($expectedGroup)); |
179
|
|
|
|
180
|
|
|
$group = $this->persistenceCacheHandler->objectStateHandler() |
181
|
|
|
->loadGroupByIdentifier('test_state_group'); |
182
|
|
|
$this->assertEquals($group, $expectedGroup); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function generateObjectGroupsArray() |
186
|
|
|
{ |
187
|
|
|
$result = array(); |
188
|
|
|
for ($i = 1; $i <= 20; ++$i) { |
189
|
|
|
$result[] = new SPIObjectStateGroup( |
190
|
|
|
array( |
191
|
|
|
'id' => $i, |
192
|
|
|
'identifier' => "test_state_group_${i}", |
193
|
|
|
'name' => "Test State Group #${i}", |
194
|
|
|
) |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
return $result; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @covers eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::loadAllGroups |
203
|
|
|
*/ |
204
|
|
|
public function testLoadAllGroups($offset = 0, $limit = -1) |
205
|
|
|
{ |
206
|
|
|
$testGroups = $this->generateObjectGroupsArray(); |
207
|
|
|
$testGroupIds = array_map( |
208
|
|
|
function ($group) { |
209
|
|
|
return $group->id; |
210
|
|
|
}, |
211
|
|
|
$testGroups |
212
|
|
|
); |
213
|
|
|
|
214
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
215
|
|
|
$this->cacheMock |
216
|
|
|
->expects($this->at(0)) |
217
|
|
|
->method('getItem') |
218
|
|
|
->with('objectstategroup', 'all') |
219
|
|
|
->will($this->returnValue($cacheItemMock)); |
220
|
|
|
$cacheItemMock |
221
|
|
|
->expects($this->once()) |
222
|
|
|
->method('get') |
223
|
|
|
->will($this->returnValue(null)); |
224
|
|
|
$cacheItemMock |
225
|
|
|
->expects($this->once()) |
226
|
|
|
->method('isMiss') |
227
|
|
|
->will($this->returnValue(true)); |
228
|
|
|
|
229
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
230
|
|
|
|
231
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
232
|
|
|
$this->persistenceHandlerMock |
233
|
|
|
->expects($this->once()) |
234
|
|
|
->method('objectStateHandler') |
235
|
|
|
->will($this->returnValue($innerHandlerMock)); |
236
|
|
|
|
237
|
|
|
$innerHandlerMock |
238
|
|
|
->expects($this->once()) |
239
|
|
|
->method('loadAllGroups') |
240
|
|
|
->with(0, -1) |
241
|
|
|
->will($this->returnValue($testGroups)); |
242
|
|
|
|
243
|
|
View Code Duplication |
foreach ($testGroups as $group) { |
|
|
|
|
244
|
|
|
$this->cacheMock |
245
|
|
|
->expects($this->at($group->id)) |
246
|
|
|
->method('getItem') |
247
|
|
|
->with('objectstategroup', $group->id) |
248
|
|
|
->will( |
249
|
|
|
$this->returnCallback( |
250
|
|
|
function ($cachekey, $i) use ($group) { |
|
|
|
|
251
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
252
|
|
|
$cacheItemMock |
253
|
|
|
->expects($this->once()) |
254
|
|
|
->method('set') |
255
|
|
|
->with($group); |
256
|
|
|
|
257
|
|
|
return $cacheItemMock; |
258
|
|
|
} |
259
|
|
|
) |
260
|
|
|
); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
$cacheItemMock |
264
|
|
|
->expects($this->once()) |
265
|
|
|
->method('set') |
266
|
|
|
->with($testGroupIds); |
267
|
|
|
|
268
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
269
|
|
|
$groups = $handler->loadAllGroups($offset, $limit); |
270
|
|
|
|
271
|
|
|
$expectedGroups = array_slice($testGroups, $offset, $limit > -1 ?: null); |
272
|
|
|
$this->assertEquals($groups, $expectedGroups); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @covers eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::loadAllGroups |
277
|
|
|
*/ |
278
|
|
|
public function testLoadAllGroupsCached($offset = 0, $limit = -1) |
279
|
|
|
{ |
280
|
|
|
$testGroups = $this->generateObjectGroupsArray($offset, $limit); |
281
|
|
|
$testGroupIds = array_map( |
282
|
|
|
function ($group) { |
283
|
|
|
return $group->id; |
284
|
|
|
}, |
285
|
|
|
$testGroups |
286
|
|
|
); |
287
|
|
|
|
288
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
289
|
|
|
$this->cacheMock |
290
|
|
|
->expects($this->at(0)) |
291
|
|
|
->method('getItem') |
292
|
|
|
->with('objectstategroup', 'all') |
293
|
|
|
->will($this->returnValue($cacheItemMock)); |
294
|
|
|
$cacheItemMock |
295
|
|
|
->expects($this->once()) |
296
|
|
|
->method('get') |
297
|
|
|
->will($this->returnValue($testGroupIds)); |
298
|
|
|
$cacheItemMock |
299
|
|
|
->expects($this->once()) |
300
|
|
|
->method('isMiss') |
301
|
|
|
->will($this->returnValue(false)); |
302
|
|
|
|
303
|
|
|
$expectedGroups = array_slice($testGroups, $offset, $limit > -1 ?: null); |
304
|
|
|
|
305
|
|
|
// loadGroup() |
306
|
|
View Code Duplication |
foreach ($expectedGroups as $i => $group) { |
|
|
|
|
307
|
|
|
$this->cacheMock |
308
|
|
|
->expects($this->at($i + 1)) |
309
|
|
|
->method('getItem') |
310
|
|
|
->with('objectstategroup', $group->id) |
311
|
|
|
->will( |
312
|
|
|
$this->returnCallback( |
313
|
|
|
function ($cachekey, $i) use ($group) { |
|
|
|
|
314
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
315
|
|
|
$cacheItemMock |
316
|
|
|
->expects($this->once()) |
317
|
|
|
->method('get') |
318
|
|
|
->will($this->returnValue($group)); |
319
|
|
|
|
320
|
|
|
return $cacheItemMock; |
321
|
|
|
} |
322
|
|
|
) |
323
|
|
|
); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
327
|
|
|
$groups = $handler->loadAllGroups($offset, $limit); |
328
|
|
|
$this->assertEquals($groups, $expectedGroups); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @covers eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::loadAllGroups |
333
|
|
|
*/ |
334
|
|
|
public function testLoadAllGroupsWithOffsetLimit() |
335
|
|
|
{ |
336
|
|
|
$this->testLoadAllGroups(7, 5); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* @covers eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::loadAllGroups |
341
|
|
|
*/ |
342
|
|
|
public function testLoadAllGroupsCachedWithOffsetLimit() |
343
|
|
|
{ |
344
|
|
|
$this->testLoadAllGroupsCached(7, 5); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @covers eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::loadObjectStates |
349
|
|
|
*/ |
350
|
|
|
public function testLoadObjectStates() |
351
|
|
|
{ |
352
|
|
|
$testStates = array( |
353
|
|
|
new SPIObjectState( |
354
|
|
|
array( |
355
|
|
|
'id' => 1, |
356
|
|
|
'identifier' => 'test_state_1_group1', |
357
|
|
|
'groupId' => 1, |
358
|
|
|
) |
359
|
|
|
), |
360
|
|
|
new SPIObjectState( |
361
|
|
|
array( |
362
|
|
|
'id' => 2, |
363
|
|
|
'identifier' => 'test_state_2_group1', |
364
|
|
|
'groupId' => 1, |
365
|
|
|
) |
366
|
|
|
), |
367
|
|
|
new SPIObjectState( |
368
|
|
|
array( |
369
|
|
|
'id' => 3, |
370
|
|
|
'identifier' => 'test_state_3_group1', |
371
|
|
|
'groupId' => 1, |
372
|
|
|
) |
373
|
|
|
), |
374
|
|
|
); |
375
|
|
|
$testStateIds = array_map( |
376
|
|
|
function ($state) { |
377
|
|
|
return $state->id; |
378
|
|
|
}, |
379
|
|
|
$testStates |
380
|
|
|
); |
381
|
|
|
|
382
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
383
|
|
|
$this->cacheMock |
384
|
|
|
->expects($this->at(0)) |
385
|
|
|
->method('getItem') |
386
|
|
|
->with('objectstate', 'byGroup', 1) |
387
|
|
|
->will($this->returnValue($cacheItemMock)); |
388
|
|
|
$cacheItemMock |
389
|
|
|
->expects($this->once()) |
390
|
|
|
->method('get') |
391
|
|
|
->will($this->returnValue(null)); |
392
|
|
|
$cacheItemMock |
393
|
|
|
->expects($this->once()) |
394
|
|
|
->method('isMiss') |
395
|
|
|
->will($this->returnValue(true)); |
396
|
|
|
|
397
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
398
|
|
|
|
399
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
400
|
|
|
$this->persistenceHandlerMock |
401
|
|
|
->expects($this->once()) |
402
|
|
|
->method('objectStateHandler') |
403
|
|
|
->will($this->returnValue($innerHandlerMock)); |
404
|
|
|
|
405
|
|
|
$innerHandlerMock |
406
|
|
|
->expects($this->once()) |
407
|
|
|
->method('loadObjectStates') |
408
|
|
|
->with(1) |
409
|
|
|
->will($this->returnValue($testStates)); |
410
|
|
|
|
411
|
|
|
$cacheItemMock |
412
|
|
|
->expects($this->once()) |
413
|
|
|
->method('set') |
414
|
|
|
->with($testStateIds); |
415
|
|
|
|
416
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
417
|
|
|
$states = $handler->loadObjectStates(1); |
418
|
|
|
$this->assertEquals($states, $testStates); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* @covers eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::loadObjectStates |
423
|
|
|
*/ |
424
|
|
|
public function testLoadObjectStatesCached() |
425
|
|
|
{ |
426
|
|
|
$testStates = array( |
427
|
|
|
new SPIObjectState( |
428
|
|
|
array( |
429
|
|
|
'id' => 1, |
430
|
|
|
'identifier' => 'test_state_1_group1', |
431
|
|
|
'groupId' => 1, |
432
|
|
|
) |
433
|
|
|
), |
434
|
|
|
new SPIObjectState( |
435
|
|
|
array( |
436
|
|
|
'id' => 2, |
437
|
|
|
'identifier' => 'test_state_2_group1', |
438
|
|
|
'groupId' => 1, |
439
|
|
|
) |
440
|
|
|
), |
441
|
|
|
new SPIObjectState( |
442
|
|
|
array( |
443
|
|
|
'id' => 3, |
444
|
|
|
'identifier' => 'test_state_3_group1', |
445
|
|
|
'groupId' => 1, |
446
|
|
|
) |
447
|
|
|
), |
448
|
|
|
); |
449
|
|
|
$testStateIds = array_map( |
450
|
|
|
function ($state) { |
451
|
|
|
return $state->id; |
452
|
|
|
}, |
453
|
|
|
$testStates |
454
|
|
|
); |
455
|
|
|
|
456
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
457
|
|
|
$this->cacheMock |
458
|
|
|
->expects($this->at(0)) |
459
|
|
|
->method('getItem') |
460
|
|
|
->with('objectstate', 'byGroup', 1) |
461
|
|
|
->will($this->returnValue($cacheItemMock)); |
462
|
|
|
$cacheItemMock |
463
|
|
|
->expects($this->once()) |
464
|
|
|
->method('get') |
465
|
|
|
->will($this->returnValue($testStateIds)); |
466
|
|
|
$cacheItemMock |
467
|
|
|
->expects($this->once()) |
468
|
|
|
->method('isMiss') |
469
|
|
|
->will($this->returnValue(false)); |
470
|
|
|
|
471
|
|
|
// load() |
472
|
|
View Code Duplication |
foreach ($testStates as $i => $state) { |
|
|
|
|
473
|
|
|
$this->cacheMock |
474
|
|
|
->expects($this->at($i + 1)) |
475
|
|
|
->method('getItem') |
476
|
|
|
->with('objectstate', $state->id) |
477
|
|
|
->will( |
478
|
|
|
$this->returnCallback( |
479
|
|
|
function ($cachekey, $i) use ($state) { |
|
|
|
|
480
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
481
|
|
|
$cacheItemMock |
482
|
|
|
->expects($this->once()) |
483
|
|
|
->method('get') |
484
|
|
|
->will($this->returnValue($state)); |
485
|
|
|
|
486
|
|
|
return $cacheItemMock; |
487
|
|
|
} |
488
|
|
|
) |
489
|
|
|
); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
493
|
|
|
$states = $handler->loadObjectStates(1); |
494
|
|
|
$this->assertEquals($states, $testStates); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* @covers eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::updateGroup |
499
|
|
|
*/ |
500
|
|
|
public function testUpdateGroup() |
501
|
|
|
{ |
502
|
|
|
$inputStruct = new SPIInputStruct( |
503
|
|
|
array('identifier' => 'test_state_group', 'name' => 'Test State Group (New)') |
504
|
|
|
); |
505
|
|
|
$expectedGroup = new SPIObjectStateGroup( |
506
|
|
|
array( |
507
|
|
|
'id' => 1, |
508
|
|
|
'identifier' => 'test_state_group_new', |
509
|
|
|
'name' => 'Test State Group (New)', |
510
|
|
|
) |
511
|
|
|
); |
512
|
|
|
|
513
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
514
|
|
|
|
515
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
516
|
|
|
$this->persistenceHandlerMock |
517
|
|
|
->expects($this->once()) |
518
|
|
|
->method('objectStateHandler') |
519
|
|
|
->will($this->returnValue($innerHandlerMock)); |
520
|
|
|
|
521
|
|
|
$innerHandlerMock |
522
|
|
|
->expects($this->once()) |
523
|
|
|
->method('updateGroup') |
524
|
|
|
->with(1, $inputStruct) |
525
|
|
|
->will($this->returnValue($expectedGroup)); |
526
|
|
|
|
527
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
|
|
|
|
528
|
|
|
$this->cacheMock |
529
|
|
|
->expects($this->at(0)) |
530
|
|
|
->method('clear') |
531
|
|
|
->with('objectstategroup', 1); |
532
|
|
|
|
533
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
534
|
|
|
$newGroup = $handler->updateGroup(1, $inputStruct); |
535
|
|
|
$this->assertEquals($newGroup, $expectedGroup); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
/** |
539
|
|
|
* @covers eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::deleteGroup |
540
|
|
|
*/ |
541
|
|
|
public function testDeleteGroup() |
542
|
|
|
{ |
543
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
544
|
|
|
|
545
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
546
|
|
|
$this->persistenceHandlerMock |
547
|
|
|
->expects($this->once()) |
548
|
|
|
->method('objectStateHandler') |
549
|
|
|
->will($this->returnValue($innerHandlerMock)); |
550
|
|
|
|
551
|
|
|
$innerHandlerMock |
552
|
|
|
->expects($this->once()) |
553
|
|
|
->method('deleteGroup') |
554
|
|
|
->with(1); |
555
|
|
|
|
556
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
|
|
|
|
557
|
|
|
$this->cacheMock |
558
|
|
|
->expects($this->at(0)) |
559
|
|
|
->method('clear') |
560
|
|
|
->with('objectstategroup', 'all'); |
561
|
|
|
$this->cacheMock |
562
|
|
|
->expects($this->at(1)) |
563
|
|
|
->method('clear') |
564
|
|
|
->with('objectstategroup', 1); |
565
|
|
|
$this->cacheMock |
566
|
|
|
->expects($this->at(2)) |
567
|
|
|
->method('clear') |
568
|
|
|
->with('objectstate', 'byGroup', 1); |
569
|
|
|
|
570
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
571
|
|
|
$handler->deleteGroup(1); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* @covers eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::create |
576
|
|
|
*/ |
577
|
|
|
public function testCreate() |
578
|
|
|
{ |
579
|
|
|
$inputStruct = new SPIInputStruct( |
580
|
|
|
array('identifier' => 'test_state', 'name' => 'Test State') |
581
|
|
|
); |
582
|
|
|
$expectedState = new SPIObjectState( |
583
|
|
|
array( |
584
|
|
|
'id' => 1, |
585
|
|
|
'identifier' => 'test_state', |
586
|
|
|
'name' => 'Test State', |
587
|
|
|
'groupId' => 1, |
588
|
|
|
) |
589
|
|
|
); |
590
|
|
|
|
591
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
592
|
|
|
|
593
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
594
|
|
|
$this->persistenceHandlerMock |
595
|
|
|
->expects($this->once()) |
596
|
|
|
->method('objectStateHandler') |
597
|
|
|
->will($this->returnValue($innerHandlerMock)); |
598
|
|
|
|
599
|
|
|
$innerHandlerMock |
600
|
|
|
->expects($this->once()) |
601
|
|
|
->method('create') |
602
|
|
|
->with(1, $inputStruct) |
603
|
|
|
->will($this->returnValue($expectedState)); |
604
|
|
|
|
605
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
|
|
|
|
606
|
|
|
$this->cacheMock |
607
|
|
|
->expects($this->at(0)) |
608
|
|
|
->method('clear') |
609
|
|
|
->with('objectstate', 'byGroup', 1); |
610
|
|
|
|
611
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
612
|
|
|
$state = $handler->create(1, $inputStruct); |
613
|
|
|
$this->assertEquals($state, $expectedState); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
/** |
617
|
|
|
* @covers \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::load |
618
|
|
|
*/ |
619
|
|
View Code Duplication |
public function testLoad() |
620
|
|
|
{ |
621
|
|
|
$expectedState = new SPIObjectState( |
622
|
|
|
array( |
623
|
|
|
'id' => 1, |
624
|
|
|
'identifier' => 'test_state', |
625
|
|
|
'name' => 'Test State', |
626
|
|
|
'groupId' => 1, |
627
|
|
|
) |
628
|
|
|
); |
629
|
|
|
|
630
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
631
|
|
|
$this->cacheMock |
632
|
|
|
->expects($this->once()) |
633
|
|
|
->method('getItem') |
634
|
|
|
->with('objectstate', 1) |
635
|
|
|
->will($this->returnValue($cacheItemMock)); |
636
|
|
|
$cacheItemMock |
637
|
|
|
->expects($this->once()) |
638
|
|
|
->method('get') |
639
|
|
|
->will($this->returnValue(null)); |
640
|
|
|
$cacheItemMock |
641
|
|
|
->expects($this->once()) |
642
|
|
|
->method('isMiss') |
643
|
|
|
->will($this->returnValue(true)); |
644
|
|
|
|
645
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
646
|
|
|
|
647
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
648
|
|
|
$this->persistenceHandlerMock |
649
|
|
|
->expects($this->once()) |
650
|
|
|
->method('objectStateHandler') |
651
|
|
|
->will($this->returnValue($innerHandlerMock)); |
652
|
|
|
|
653
|
|
|
$innerHandlerMock |
654
|
|
|
->expects($this->once()) |
655
|
|
|
->method('load') |
656
|
|
|
->with(1) |
657
|
|
|
->will($this->returnValue($expectedState)); |
658
|
|
|
|
659
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
660
|
|
|
$state = $handler->load(1); |
661
|
|
|
$this->assertEquals($state, $expectedState); |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
/** |
665
|
|
|
* @covers \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::load |
666
|
|
|
* @depends testLoad |
667
|
|
|
*/ |
668
|
|
View Code Duplication |
public function testLoadCached() |
669
|
|
|
{ |
670
|
|
|
$expectedState = new SPIObjectState( |
671
|
|
|
array( |
672
|
|
|
'id' => 1, |
673
|
|
|
'identifier' => 'test_state', |
674
|
|
|
'name' => 'Test State', |
675
|
|
|
'groupId' => 1, |
676
|
|
|
) |
677
|
|
|
); |
678
|
|
|
|
679
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
680
|
|
|
$this->cacheMock |
681
|
|
|
->expects($this->once()) |
682
|
|
|
->method('getItem') |
683
|
|
|
->with('objectstate', 1) |
684
|
|
|
->will($this->returnValue($cacheItemMock)); |
685
|
|
|
$cacheItemMock |
686
|
|
|
->expects($this->once()) |
687
|
|
|
->method('get') |
688
|
|
|
->will($this->returnValue($expectedState)); |
689
|
|
|
|
690
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
691
|
|
|
$state = $handler->load(1); |
692
|
|
|
$this->assertEquals($state, $expectedState); |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
/** |
696
|
|
|
* @covers \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::loadByIdentifier |
697
|
|
|
*/ |
698
|
|
|
public function testLoadByIdentifier() |
699
|
|
|
{ |
700
|
|
|
$expectedState = new SPIObjectState( |
701
|
|
|
array( |
702
|
|
|
'id' => 1, |
703
|
|
|
'identifier' => 'test_state', |
704
|
|
|
'name' => 'Test State', |
705
|
|
|
'groupId' => 1, |
706
|
|
|
) |
707
|
|
|
); |
708
|
|
|
|
709
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
710
|
|
|
|
711
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
712
|
|
|
$this->persistenceHandlerMock |
713
|
|
|
->expects($this->once()) |
714
|
|
|
->method('objectStateHandler') |
715
|
|
|
->will($this->returnValue($innerHandlerMock)); |
716
|
|
|
|
717
|
|
|
$innerHandlerMock |
718
|
|
|
->expects($this->once()) |
719
|
|
|
->method('loadByIdentifier') |
720
|
|
|
->with($expectedState->identifier, $expectedState->groupId) |
721
|
|
|
->will($this->returnValue($expectedState)); |
722
|
|
|
|
723
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
724
|
|
|
$state = $handler->loadByIdentifier($expectedState->identifier, $expectedState->groupId); |
725
|
|
|
$this->assertEquals($state, $expectedState); |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
/** |
729
|
|
|
* @covers \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::update |
730
|
|
|
*/ |
731
|
|
|
public function testUpdate() |
732
|
|
|
{ |
733
|
|
|
$inputStruct = new SPIInputStruct( |
734
|
|
|
array('identifier' => 'test_state_new', 'name' => 'Test State (new)') |
735
|
|
|
); |
736
|
|
|
|
737
|
|
|
$expectedState = new SPIObjectState( |
738
|
|
|
array( |
739
|
|
|
'id' => 1, |
740
|
|
|
'identifier' => 'test_state', |
741
|
|
|
'name' => 'Test State', |
742
|
|
|
'groupId' => 1, |
743
|
|
|
) |
744
|
|
|
); |
745
|
|
|
|
746
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
747
|
|
|
|
748
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
749
|
|
|
$this->persistenceHandlerMock |
750
|
|
|
->expects($this->once()) |
751
|
|
|
->method('objectStateHandler') |
752
|
|
|
->will($this->returnValue($innerHandlerMock)); |
753
|
|
|
|
754
|
|
|
$innerHandlerMock |
755
|
|
|
->expects($this->once()) |
756
|
|
|
->method('update') |
757
|
|
|
->with($expectedState->id, $inputStruct) |
758
|
|
|
->will($this->returnValue($expectedState)); |
759
|
|
|
|
760
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
|
|
|
|
761
|
|
|
$this->cacheMock |
762
|
|
|
->expects($this->at(0)) |
763
|
|
|
->method('clear') |
764
|
|
|
->with('objectstate', $expectedState->id); |
765
|
|
|
|
766
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
767
|
|
|
$state = $handler->update($expectedState->id, $inputStruct); |
768
|
|
|
$this->assertEquals($state, $expectedState); |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* @covers \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::setPriority |
773
|
|
|
*/ |
774
|
|
|
public function testSetPriority() |
775
|
|
|
{ |
776
|
|
|
$expectedState = new SPIObjectState( |
777
|
|
|
array( |
778
|
|
|
'id' => 1, |
779
|
|
|
'identifier' => 'test_state', |
780
|
|
|
'name' => 'Test State', |
781
|
|
|
'groupId' => 1, |
782
|
|
|
'priority' => 1, |
783
|
|
|
) |
784
|
|
|
); |
785
|
|
|
|
786
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
787
|
|
|
|
788
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
789
|
|
|
$this->persistenceHandlerMock |
790
|
|
|
->expects($this->once()) |
791
|
|
|
->method('objectStateHandler') |
792
|
|
|
->will($this->returnValue($innerHandlerMock)); |
793
|
|
|
|
794
|
|
|
$innerHandlerMock |
795
|
|
|
->expects($this->once()) |
796
|
|
|
->method('setPriority') |
797
|
|
|
->with($expectedState->id, 1) |
798
|
|
|
->will($this->returnValue($expectedState)); |
799
|
|
|
|
800
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
|
|
|
|
801
|
|
|
$this->cacheMock |
802
|
|
|
->expects($this->at(0)) |
803
|
|
|
->method('clear') |
804
|
|
|
->with('objectstate', $expectedState->id); |
805
|
|
|
|
806
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
807
|
|
|
$state = $handler->setPriority($expectedState->id, 1); |
808
|
|
|
$this->assertEquals($state, $expectedState); |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
/** |
812
|
|
|
* @covers \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::delete |
813
|
|
|
*/ |
814
|
|
|
public function testDelete() |
815
|
|
|
{ |
816
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
817
|
|
|
|
818
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
819
|
|
|
$this->persistenceHandlerMock |
820
|
|
|
->expects($this->once()) |
821
|
|
|
->method('objectStateHandler') |
822
|
|
|
->will($this->returnValue($innerHandlerMock)); |
823
|
|
|
|
824
|
|
|
$innerHandlerMock |
825
|
|
|
->expects($this->once()) |
826
|
|
|
->method('delete') |
827
|
|
|
->with(1); |
828
|
|
|
|
829
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
|
|
|
|
830
|
|
|
$this->cacheMock |
831
|
|
|
->expects($this->at(0)) |
832
|
|
|
->method('clear') |
833
|
|
|
->with('objectstate', 1); |
834
|
|
|
$this->cacheMock |
835
|
|
|
->expects($this->at(1)) |
836
|
|
|
->method('clear') |
837
|
|
|
->with('objectstate', 'byGroup'); |
838
|
|
|
|
839
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
840
|
|
|
$state = $handler->delete(1); |
|
|
|
|
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
/** |
844
|
|
|
* @covers \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::setContentState |
845
|
|
|
*/ |
846
|
|
|
public function testSetContentState() |
847
|
|
|
{ |
848
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
849
|
|
|
|
850
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
851
|
|
|
$this->persistenceHandlerMock |
852
|
|
|
->expects($this->once()) |
853
|
|
|
->method('objectStateHandler') |
854
|
|
|
->will($this->returnValue($innerHandlerMock)); |
855
|
|
|
|
856
|
|
|
$innerHandlerMock |
857
|
|
|
->expects($this->once()) |
858
|
|
|
->method('setContentState') |
859
|
|
|
->with(10, 1, 2); |
860
|
|
|
|
861
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
|
|
|
|
862
|
|
|
$this->cacheMock |
863
|
|
|
->expects($this->at(0)) |
864
|
|
|
->method('clear') |
865
|
|
|
->with('objectstate', 'byContent', 10, 1); |
866
|
|
|
|
867
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
868
|
|
|
$state = $handler->setContentState(10, 1, 2); |
|
|
|
|
869
|
|
|
} |
870
|
|
|
|
871
|
|
|
/** |
872
|
|
|
* @covers \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::getContentState |
873
|
|
|
*/ |
874
|
|
|
public function testGetContentState() |
875
|
|
|
{ |
876
|
|
|
$expectedState = new SPIObjectState( |
877
|
|
|
array( |
878
|
|
|
'id' => 1, |
879
|
|
|
'identifier' => 'test_state', |
880
|
|
|
'name' => 'Test State', |
881
|
|
|
'groupId' => 1, |
882
|
|
|
'priority' => 1, |
883
|
|
|
) |
884
|
|
|
); |
885
|
|
|
|
886
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
887
|
|
|
$this->cacheMock |
888
|
|
|
->expects($this->at(0)) |
889
|
|
|
->method('getItem') |
890
|
|
|
->with('objectstate', 'byContent', 10, 1) |
891
|
|
|
->will($this->returnValue($cacheItemMock)); |
892
|
|
|
$cacheItemMock |
893
|
|
|
->expects($this->once()) |
894
|
|
|
->method('get') |
895
|
|
|
->will($this->returnValue(null)); |
896
|
|
|
$cacheItemMock |
897
|
|
|
->expects($this->once()) |
898
|
|
|
->method('isMiss') |
899
|
|
|
->will($this->returnValue(true)); |
900
|
|
|
|
901
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
902
|
|
|
|
903
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
904
|
|
|
$this->persistenceHandlerMock |
905
|
|
|
->expects($this->once()) |
906
|
|
|
->method('objectStateHandler') |
907
|
|
|
->will($this->returnValue($innerHandlerMock)); |
908
|
|
|
|
909
|
|
|
$innerHandlerMock |
910
|
|
|
->expects($this->once()) |
911
|
|
|
->method('getContentState') |
912
|
|
|
->with(10, 1) |
913
|
|
|
->will($this->returnValue($expectedState)); |
914
|
|
|
|
915
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
916
|
|
|
$state = $handler->getContentState(10, 1, 2); |
917
|
|
|
$this->assertEquals($state, $expectedState); |
918
|
|
|
} |
919
|
|
|
|
920
|
|
|
/** |
921
|
|
|
* @covers \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::getContentState |
922
|
|
|
*/ |
923
|
|
|
public function testGetContentStateCached() |
924
|
|
|
{ |
925
|
|
|
$expectedState = new SPIObjectState( |
926
|
|
|
array( |
927
|
|
|
'id' => 1, |
928
|
|
|
'identifier' => 'test_state', |
929
|
|
|
'name' => 'Test State', |
930
|
|
|
'groupId' => 1, |
931
|
|
|
) |
932
|
|
|
); |
933
|
|
|
|
934
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
935
|
|
|
$this->cacheMock |
936
|
|
|
->expects($this->at(0)) |
937
|
|
|
->method('getItem') |
938
|
|
|
->with('objectstate', 'byContent', 10, 1) |
939
|
|
|
->will($this->returnValue($cacheItemMock)); |
940
|
|
|
$cacheItemMock |
941
|
|
|
->expects($this->once()) |
942
|
|
|
->method('get') |
943
|
|
|
->will($this->returnValue(1)); |
944
|
|
|
$cacheItemMock |
945
|
|
|
->expects($this->once()) |
946
|
|
|
->method('isMiss') |
947
|
|
|
->will($this->returnValue(false)); |
948
|
|
|
|
949
|
|
|
// load() |
950
|
|
|
$this->cacheMock |
951
|
|
|
->expects($this->at(1)) |
952
|
|
|
->method('getItem') |
953
|
|
|
->with('objectstate', $expectedState->id) |
954
|
|
|
->will( |
955
|
|
|
$this->returnCallback( |
956
|
|
|
function ($cachekey, $i) use ($expectedState) { |
|
|
|
|
957
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
958
|
|
|
$cacheItemMock |
959
|
|
|
->expects($this->once()) |
960
|
|
|
->method('get') |
961
|
|
|
->will($this->returnValue($expectedState)); |
962
|
|
|
|
963
|
|
|
return $cacheItemMock; |
964
|
|
|
} |
965
|
|
|
) |
966
|
|
|
); |
967
|
|
|
|
968
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
969
|
|
|
$state = $handler->getContentState(10, 1); |
970
|
|
|
$this->assertEquals($state, $expectedState); |
971
|
|
|
} |
972
|
|
|
|
973
|
|
|
/** |
974
|
|
|
* @covers \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler::getContentCount |
975
|
|
|
*/ |
976
|
|
|
public function testGetContentCount() |
977
|
|
|
{ |
978
|
|
|
$expectedCount = 2; |
979
|
|
|
|
980
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
981
|
|
|
|
982
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ObjectState\\Handler'); |
983
|
|
|
$this->persistenceHandlerMock |
984
|
|
|
->expects($this->once()) |
985
|
|
|
->method('objectStateHandler') |
986
|
|
|
->will($this->returnValue($innerHandlerMock)); |
987
|
|
|
|
988
|
|
|
$innerHandlerMock |
989
|
|
|
->expects($this->once()) |
990
|
|
|
->method('getContentCount') |
991
|
|
|
->with(1) |
992
|
|
|
->will($this->returnValue($expectedCount)); |
993
|
|
|
|
994
|
|
|
//$this->logger->logCall( __METHOD__, array( 'stateId' => $stateId ) ); |
995
|
|
|
|
996
|
|
|
$handler = $this->persistenceCacheHandler->objectStateHandler(); |
997
|
|
|
$count = $handler->getContentCount(1); |
998
|
|
|
$this->assertEquals($count, $expectedCount); |
999
|
|
|
} |
1000
|
|
|
} |
1001
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.