Skip to content

Commit

Permalink
Fix the dump method for LazyCollection (#33944)
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephSilber authored Aug 20, 2020
1 parent 28f847f commit 455b343
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public function dd(...$args)
*/
public function dump()
{
(new static(func_get_args()))
->push($this)
(new Collection(func_get_args()))
->push($this->all())
->each(function ($item) {
VarDumper::dump($item);
});
Expand Down
19 changes: 19 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use stdClass;
use Symfony\Component\VarDumper\VarDumper;

class SupportCollectionTest extends TestCase
{
Expand Down Expand Up @@ -3419,6 +3420,24 @@ public function testConcatWithCollection($collection)
$this->assertSame($expected, $actual);
}

/**
* @dataProvider collectionClassProvider
*/
public function testDump($collection)
{
$log = new Collection();

VarDumper::setHandler(function ($value) use ($log) {
$log->add($value);
});

(new $collection([1, 2, 3]))->dump('one', 'two');

$this->assertSame(['one', 'two', [1, 2, 3]], $log->all());

VarDumper::setHandler(null);
}

/**
* @dataProvider collectionClassProvider
*/
Expand Down

0 comments on commit 455b343

Please sign in to comment.