@@ -347,6 +347,34 @@ public function testShiftReturnsAndRemovesFirstXItemsInCollection()
347
347
$ this ->assertSame ('baz ' , $ data ->first ());
348
348
349
349
$ this ->assertEquals (new Collection (['foo ' , 'bar ' , 'baz ' ]), (new Collection (['foo ' , 'bar ' , 'baz ' ]))->shift (6 ));
350
+
351
+ $ data = new Collection (['foo ' , 'bar ' , 'baz ' ]);
352
+
353
+ $ this ->assertEquals (new Collection ([]), $ data ->shift (0 ));
354
+ $ this ->assertEquals (collect (['foo ' , 'bar ' , 'baz ' ]), $ data );
355
+
356
+ $ this ->expectException ('InvalidArgumentException ' );
357
+ (new Collection (['foo ' , 'bar ' , 'baz ' ]))->shift (-1 );
358
+
359
+ $ this ->expectException ('InvalidArgumentException ' );
360
+ (new Collection (['foo ' , 'bar ' , 'baz ' ]))->shift (-2 );
361
+ }
362
+
363
+ public function testShiftReturnsNullOnEmptyCollection ()
364
+ {
365
+ $ itemFoo = new \stdClass ();
366
+ $ itemFoo ->text = 'f ' ;
367
+ $ itemBar = new \stdClass ();
368
+ $ itemBar ->text = 'x ' ;
369
+
370
+ $ items = collect ([$ itemFoo , $ itemBar ]);
371
+
372
+ $ foo = $ items ->shift ();
373
+ $ bar = $ items ->shift ();
374
+
375
+ $ this ->assertSame ('f ' , $ foo ?->text);
376
+ $ this ->assertSame ('x ' , $ bar ?->text);
377
+ $ this ->assertNull ($ items ->shift ());
350
378
}
351
379
352
380
#[DataProvider('collectionClassProvider ' )]
0 commit comments