Skip to content

Commit 8de3bbd

Browse files
committed
First element filter support test.
1 parent e5fee8c commit 8de3bbd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/WS/Utils/Collections/SerialStreamTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,15 @@ public function firstLastElementCases(): array
391391
];
392392
}
393393

394+
public function firstFirstElementWithFilterCases(): array
395+
{
396+
return [
397+
[ [1, 2, 3], 2, 2],
398+
[ [1], 2, null],
399+
[[], 2, null]
400+
];
401+
}
402+
394403
/**
395404
* @dataProvider firstLastElementCases
396405
* @test
@@ -405,6 +414,23 @@ public function findFirstElement($input, $first): void
405414
$this->assertEquals($first, $actual);
406415
}
407416

417+
/**
418+
* @dataProvider firstFirstElementWithFilterCases
419+
* @test
420+
* @param array $input
421+
* @param mixed $first
422+
* @param mixed $expected
423+
*/
424+
public function findFirstElementWithFilter(array $input, $first, $expected): void
425+
{
426+
$actual = $this->createCollection($input)
427+
->stream()
428+
->findFirst(function ($item) use ($first) {
429+
return $item === $first;
430+
});
431+
$this->assertEquals($expected, $actual);
432+
}
433+
408434
/** @noinspection PhpUnusedParameterInspection */
409435
/**
410436
* @dataProvider firstLastElementCases

0 commit comments

Comments
 (0)