Skip to content

Commit

Permalink
[VarDumper] Fix dd() showing line with null
Browse files Browse the repository at this point in the history
  • Loading branch information
HypeMC committed May 23, 2023
1 parent a93ec17 commit 5008fa8
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Resources/functions/dump.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function dd(mixed ...$vars): never
header('HTTP/1.1 500 Internal Server Error');
}

if (isset($vars[0]) && 1 === count($vars)) {
if (array_key_exists(0, $vars) && 1 === count($vars)) {
VarDumper::dump($vars[0]);
} else {
foreach ($vars as $k => $v) {
Expand Down
17 changes: 17 additions & 0 deletions Tests/Dumper/functions/dd_with_multiple_args.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test dd() with multiple args shows line number
--FILE--
<?php

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = \dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

dd(null, 1, 'foo');

--EXPECT--
1 null
2 1
3 "foo"
15 changes: 15 additions & 0 deletions Tests/Dumper/functions/dd_with_null.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Test dd() with null doesn't show line number
--FILE--
<?php

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = \dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

dd(null);

--EXPECT--
null
15 changes: 15 additions & 0 deletions Tests/Dumper/functions/dd_with_single_arg.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Test dd() with one arg doesn't show line number
--FILE--
<?php

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = \dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

dd('foo');

--EXPECT--
"foo"
17 changes: 17 additions & 0 deletions Tests/Dumper/functions/dump_with_multiple_args.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test dump() with multiple args shows line number
--FILE--
<?php

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = \dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

dump(null, 1, 'foo');

--EXPECT--
1 null
2 1
3 "foo"
15 changes: 15 additions & 0 deletions Tests/Dumper/functions/dump_with_null.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Test dump() with null doesn't show line number
--FILE--
<?php

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = \dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

dump(null);

--EXPECT--
null
15 changes: 15 additions & 0 deletions Tests/Dumper/functions/dump_with_single_arg.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Test dump() with one arg doesn't show line number
--FILE--
<?php

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = \dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

dump('foo');

--EXPECT--
"foo"
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<testsuites>
<testsuite name="Symfony VarDumper Component Test Suite">
<directory>./Tests/</directory>
<directory suffix=".phpt">./Tests/Dumper/functions/</directory>
</testsuite>
</testsuites>

Expand Down

0 comments on commit 5008fa8

Please sign in to comment.