@@ -207,9 +207,11 @@ public function testSkipMethod($collection)
207
207
{
208
208
$ data = new $ collection ([1 , 2 , 3 , 4 , 5 , 6 ]);
209
209
210
- $ data = $ data ->skip (4 )->values ();
210
+ // Total items to skip is smaller than collection length
211
+ $ this ->assertSame ([5 , 6 ], $ data ->skip (4 )->values ()->all ());
211
212
212
- $ this ->assertSame ([5 , 6 ], $ data ->all ());
213
+ // Total items to skip is more than collection length
214
+ $ this ->assertSame ([], $ data ->skip (10 )->values ()->all ());
213
215
}
214
216
215
217
/**
@@ -219,15 +221,35 @@ public function testSkipUntil($collection)
219
221
{
220
222
$ data = new $ collection ([1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 ]);
221
223
222
- $ data = $ data ->skipUntil (3 )->values ();
224
+ // Item at the beginning of the collection
225
+ $ this ->assertSame ([1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 ], $ data ->skipUntil (1 )->values ()->all ());
226
+
227
+ // Item at the middle of the collection
228
+ $ this ->assertSame ([3 , 3 , 4 , 4 ], $ data ->skipUntil (3 )->values ()->all ());
229
+
230
+ // Item not in the collection
231
+ $ this ->assertSame ([], $ data ->skipUntil (5 )->values ()->all ());
232
+
233
+ // Item at the beginning of the collection
234
+ $ data = $ data ->skipUntil (function ($ value , $ key ) {
235
+ return $ value <= 1 ;
236
+ })->values ();
237
+
238
+ $ this ->assertSame ([1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 ], $ data ->all ());
239
+
240
+ // Item at the middle of the collection
241
+ $ data = $ data ->skipUntil (function ($ value , $ key ) {
242
+ return $ value >= 3 ;
243
+ })->values ();
223
244
224
245
$ this ->assertSame ([3 , 3 , 4 , 4 ], $ data ->all ());
225
246
247
+ // Item not in the collection
226
248
$ data = $ data ->skipUntil (function ($ value , $ key ) {
227
- return $ value > 3 ;
249
+ return $ value >= 5 ;
228
250
})->values ();
229
251
230
- $ this ->assertSame ([4 , 4 ], $ data ->all ());
252
+ $ this ->assertSame ([], $ data ->all ());
231
253
}
232
254
233
255
/**
@@ -237,10 +259,30 @@ public function testSkipWhile($collection)
237
259
{
238
260
$ data = new $ collection ([1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 ]);
239
261
240
- $ data = $ data ->skipWhile (1 )->values ();
262
+ // Item at the beginning of the collection
263
+ $ this ->assertSame ([2 , 2 , 3 , 3 , 4 , 4 ], $ data ->skipWhile (1 )->values ()->all ());
264
+
265
+ // Item not in the collection
266
+ $ this ->assertSame ([1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 ], $ data ->skipWhile (5 )->values ()->all ());
267
+
268
+ // Item in the collection but not at the beginning
269
+ $ this ->assertSame ([1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 ], $ data ->skipWhile (2 )->values ()->all ());
270
+
271
+ // Item not in the collection
272
+ $ data = $ data ->skipWhile (function ($ value , $ key ) {
273
+ return $ value >= 5 ;
274
+ })->values ();
275
+
276
+ $ this ->assertSame ([1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 ], $ data ->all ());
277
+
278
+ // Item in the collection but not at the beginning
279
+ $ data = $ data ->skipWhile (function ($ value , $ key ) {
280
+ return $ value >= 2 ;
281
+ })->values ();
241
282
242
- $ this ->assertSame ([2 , 2 , 3 , 3 , 4 , 4 ], $ data ->all ());
283
+ $ this ->assertSame ([1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 ], $ data ->all ());
243
284
285
+ // Item at the beginning of the collection
244
286
$ data = $ data ->skipWhile (function ($ value , $ key ) {
245
287
return $ value < 3 ;
246
288
})->values ();
0 commit comments