8000 [HttpKernel] tests for DumpListener · symfony/symfony@081363c · GitHub
[go: up one dir, main page]

Skip to content

Commit 081363c

Browse files
[HttpKernel] tests for DumpListener
1 parent 0d8a942 commit 081363c

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\EventListener;
13+
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
17+
use Symfony\Component\HttpKernel\EventListener\DumpListener;
18+
use Symfony\Component\HttpKernel\KernelEvents;
19+
use Symfony\Component\VarDumper\VarDumper;
20+
21+
/**
22+
* DumpListenerTest
23+
*
24+
* @author Nicolas Grekas <p@tchwork.com>
25+
*/
26+
class DumpListenerTest extends \PHPUnit_Framework_TestCase
27+
{
28+
public function testSubscribedEvents()
29+
{
30+
$this->assertSame(
31+
array(KernelEvents::REQUEST => array('configure', 1024)),
32+
DumpListener::getSubscribedEvents()
33+
);
34+
}
35+
36+
public function testConfigure()
37+
{
38+
$prevDumper = $this->getDumpHandler();
39+
40+
$container = new ContainerBuilder();
41+
$container->setDefinition('var_dumper.cloner', new Definition('Symfony\Component\HttpKernel\Tests\EventListener\MockCloner'));
42+
$container->setDefinition('mock_dumper', new Definition('Symfony\Component\HttpKernel\Tests\EventListener\MockDumper'));
43+
44+
ob_start();
45+
$exception = null;
46+
$listener = new DumpListener($container, 'mock_dumper');
47+
48+
try {
49+
$listener->configure();
50+
51+
$lazyDumper = $this->getDumpHandler();
52+
VarDumper::dump('foo');
53+
54+
$loadedDumper = $this->getDumpHandler();
55+
VarDumper::dump('bar');
56+
57+
$this->assertSame('+foo-+bar-', ob_get_clean());
58+
59+
$listenerReflector = new \ReflectionClass($listener);
60+
$lazyReflector = new \ReflectionFunction($lazyDumper);
61+
$loadedReflector = new \ReflectionFunction($loadedDumper);
62+
63+
$this->assertSame($listenerReflector->getFilename(), $lazyReflector->getFilename());
64+
$this->assertSame($listenerReflector->getFilename(), $loadedReflector->getFilename());
65+
$this->assertGreaterThan($lazyReflector->getStartLine(), $loadedReflector->getStartLine());
66+
} catch (\Exception $exception) {
67+
}
68+
69+
VarDumper::setHandler($prevDumper);
70+
71+
if (null !== $exception) {
72+
throw $exception;
73+
}
74+
}
75+
76+
private function getDumpHandler()
77+
{
78+
$prevDumper = VarDumper::setHandler('var_dump');
79+
VarDumper::setHandler($prevDumper );
80+
81+
return $prevDumper;
82+
}
83+
}
84+
85+
class MockCloner
86+
{
87+
public function cloneVar($var)
88+
{
89+
return $var.'-';
90+
}
91+
}
92+
93+
class MockDumper
94+
{
95+
public function dump($var)
96+
{
97+
echo '+'.$var;
98+
}
99+
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ protected function castObject($obj, Stub $stub, $isNested)
200200
}
201201

202202
if ($classInfo[1]) {
203-
$a = $this->callCaster(array($obj, '__debugInfo'), $obj, array(), null, $isNested);
203+
$a = $this->callCaster(function ($obj) {return $obj->__debugInfo();}, $obj, array(), null, $isNested);
204204
} else {
205205
$a = (array) $obj;
206206
}

0 commit comments

Comments
 (0)
0