Skip to content

Commit 52faa00

Browse files
committed
Fix base DataCollector throws warning on unsupported scheme strings
1 parent 1d96df0 commit 52faa00

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function decorateVar($var)
130130
return new ClassStub($var);
131131
}
132132
}
133-
if (false !== strpos($var, DIRECTORY_SEPARATOR) && file_exists($var)) {
133+
if (false !== strpos($var, DIRECTORY_SEPARATOR) && false === strpos($var, '://') && file_exists($var)) {
134134
return new LinkStub($var);
135135
}
136136
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\HttpKernel\Tests\Fixtures\DataCollector\CloneVarDataCollector;
17+
use Symfony\Component\VarDumper\Cloner\Stub;
18+
use Symfony\Component\VarDumper\Cloner\VarCloner;
19+
use Symfony\Component\VarDumper\Dumper\CliDumper;
20+
21+
class DataCollectorTest extends \PHPUnit_Framework_TestCase
22+
{
23+
public function testCloneVarStringWithScheme()
24+
{
25+
$c = new CloneVarDataCollector('scheme://foo');
26+
$c->collect(new Request(), new Response());
27+
$cloner = new VarCloner();
28+
29+
$this->assertEquals($cloner->cloneVar('scheme://foo'), $c->getData());
30+
}
31+
32+
public function testCloneVarExistingFilePath()
33+
{
34+
$c = new CloneVarDataCollector($filePath = tempnam(sys_get_temp_dir(), 'clone_var_data_collector_'));
35+
$c->collect(new Request(), new Response());
36+
37+
$data = $c->getData();
38+
$this->assertInstanceOf(Stub::class, $data->getRawData()[0][0]);
39+
$this->assertDumpEquals("\"$filePath\"", $data);
40+
}
41+
42+
private function assertDumpEquals($dump, $data, $message = '')
43+
{
44+
$dumper = new CliDumper();
45+
$dumper->setColors(false);
46+
47+
$this->assertSame(rtrim($dump), rtrim($dumper->dump($data, true)), $message);
48+
}
49+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpKernel\Tests\Fixtures\DataCollector;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
17+
18+
class CloneVarDataCollector extends DataCollector
19+
{
20+
private $varToClone;
21+
22+
public function __construct($varToClone)
23+
{
24+
$this->varToClone = $varToClone;
25+
}
26+
27+
public function collect(Request $request, Response $response, \Exception $exception = null)
28+
{
29+
$this->data = $this->cloneVar($this->varToClone);
30+
}
31+
32+
public function getData()
33+
{
34+
return $this->data;
35+
}
36+
37+
public function getName()
38+
{
39+
return 'clone_var';
40+
}
41+
}

0 commit comments

Comments
 (0)