@@ -201,8 +201,8 @@ public function testGetTreeForAllScope()
201
201
202
202
public function testMove ()
203
203
{
204
- $ categoryId = 2 ;
205
- $ parentId = 1 ;
204
+ $ categoryId = 4 ;
205
+ $ parentId = 40 ;
206
206
$ afterId = null ;
207
207
$ categoryMock = $ this ->getMockBuilder (Category::class)
208
208
->setMockClassName ('categoryMock ' )
@@ -214,18 +214,25 @@ public function testMove()
214
214
->getMock ();
215
215
216
216
$ this ->categoryRepositoryMock
217
- ->expects ($ this ->exactly (2 ))
217
+ ->expects ($ this ->exactly (6 ))
218
218
->method ('get ' )
219
219
->willReturnMap ([
220
220
[$ categoryId , null , $ categoryMock ],
221
221
[$ parentId , null , $ parentCategoryMock ],
222
222
]);
223
- $ parentCategoryMock ->expects ($ this ->once ())->method ('hasChildren ' )->willReturn (true );
223
+ $ parentCategoryMock ->expects ($ this ->exactly (3 ))->method ('hasChildren ' )
224
+ ->willReturn (true , false , false );
224
225
$ parentCategoryMock ->expects ($ this ->once ())->method ('getChildren ' )->willReturn ('5,6,7 ' );
225
- $ categoryMock ->expects ($ this ->once ())->method ('getPath ' );
226
- $ parentCategoryMock ->expects ($ this ->once ())->method ('getPath ' );
227
- $ categoryMock ->expects ($ this ->once ())->method ('move ' )->with ($ parentId , '7 ' );
226
+ $ categoryMock ->expects ($ this ->exactly (3 ))->method ('getPath ' )
227
+ ->willReturnOnConsecutiveCalls ('2/4 ' , '2/3/4 ' , '2/3/4 ' );
228
+ $ parentCategoryMock ->expects ($ this ->exactly (3 ))->method ('getPath ' )
229
+ ->willReturnOnConsecutiveCalls ('2/40 ' , '2/3/40 ' , '2/3/44/40 ' );
230
+ $ categoryMock ->expects ($ this ->exactly (3 ))->method ('move ' )
231
+ ->withConsecutive ([$ parentId , '7 ' ], [$ parentId , null ], [$ parentId , null ]);
232
+
228
233
$ this ->assertTrue ($ this ->model ->move ($ categoryId , $ parentId , $ afterId ));
234
+ $ this ->assertTrue ($ this ->model ->move ($ categoryId , $ parentId ));
235
+ $ this ->assertTrue ($ this ->model ->move ($ categoryId , $ parentId ));
229
236
}
230
237
231
238
public function testMoveWithException ()
@@ -251,8 +258,8 @@ public function testMoveWithException()
251
258
[$ categoryId , null , $ categoryMock ],
252
259
[$ parentId , null , $ parentCategoryMock ],
253
260
]);
254
- $ categoryMock ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('test ' );
255
- $ parentCategoryMock ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('test ' );
261
+ $ categoryMock ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('test/2 ' );
262
+ $ parentCategoryMock ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('test/2/1 ' );
256
263
$ this ->model ->move ($ categoryId , $ parentId , $ afterId );
257
264
}
258
265
0 commit comments