Skip to content

Commit 64f3cb1

Browse files
committed
[HttpKernel] Fix profiler event-listener usage outside request stack context
1 parent cd04f7b commit 64f3cb1

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

EventListener/ProfilerListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ public function onKernelTerminate(PostResponseEvent $event)
125125
{
126126
// attach children to parents
127127
foreach ($this->profiles as $request) {
128-
if ($parentRequest = $this->parents[$request]) {
128+
// isset call should be removed when requestStack is required
129+
if (isset($this->parents[$request]) && null !== $parentRequest = $this->parents[$request]) {
129130
$this->profiles[$parentRequest]->addChild($this->profiles[$request]);
130131
}
131132
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\EventListener;
13+
14+
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
15+
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
16+
use Symfony\Component\HttpKernel\EventListener\ProfilerListener;
17+
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
18+
use Symfony\Component\HttpKernel\Kernel;
19+
20+
class ProfilerListenerTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* Test to ensure BC without RequestStack
24+
*
25+
* @deprecated Deprecated since version 2.4, to be removed in 3.0.
26+
*/
27+
public function testEventsWithoutRequestStack()
28+
{
29+
$profile = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile')
30+
->disableOriginalConstructor()
31+
->getMock();
32+
33+
$profiler = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
34+
->disableOriginalConstructor()
35+
->getMock();
36+
$profiler->expects($this->once())
37+
->method('collect')
38+
->will($this->returnValue($profile));
39+
40+
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
41+
42+
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
43+
->disableOriginalConstructor()
44+
->getMock();
45+
46+
$response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response')
47+
->disableOriginalConstructor()
48+
->getMock();
49+
50+
$listener = new ProfilerListener($profiler);
51+
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, Kernel::MASTER_REQUEST));
52+
$listener->onKernelResponse(new FilterResponseEvent($kernel, $request, Kernel::MASTER_REQUEST, $response));
53+
$listener->onKernelTerminate(new PostResponseEvent($kernel, $request, $response));
54+
}
55+
}

0 commit comments

Comments
 (0)