Skip to content

Commit fee0590

Browse files
committed
close #17
1 parent 86b779d commit fee0590

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

src/VarOutput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function __construct(
3030
private array $trace,
3131
private FormatInterface $format,
3232
) {
33-
$this->objectReferences = new ObjectReferences();
3433
}
3534

3635
public function process(OutputInterface $output, mixed ...$variables): void
@@ -46,6 +45,7 @@ private function handleArgs(mixed ...$variables): void
4645
{
4746
$aux = 0;
4847
foreach ($variables as $name => $value) {
48+
$this->objectReferences = new ObjectReferences();
4949
$aux++;
5050
if (is_int($name)) {
5151
$name = $aux;

tests/VarDumpTest.php

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,63 @@ public function testWithVariables(): void
3636
{
3737
$stream = $this->getStream();
3838
$writer = new StreamWriter($stream);
39-
$variable = new stdClass();
39+
$var = new stdClass();
4040
$varDump = $this->getVarDump();
41-
$varDumpWithVariables = $varDump->withVariables($variable);
41+
$varDumpWithVariables = $varDump->withVariables($var);
4242
$this->assertNotSame($varDump, $varDumpWithVariables);
4343
$this->assertEqualsCanonicalizing(
44-
[$variable],
44+
[$var],
4545
$varDumpWithVariables->variables()
4646
);
4747
$varDumpWithVariables->process($writer);
4848
$line = strval(__LINE__ - 1);
49-
$hrLine = str_repeat('-', 60);
50-
$expectedString = "\n"
51-
. $varDump::class . '->process()'
52-
. "\n"
53-
. $hrLine
54-
. "\n"
55-
. __FILE__ . ':' . $line
56-
. "\n\n"
57-
. 'Arg#1 stdClass#' . spl_object_id($variable)
58-
. "\n" . $hrLine
59-
. "\n";
49+
$className = $varDump::class;
50+
$fileLine = __FILE__ . ':' . $line;
51+
$objectId = spl_object_id($var);
52+
$expectedString = <<<PLAIN
53+
54+
{$className}->process()
55+
------------------------------------------------------------
56+
{$fileLine}
57+
58+
Arg#1 stdClass#{$objectId}
59+
------------------------------------------------------------
60+
61+
PLAIN;
62+
$this->assertSame($expectedString, $writer->__toString());
63+
}
64+
65+
public function testCircularReferenceArguments(): void
66+
{
67+
$var = new stdClass();
68+
$var->circular = $var;
69+
$var->string = 'test';
70+
$varDump = $this->getVarDump();
71+
$varDumpWithVariables = $varDump->withVariables($var, [$var]);
72+
$stream = $this->getStream();
73+
$writer = new StreamWriter($stream);
74+
$varDumpWithVariables->process($writer);
75+
$line = strval(__LINE__ - 1);
76+
$className = $varDump::class;
77+
$fileLine = __FILE__ . ':' . $line;
78+
$objectId = spl_object_id($var);
79+
$expectedString = <<<PLAIN
80+
81+
{$className}->process()
82+
------------------------------------------------------------
83+
{$fileLine}
84+
85+
Arg#1 stdClass#{$objectId}
86+
public circular stdClass#{$objectId} (circular reference #{$objectId})
87+
public string string test (length=4)
88+
89+
Arg#2 array (size=1)
90+
0 => stdClass#{$objectId}
91+
public circular stdClass#{$objectId} (circular reference #{$objectId})
92+
public string string test (length=4)
93+
------------------------------------------------------------
94+
95+
PLAIN;
6096
$this->assertSame($expectedString, $writer->__toString());
6197
}
6298

0 commit comments

Comments
 (0)