751aee8695f37d23c0a11eacaa6a708e13b4d396
[yaffs-website] / vendor / symfony / http-kernel / Tests / EventListener / ProfilerListenerTest.php
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 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;
22
23 class ProfilerListenerTest extends TestCase
24 {
25     /**
26      * Test a master and sub request with an exception and `onlyException` profiler option enabled.
27      */
28     public function testKernelTerminate()
29     {
30         $profile = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile')
31             ->disableOriginalConstructor()
32             ->getMock();
33
34         $profiler = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
35             ->disableOriginalConstructor()
36             ->getMock();
37
38         $profiler->expects($this->once())
39             ->method('collect')
40             ->will($this->returnValue($profile));
41
42         $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
43
44         $masterRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
45             ->disableOriginalConstructor()
46             ->getMock();
47
48         $subRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
49             ->disableOriginalConstructor()
50             ->getMock();
51
52         $response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response')
53             ->disableOriginalConstructor()
54             ->getMock();
55
56         $requestStack = new RequestStack();
57         $requestStack->push($masterRequest);
58
59         $onlyException = true;
60         $listener = new ProfilerListener($profiler, $requestStack, null, $onlyException);
61
62         // master request
63         $listener->onKernelResponse(new FilterResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response));
64
65         // sub request
66         $listener->onKernelException(new GetResponseForExceptionEvent($kernel, $subRequest, Kernel::SUB_REQUEST, new HttpException(404)));
67         $listener->onKernelResponse(new FilterResponseEvent($kernel, $subRequest, Kernel::SUB_REQUEST, $response));
68
69         $listener->onKernelTerminate(new PostResponseEvent($kernel, $masterRequest, $response));
70     }
71 }