From 888f1d80d806b40c7da5c4e60810f09900990cc6 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Wed, 10 Feb 2021 12:53:57 -0500 Subject: [PATCH 1/2] Pass instance into `tap` directly --- src/Illuminate/Collections/Traits/EnumeratesValues.php | 2 +- tests/Support/SupportCollectionTest.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Collections/Traits/EnumeratesValues.php b/src/Illuminate/Collections/Traits/EnumeratesValues.php index aee05f114c0d..85720ebbedf7 100644 --- a/src/Illuminate/Collections/Traits/EnumeratesValues.php +++ b/src/Illuminate/Collections/Traits/EnumeratesValues.php @@ -764,7 +764,7 @@ public function reject($callback = true) */ public function tap(callable $callback) { - $callback(clone $this); + $callback($this); return $this; } diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index c5584d5ebbc9..506b85df8981 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -4126,10 +4126,13 @@ public function testTap($collection) $data = new $collection([1, 2, 3]); $fromTap = []; - $data = $data->tap(function ($data) use (&$fromTap) { + $tappedInstance = null; + $data = $data->tap(function ($data) use (&$fromTap, &$tappedInstance) { $fromTap = $data->slice(0, 1)->toArray(); + $tappedInstance = $data; }); + $this->assertSame($data, $tappedInstance); $this->assertSame([1], $fromTap); $this->assertSame([1, 2, 3], $data->toArray()); } From 902505915bd2502283b24e839daf302e2f86c658 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Wed, 10 Feb 2021 12:54:11 -0500 Subject: [PATCH 2/2] Use `tap` instead of `pipe` in test --- tests/Support/SupportLazyCollectionTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Support/SupportLazyCollectionTest.php b/tests/Support/SupportLazyCollectionTest.php index c671830029e1..bb85818b7d8f 100644 --- a/tests/Support/SupportLazyCollectionTest.php +++ b/tests/Support/SupportLazyCollectionTest.php @@ -164,7 +164,7 @@ public function testTakeUntilTimeout() $results = $mock ->times(10) - ->pipe(function ($collection) use ($mock, $timeout) { + ->tap(function ($collection) use ($mock, $timeout) { tap($collection) ->mockery_init($mock->mockery_getContainer()) ->shouldAllowMockingProtectedMethods() @@ -175,8 +175,6 @@ public function testTakeUntilTimeout() (clone $timeout)->sub(1, 'minute')->getTimestamp(), $timeout->getTimestamp() ); - - return $collection; }) ->takeUntilTimeout($timeout) ->all();