Skip to content

Commit

Permalink
close #17
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed May 19, 2024
1 parent 86b779d commit fee0590
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/VarOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function __construct(
private array $trace,
private FormatInterface $format,
) {
$this->objectReferences = new ObjectReferences();
}

public function process(OutputInterface $output, mixed ...$variables): void
Expand All @@ -46,6 +45,7 @@ private function handleArgs(mixed ...$variables): void
{
$aux = 0;
foreach ($variables as $name => $value) {
$this->objectReferences = new ObjectReferences();
$aux++;
if (is_int($name)) {
$name = $aux;
Expand Down
64 changes: 50 additions & 14 deletions tests/VarDumpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,63 @@ public function testWithVariables(): void
{
$stream = $this->getStream();
$writer = new StreamWriter($stream);
$variable = new stdClass();
$var = new stdClass();
$varDump = $this->getVarDump();
$varDumpWithVariables = $varDump->withVariables($variable);
$varDumpWithVariables = $varDump->withVariables($var);
$this->assertNotSame($varDump, $varDumpWithVariables);
$this->assertEqualsCanonicalizing(
[$variable],
[$var],
$varDumpWithVariables->variables()
);
$varDumpWithVariables->process($writer);
$line = strval(__LINE__ - 1);
$hrLine = str_repeat('-', 60);
$expectedString = "\n"
. $varDump::class . '->process()'
. "\n"
. $hrLine
. "\n"
. __FILE__ . ':' . $line
. "\n\n"
. 'Arg#1 stdClass#' . spl_object_id($variable)
. "\n" . $hrLine
. "\n";
$className = $varDump::class;
$fileLine = __FILE__ . ':' . $line;
$objectId = spl_object_id($var);
$expectedString = <<<PLAIN
{$className}->process()
------------------------------------------------------------
{$fileLine}
Arg#1 stdClass#{$objectId}
------------------------------------------------------------
PLAIN;
$this->assertSame($expectedString, $writer->__toString());
}

public function testCircularReferenceArguments(): void
{
$var = new stdClass();
$var->circular = $var;
$var->string = 'test';
$varDump = $this->getVarDump();
$varDumpWithVariables = $varDump->withVariables($var, [$var]);
$stream = $this->getStream();
$writer = new StreamWriter($stream);
$varDumpWithVariables->process($writer);
$line = strval(__LINE__ - 1);
$className = $varDump::class;
$fileLine = __FILE__ . ':' . $line;
$objectId = spl_object_id($var);
$expectedString = <<<PLAIN
{$className}->process()
------------------------------------------------------------
{$fileLine}
Arg#1 stdClass#{$objectId}
public circular stdClass#{$objectId} (circular reference #{$objectId})
public string string test (length=4)
Arg#2 array (size=1)
0 => stdClass#{$objectId}
public circular stdClass#{$objectId} (circular reference #{$objectId})
public string string test (length=4)
------------------------------------------------------------
PLAIN;
$this->assertSame($expectedString, $writer->__toString());
}

Expand Down

0 comments on commit fee0590

Please sign in to comment.