From b99c4d611bc87df7e978876124e8f180c6a8ea3f Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Thu, 20 Jan 2022 10:21:54 +0000 Subject: [PATCH 1/3] test --- tests/Features/Expect/each.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Features/Expect/each.php b/tests/Features/Expect/each.php index 0f26a974..ad61f578 100644 --- a/tests/Features/Expect/each.php +++ b/tests/Features/Expect/each.php @@ -79,11 +79,13 @@ it('can add expectations via "and"', function () { }); it('accepts callables', function () { - expect([1, 2, 3])->each(function ($number) { + expect([1, 2, 3])->each(function ($number, $key) { expect($number)->toBeInstanceOf(Expectation::class); expect($number->value)->toBeInt(); $number->toBeInt->not->toBeString; + + expect($key)->toBeInt(); }); - expect(static::getCount())->toBe(12); + expect(static::getCount())->toBe(15); }); From 635a71ce666518aa914170c5ca93da9dfaf08bd6 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Thu, 20 Jan 2022 10:21:57 +0000 Subject: [PATCH 2/3] feature --- src/Expectation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 8dc287a0..300820c1 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -125,8 +125,8 @@ final class Expectation } if (is_callable($callback)) { - foreach ($this->value as $item) { - $callback(new self($item)); + foreach ($this->value as $key => $item) { + $callback(new self($item), $key); } } From 12b48a6cf698a76b2d54407b8e348f78a245de93 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Thu, 20 Jan 2022 10:34:32 +0000 Subject: [PATCH 3/3] move to new test --- tests/Features/Expect/each.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/Features/Expect/each.php b/tests/Features/Expect/each.php index ad61f578..63b3d60c 100644 --- a/tests/Features/Expect/each.php +++ b/tests/Features/Expect/each.php @@ -79,13 +79,19 @@ it('can add expectations via "and"', function () { }); it('accepts callables', function () { - expect([1, 2, 3])->each(function ($number, $key) { + expect([1, 2, 3])->each(function ($number) { expect($number)->toBeInstanceOf(Expectation::class); expect($number->value)->toBeInt(); $number->toBeInt->not->toBeString; + }); + 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(15); + expect(static::getCount())->toBe(3); });