mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Merge pull request #460 from danharrin/feature/each-keys
feature: Pass `each()` keys to closures
This commit is contained in:
@ -125,8 +125,8 @@ final class Expectation
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_callable($callback)) {
|
if (is_callable($callback)) {
|
||||||
foreach ($this->value as $item) {
|
foreach ($this->value as $key => $item) {
|
||||||
$callback(new self($item));
|
$callback(new self($item), $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -87,3 +87,11 @@ it('accepts callables', function () {
|
|||||||
|
|
||||||
expect(static::getCount())->toBe(12);
|
expect(static::getCount())->toBe(12);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('passes the key of the current item to callables', function () {
|
||||||
|
expect([1, 2, 3])->each(function ($number, $key) {
|
||||||
|
expect($key)->toBeInt();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(static::getCount())->toBe(3);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user