Skip to content

Commit 8a106ef

Browse files
authored
[9.x] Pass collection instance into tap directly, not a clone (#36220)
* Pass instance into `tap` directly * Use `tap` instead of `pipe` in test
1 parent e095ac0 commit 8a106ef

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/Illuminate/Collections/Traits/EnumeratesValues.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ public function reject($callback = true)
764764
*/
765765
public function tap(callable $callback)
766766
{
767-
$callback(clone $this);
767+
$callback($this);
768768

769769
return $this;
770770
}

tests/Support/SupportCollectionTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -4126,10 +4126,13 @@ public function testTap($collection)
41264126
$data = new $collection([1, 2, 3]);
41274127

41284128
$fromTap = [];
4129-
$data = $data->tap(function ($data) use (&$fromTap) {
4129+
$tappedInstance = null;
4130+
$data = $data->tap(function ($data) use (&$fromTap, &$tappedInstance) {
41304131
$fromTap = $data->slice(0, 1)->toArray();
4132+
$tappedInstance = $data;
41314133
});
41324134

4135+
$this->assertSame($data, $tappedInstance);
41334136
$this->assertSame([1], $fromTap);
41344137
$this->assertSame([1, 2, 3], $data->toArray());
41354138
}

tests/Support/SupportLazyCollectionTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function testTakeUntilTimeout()
164164

165165
$results = $mock
166166
->times(10)
167-
->pipe(function ($collection) use ($mock, $timeout) {
167+
->tap(function ($collection) use ($mock, $timeout) {
168168
tap($collection)
169169
->mockery_init($mock->mockery_getContainer())
170170
->shouldAllowMockingProtectedMethods()
@@ -175,8 +175,6 @@ public function testTakeUntilTimeout()
175175
(clone $timeout)->sub(1, 'minute')->getTimestamp(),
176176
$timeout->getTimestamp()
177177
);
178-
179-
return $collection;
180178
})
181179
->takeUntilTimeout($timeout)
182180
->all();

0 commit comments

Comments
 (0)