@@ -433,6 +433,52 @@ public function testSomeShortCircuitsOnFirstFalsyValue(): void
433433 });
434434 }
435435
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+
436482 public function testFirst (): void
437483 {
438484 $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
@@ -477,7 +523,7 @@ public function testFirstOrReturnsFallbackValueIfCallbackIsNeverSatisfied(): voi
477523 {
478524 $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
479525 $ 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 ));
481527 }
482528
483529 public function testLast (): void
@@ -524,7 +570,7 @@ public function testLastOrReturnsFallbackValueIfCallbackIsNeverSatisfied(): void
524570 {
525571 $ items = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ];
526572 $ 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 ));
528574 }
529575
530576 public function testIsEmpty (): void
0 commit comments