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()); } 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();