4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\EventListener;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\RequestStack;
16 use Symfony\Component\HttpKernel\EventListener\ProfilerListener;
17 use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
18 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
19 use Symfony\Component\HttpKernel\Event\PostResponseEvent;
20 use Symfony\Component\HttpKernel\Exception\HttpException;
21 use Symfony\Component\HttpKernel\Kernel;
23 class ProfilerListenerTest extends TestCase
26 * Test a master and sub request with an exception and `onlyException` profiler option enabled.
28 public function testKernelTerminate()
30 $profile = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile')
31 ->disableOriginalConstructor()
34 $profiler = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
35 ->disableOriginalConstructor()
38 $profiler->expects($this->once())
40 ->will($this->returnValue($profile));
42 $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
44 $masterRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
45 ->disableOriginalConstructor()
48 $subRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
49 ->disableOriginalConstructor()
52 $response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response')
53 ->disableOriginalConstructor()
56 $requestStack = new RequestStack();
57 $requestStack->push($masterRequest);
59 $onlyException = true;
60 $listener = new ProfilerListener($profiler, $requestStack, null, $onlyException);
63 $listener->onKernelResponse(new FilterResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response));
66 $listener->onKernelException(new GetResponseForExceptionEvent($kernel, $subRequest, Kernel::SUB_REQUEST, new HttpException(404)));
67 $listener->onKernelResponse(new FilterResponseEvent($kernel, $subRequest, Kernel::SUB_REQUEST, $response));
69 $listener->onKernelTerminate(new PostResponseEvent($kernel, $masterRequest, $response));