Skip to content

Commit 9488596

Browse files
[VarDumper] LinkStub fix
1 parent 8ca77f9 commit 9488596

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/Symfony/Component/VarDumper/Caster/LinkStub.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public function __construct($label, $line = 0, $href = null)
2727
}
2828
if (is_string($href)) {
2929
if (0 === strpos($href, 'file://')) {
30+
if ($href === $label) {
31+
$label = substr($label, 7);
32+
}
3033
$href = substr($href, 7);
3134
} elseif (false !== strpos($href, '://')) {
3235
$this->attr['href'] = $href;
@@ -39,7 +42,7 @@ public function __construct($label, $line = 0, $href = null)
3942
}
4043
$this->attr['file'] = realpath($href);
4144

42-
if ($this->attr['file'] === $href && 3 < count($ellipsis = explode(DIRECTORY_SEPARATOR, $href))) {
45+
if ($this->attr['file'] === $label && 3 < count($ellipsis = explode(DIRECTORY_SEPARATOR, $href))) {
4346
$this->attr['ellipsis'] = 2 + strlen(implode(array_slice($ellipsis, -2)));
4447
}
4548
}

src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,12 @@ public function testHtmlDump()
139139
$e = $this->getTestException(1);
140140
ExceptionCaster::$srcContext = -1;
141141

142-
$h = fopen('php://memory', 'r+b');
143142
$cloner = new VarCloner();
144143
$cloner->setMaxItems(1);
145-
$dumper = new HtmlDumper($h);
144+
$dumper = new HtmlDumper();
146145
$dumper->setDumpHeader('<foo></foo>');
147146
$dumper->setDumpBoundaries('<bar>', '</bar>');
148-
$dumper->dump($cloner->cloneVar($e)->withRefHandles(false));
149-
$dump = stream_get_contents($h, -1, 0);
150-
fclose($h);
147+
$dump = $dumper->dump($cloner->cloneVar($e)->withRefHandles(false), true);
151148

152149
$expectedDump = <<<'EODUMP'
153150
<foo></foo><bar><span class=sf-dump-note>Exception</span> {<samp>

src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\VarDumper\Caster\ArgsStub;
1515
use Symfony\Component\VarDumper\Caster\ClassStub;
16+
use Symfony\Component\VarDumper\Caster\LinkStub;
1617
use Symfony\Component\VarDumper\Cloner\VarCloner;
1718
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
1819
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
@@ -85,6 +86,26 @@ public function testArgsStubWithClosure()
8586
$this->assertDumpMatchesFormat($expectedDump, $args);
8687
}
8788

89+
public function testLinkStub()
90+
{
91+
$var = array(new LinkStub(__CLASS__, 0, __FILE__));
92+
93+
$cloner = new VarCloner();
94+
$dumper = new HtmlDumper();
95+
$dumper->setDumpHeader('<foo></foo>');
96+
$dumper->setDumpBoundaries('<bar>', '</bar>');
97+
$dump = $dumper->dump($cloner->cloneVar($var), true);
98+
99+
$expectedDump = <<<'EODUMP'
100+
<foo></foo><bar><span class=sf-dump-note>array:1</span> [<samp>
101+
<span class=sf-dump-index>0</span> => "<a data-file="%sStubCasterTest.php" data-line="1"><span class=sf-dump-str title="%d characters">Symfony\Component\VarDumper\Tests\Caster\StubCasterTest</span></a>"
102+
</samp>]
103+
</bar>
104+
EODUMP;
105+
106+
$this->assertStringMatchesFormat($expectedDump, $dump);
107+
}
108+
88109
public function testClassStub()
89110
{
90111
$var = array(new ClassStub('hello', array(FooInterface::class, 'foo')));

0 commit comments

Comments
 (0)