@@ -433,6 +433,52 @@ public function testSomeShortCircuitsOnFirstFalsyValue(): void
433
433
});
434
434
}
435
435
436
+ public function testFind (): void
437
+ {
438
+ $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
439
+ $ collection = new Collection ($ items );
440
+
441
+ $ this ->assertSame (3 , $ collection ->find (static fn ($ item ) => $ item > 2 ));
442
+ }
443
+
444
+ public function testFindReturnsNullIfCallbackNeverReturnsTrue (): void
445
+ {
446
+ $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
447
+ $ collection = new Collection ($ items );
448
+
449
+ $ this ->assertSame (null , $ collection ->find (static fn () => false ));
450
+ }
451
+
452
+ public function testFindReturnsNullOnEmptyCollection (): void
453
+ {
454
+ $ collection = new Collection ([]);
455
+
456
+ $ this ->assertSame (null , $ collection ->find (static fn () => true ));
457
+ }
458
+
459
+ public function testFindLast (): void
460
+ {
461
+ $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
462
+ $ collection = new Collection ($ items );
463
+
464
+ $ this ->assertSame (10 , $ collection ->findLast (static fn ($ item ) => $ item > 2 ));
465
+ }
466
+
467
+ public function testFindLastReturnsNullIfCallbackNeverReturnsTrue (): void
468
+ {
469
+ $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
470
+ $ collection = new Collection ($ items );
471
+
472
+ $ this ->assertSame (null , $ collection ->findLast (static fn () => false ));
473
+ }
474
+
475
+ public function testFindLastReturnsNullOnEmptyCollection (): void
476
+ {
477
+ $ collection = new Collection ([]);
478
+
479
+ $ this ->assertSame (null , $ collection ->find (static fn () => true ));
480
+ }
481
+
436
482
public function testFirst (): void
437
483
{
438
484
$ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
@@ -477,7 +523,7 @@ public function testFirstOrReturnsFallbackValueIfCallbackIsNeverSatisfied(): voi
477
523
{
478
524
$ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
479
525
$ collection = new Collection ($ items );
480
- $ this ->assertSame (-1 , $ collection ->firstOr (static fn ($ item ) => $ item > 10 , -1 ));
526
+ $ this ->assertSame (-1 , $ collection ->firstOr (static fn () => false , -1 ));
481
527
}
482
528
483
529
public function testLast (): void
@@ -524,7 +570,7 @@ public function testLastOrReturnsFallbackValueIfCallbackIsNeverSatisfied(): void
524
570
{
525
571
$ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
526
572
$ collection = new Collection ($ items );
527
- $ this ->assertSame (-1 , $ collection ->lastOr (static fn ($ item ) => $ item > 10 , -1 ));
573
+ $ this ->assertSame (-1 , $ collection ->lastOr (static fn () => false , -1 ));
528
574
}
529
575
530
576
public function testIsEmpty (): void
0 commit comments