Skip to content

Commit 4a4a3aa

Browse files
committed
Richer argument display
1 parent d229f22 commit 4a4a3aa

File tree

3 files changed

+66
-29
lines changed

3 files changed

+66
-29
lines changed

lib/r.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,26 @@ private static function formatDb(bool $fullstack): string
7676
$output .= (isset($point['class']) ? $point['class'] . '->' : '') . $point['function'];
7777

7878
$args = [];
79-
foreach ($point['args'] as $argument) {
80-
$args[] = (\is_object($argument)
81-
? \get_class($argument)
82-
: \gettype($argument)
83-
);
79+
foreach ($point['args'] as $originalArgument) {
80+
if (\is_object($originalArgument)) {
81+
$argument = \get_class($originalArgument);
82+
} else {
83+
$argument = \gettype($originalArgument);
84+
if (\is_array($originalArgument)) {
85+
$argument .= ':' . \count($originalArgument);
86+
} elseif (\is_bool($originalArgument)) {
87+
$argument .= ':' . ($originalArgument ? 'true' : 'false');
88+
} elseif (\is_string($originalArgument)) {
89+
$argument .= ':' . (isset($originalArgument[21])
90+
? \strlen($originalArgument) . ':' . \substr($originalArgument, 0, 21) . '[...]'
91+
: $originalArgument
92+
);
93+
} elseif (\is_scalar($originalArgument)) {
94+
$argument .= ':' . $originalArgument;
95+
}
96+
}
97+
98+
$args[] = $argument;
8499
}
85100

86101
$output .= '(' . \implode(', ', $args) . ')' . \PHP_EOL;
@@ -108,14 +123,6 @@ private static function formatDb(bool $fullstack): string
108123
* Static class containing most used debug methods.
109124
*
110125
* @see www.doctrine-project.org
111-
* @since 2.0
112-
*
113-
* @author Guilherme Blanco <[email protected]>
114-
* @author Jonathan Wage <[email protected]>
115-
* @author Roman Borschel <[email protected]>
116-
* @author Giorgio Sironi <[email protected]>
117-
*
118-
* @deprecated the Debug class is deprecated, please use symfony/var-dumper instead
119126
*/
120127
final class Debug
121128
{

tests/Doctrine/DebugTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
final class DebugTest extends TestCase
1111
{
12-
public function testExportObject()
12+
public function testExportObject(): void
1313
{
1414
$obj = new \stdClass();
1515
$obj->foo = 'bar';
@@ -19,7 +19,7 @@ public function testExportObject()
1919
static::assertEquals('stdClass', $var->__CLASS__);
2020
}
2121

22-
public function testExportObjectWithReference()
22+
public function testExportObjectWithReference(): void
2323
{
2424
$foo = 'bar';
2525
$bar = ['foo' => & $foo];
@@ -32,7 +32,7 @@ public function testExportObjectWithReference()
3232
static::assertEquals('tab', $bar['foo']);
3333
}
3434

35-
public function testExportArray()
35+
public function testExportArray(): void
3636
{
3737
$array = ['a' => 'b', 'b' => ['c', 'd' => ['e', 'f']]];
3838
$var = Debug::export($array, 2);
@@ -41,7 +41,7 @@ public function testExportArray()
4141
static::assertEquals($expected, $var);
4242
}
4343

44-
public function testExportDateTime()
44+
public function testExportDateTime(): void
4545
{
4646
$obj = new \DateTime('2010-10-10 10:10:10', new \DateTimeZone('UTC'));
4747

@@ -50,7 +50,7 @@ public function testExportDateTime()
5050
static::assertEquals('2010-10-10T10:10:10+00:00', $var->date);
5151
}
5252

53-
public function testExportDateTimeImmutable()
53+
public function testExportDateTimeImmutable(): void
5454
{
5555
$obj = new \DateTimeImmutable('2010-10-10 10:10:10', new \DateTimeZone('UTC'));
5656

@@ -59,7 +59,7 @@ public function testExportDateTimeImmutable()
5959
static::assertEquals('2010-10-10T10:10:10+00:00', $var->date);
6060
}
6161

62-
public function testExportDateTimeZone()
62+
public function testExportDateTimeZone(): void
6363
{
6464
$obj = new \DateTimeImmutable('2010-10-10 12:34:56', new \DateTimeZone('Europe/Rome'));
6565

@@ -68,7 +68,7 @@ public function testExportDateTimeZone()
6868
static::assertEquals('2010-10-10T12:34:56+02:00', $var->date);
6969
}
7070

71-
public function testExportArrayTraversable()
71+
public function testExportArrayTraversable(): void
7272
{
7373
$obj = new \ArrayObject(['foobar']);
7474

@@ -81,7 +81,7 @@ public function testExportArrayTraversable()
8181
static::assertContains('foobar', $var->__STORAGE__);
8282
}
8383

84-
public function testReturnsOutput()
84+
public function testReturnsOutput(): void
8585
{
8686
\ob_start();
8787

@@ -93,7 +93,7 @@ public function testReturnsOutput()
9393
static::assertSame($outputValue, $dump);
9494
}
9595

96-
public function testDisablesOutput()
96+
public function testDisablesOutput(): void
9797
{
9898
\ob_start();
9999

@@ -109,7 +109,7 @@ public function testDisablesOutput()
109109
/**
110110
* @dataProvider provideAttributesCases
111111
*/
112-
public function testExportParentAttributes(TestAsset\ParentClass $class, array $expected)
112+
public function testExportParentAttributes(TestAsset\ParentClass $class, array $expected): void
113113
{
114114
$print_r_class = \print_r($class, true);
115115
$print_r_expected = \print_r($expected, true);

tests/RTest.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ final class RTest extends TestCase
1111
{
1212
public const STREAM_FILTER_NAME = 'STDERR_MOCK';
1313

14+
/**
15+
* @var bool
16+
*/
1417
private static $isStreamFilterRegistered;
1518

19+
/**
20+
* @var resource
21+
*/
1622
private $registeredFilter;
1723

1824
protected function setUp(): void
@@ -30,23 +36,23 @@ protected function tearDown(): void
3036
\stream_filter_remove($this->registeredFilter);
3137
}
3238

33-
public function testScalar()
39+
public function testScalar(): void
3440
{
3541
r(1, false);
3642

3743
static::assertStringContainsString(__FILE__, MockStderr::$output);
3844
static::assertStringContainsString('int(1)', MockStderr::$output);
3945
}
4046

41-
public function testNonScalar()
47+
public function testNonScalar(): void
4248
{
4349
r([1 => 2], false);
4450

4551
static::assertStringContainsString(__FILE__, MockStderr::$output);
4652
static::assertStringContainsString("Array\n(\n [1] => 2\n)", MockStderr::$output);
4753
}
4854

49-
public function testFullstackOutput()
55+
public function testFullstackOutput(): void
5056
{
5157
r(1, false, 0, true);
5258

@@ -55,22 +61,22 @@ public function testFullstackOutput()
5561
static::assertStringContainsString('TestCase', MockStderr::$output);
5662
}
5763

58-
public function testQueryDebug()
64+
public function testQueryDebug(): void
5965
{
6066
rq('SELECT * FROM table WHERE c1 = :p1 AND c1 = :p11 AND c1 = :p2', ['p1' => 1, 'p11' => 2, 'p2' => '"'], false, 0, true);
6167

6268
static::assertStringContainsString('SELECT * FROM table WHERE c1 = "1" AND c1 = "2" AND c1 = "\\""', MockStderr::$output);
6369
}
6470

65-
public function testDoctrine()
71+
public function testDoctrine(): void
6672
{
6773
r(new stdClass(), false, 1);
6874

6975
static::assertStringContainsString(__FILE__, MockStderr::$output);
7076
static::assertStringContainsString('__CLASS__', MockStderr::$output);
7177
}
7278

73-
public function testClearRootPath()
79+
public function testClearRootPath(): void
7480
{
7581
\define('ROOT_PATH', __DIR__);
7682

@@ -79,4 +85,28 @@ public function testClearRootPath()
7985
static::assertStringContainsString(\basename(__FILE__), MockStderr::$output);
8086
static::assertStringNotContainsString(__DIR__, MockStderr::$output);
8187
}
88+
89+
/**
90+
* @dataProvider provideCallArgumentDetails
91+
*/
92+
public function testCallArgumentDetails($argument, string $expectedNeedle): void
93+
{
94+
r($argument, false);
95+
96+
static::assertStringContainsString($expectedNeedle, MockStderr::$output);
97+
}
98+
99+
public function provideCallArgumentDetails(): array
100+
{
101+
return [
102+
[new stdClass(), 'r(stdClass,'],
103+
[[1, 2], 'r(array:2,'],
104+
[3, 'r(integer:3,'],
105+
['4', 'r(string:4,'],
106+
[5.1, 'r(double:5.1,'],
107+
[null, 'r(NULL,'],
108+
[true, 'r(boolean:true,'],
109+
[\str_repeat('foobar ', 10), 'r(string:70:foobar foobar foobar [...],'],
110+
];
111+
}
82112
}

0 commit comments

Comments
 (0)