@@ -320,4 +320,115 @@ public function testFromIterable(): void
320
320
$ collectionFromGenerator = Collection::fromIterable ($ generatorFn ());
321
321
$ this ->assertSame ($ items , iterator_to_array ($ collectionFromGenerator ));
322
322
}
323
+
324
+ public function testEvery (): void
325
+ {
326
+ $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
327
+ $ collection = new Collection ($ items );
328
+
329
+ $ this ->assertFalse ($ collection ->every (static fn ($ item ) => $ item > 10 ));
330
+ $ this ->assertFalse ($ collection ->every (static fn ($ item ) => $ item > 5 ));
331
+ $ this ->assertTrue ($ collection ->every (static fn ($ item ) => $ item > 0 ));
332
+ }
333
+
334
+ public function testEveryWithoutArgumentDefaultsToTruthyCheck (): void
335
+ {
336
+ $ this ->assertTrue ((new Collection ([1 , true ]))->every ());
337
+ $ this ->assertTrue ((new Collection ([1 , true ]))->every ());
338
+ $ this ->assertFalse ((new Collection ([null , false ]))->every ());
339
+ $ this ->assertFalse ((new Collection ([false , null ]))->every ());
340
+ $ this ->assertFalse ((new Collection ([0 , false ]))->every ());
341
+ }
342
+
343
+ public function testEveryReturnsTrueOnEmptyCollection (): void
344
+ {
345
+ $ this ->assertTrue ((new Collection ())->every (static fn ($ item ) => false ));
346
+ }
347
+
348
+ public function testEveryShortCircuitsOnFirstFalsyValue (): void
349
+ {
350
+ $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
351
+ $ collection = new Collection ($ items );
352
+
353
+ $ collection ->every (function ($ item , $ index , $ c ) use ($ collection ): bool {
354
+ // First item already returns false therefore the index should never be something other than 0
355
+ $ this ->assertSame (0 , $ index );
356
+ $ this ->assertSame ($ c , $ collection );
357
+ return false ;
358
+ });
359
+ }
360
+
361
+ public function testNone (): void
362
+ {
363
+ $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
364
+ $ collection = new Collection ($ items );
365
+
366
+ $ this ->assertTrue ($ collection ->none (static fn ($ item ) => $ item > 10 ));
367
+ $ this ->assertFalse ($ collection ->none (static fn ($ item ) => $ item > 5 ));
368
+ $ this ->assertFalse ($ collection ->none (static fn ($ item ) => $ item > 0 ));
369
+ }
370
+
371
+ public function testNoneWithoutArgumentDefaultsToTruthyCheck (): void
372
+ {
373
+ $ this ->assertFalse ((new Collection ([1 , true ]))->none ());
374
+ $ this ->assertFalse ((new Collection ([1 , true ]))->none ());
375
+ $ this ->assertTrue ((new Collection ([null , false ]))->none ());
376
+ $ this ->assertTrue ((new Collection ([false , null ]))->none ());
377
+ $ this ->assertTrue ((new Collection ([0 , false ]))->none ());
378
+ }
379
+
380
+ public function testNoneReturnsFalseOnEmptyCollection (): void
381
+ {
382
+ $ this ->assertTrue ((new Collection ())->none (static fn ($ item ) => true ));
383
+ }
384
+
385
+ public function testNoneShortCircuitsOnFirstFalsyValue (): void
386
+ {
387
+ $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
388
+ $ collection = new Collection ($ items );
389
+
390
+ $ collection ->none (function ($ item , $ index , $ c ) use ($ collection ): bool {
391
+ // First item already returns true therefore the index should never be something other than 0
392
+ $ this ->assertSame (0 , $ index );
393
+ $ this ->assertSame ($ c , $ collection );
394
+ return true ;
395
+ });
396
+ }
397
+
398
+ public function testSome (): void
399
+ {
400
+ $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
401
+ $ collection = new Collection ($ items );
402
+
403
+ $ this ->assertFalse ($ collection ->some (static fn ($ item ) => $ item > 10 ));
404
+ $ this ->assertTrue ($ collection ->some (static fn ($ item ) => $ item > 5 ));
405
+ $ this ->assertTrue ($ collection ->some (static fn ($ item ) => $ item > 0 ));
406
+ }
407
+
408
+ public function testSomeWithoutArgumentDefaultsToTruthyCheck (): void
409
+ {
410
+ $ this ->assertTrue ((new Collection ([1 , true ]))->some ());
411
+ $ this ->assertTrue ((new Collection ([1 , true ]))->some ());
412
+ $ this ->assertFalse ((new Collection ([null , false ]))->some ());
413
+ $ this ->assertFalse ((new Collection ([false , null ]))->some ());
414
+ $ this ->assertFalse ((new Collection ([0 , false ]))->some ());
415
+ }
416
+
417
+ public function testSomeReturnsFalseOnEmptyCollection (): void
418
+ {
419
+ $ this ->assertFalse ((new Collection ())->some (static fn ($ item ) => true ));
420
+ }
421
+
422
+ public function testSomeShortCircuitsOnFirstFalsyValue (): void
423
+ {
424
+ $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
425
+ $ collection = new Collection ($ items );
426
+
427
+ $ collection ->some (function ($ item , $ index , $ c ) use ($ collection ): bool {
428
+ // First item already returns true therefore the index should never be something other than 0
429
+ $ this ->assertSame (0 , $ index );
430
+ $ this ->assertSame ($ c , $ collection );
431
+ return true ;
432
+ });
433
+ }
323
434
}
0 commit comments