|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
13 | 13 |
|
14 |
| -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; |
15 |
| -use Symfony\Component\HttpKernel\Event\PostResponseEvent; |
16 | 14 | use Symfony\Component\HttpKernel\EventListener\ProfilerListener;
|
| 15 | +use Symfony\Component\HttpKernel\Event\FilterResponseEvent; |
17 | 16 | use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
| 17 | +use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; |
| 18 | +use Symfony\Component\HttpKernel\Event\PostResponseEvent; |
| 19 | +use Symfony\Component\HttpKernel\Exception\HttpException; |
18 | 20 | use Symfony\Component\HttpKernel\Kernel;
|
19 | 21 |
|
20 | 22 | class ProfilerListenerTest extends \PHPUnit_Framework_TestCase
|
@@ -52,4 +54,50 @@ public function testEventsWithoutRequestStack()
|
52 | 54 | $listener->onKernelResponse(new FilterResponseEvent($kernel, $request, Kernel::MASTER_REQUEST, $response));
|
53 | 55 | $listener->onKernelTerminate(new PostResponseEvent($kernel, $request, $response));
|
54 | 56 | }
|
| 57 | + |
| 58 | + /** |
| 59 | + * Test a master and sub request with an exception and `onlyException` profiler option enabled. |
| 60 | + */ |
| 61 | + public function testKernelTerminate() |
| 62 | + { |
| 63 | + $profile = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile') |
| 64 | + ->disableOriginalConstructor() |
| 65 | + ->getMock(); |
| 66 | + |
| 67 | + $profiler = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') |
| 68 | + ->disableOriginalConstructor() |
| 69 | + ->getMock(); |
| 70 | + |
| 71 | + $profiler->expects($this->once()) |
| 72 | + ->method('collect') |
| 73 | + ->will($this->returnValue($profile)); |
| 74 | + |
| 75 | + $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); |
| 76 | + |
| 77 | + $masterRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') |
| 78 | + ->disableOriginalConstructor() |
| 79 | + ->getMock(); |
| 80 | + |
| 81 | + $subRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') |
| 82 | + ->disableOriginalConstructor() |
| 83 | + ->getMock(); |
| 84 | + |
| 85 | + $response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response') |
| 86 | + ->disableOriginalConstructor() |
| 87 | + ->getMock(); |
| 88 | + |
| 89 | + $onlyException = true; |
| 90 | + $listener = new ProfilerListener($profiler, null, $onlyException); |
| 91 | + |
| 92 | + // master request |
| 93 | + $listener->onKernelRequest(new GetResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST)); |
| 94 | + $listener->onKernelResponse(new FilterResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response)); |
| 95 | + |
| 96 | + // sub request |
| 97 | + $listener->onKernelRequest(new GetResponseEvent($kernel, $subRequest, Kernel::SUB_REQUEST)); |
| 98 | + $listener->onKernelException(new GetResponseForExceptionEvent($kernel, $subRequest, Kernel::SUB_REQUEST, new HttpException(404))); |
| 99 | + $listener->onKernelResponse(new FilterResponseEvent($kernel, $subRequest, Kernel::SUB_REQUEST, $response)); |
| 100 | + |
| 101 | + $listener->onKernelTerminate(new PostResponseEvent($kernel, $masterRequest, $response)); |
| 102 | + } |
55 | 103 | }
|
0 commit comments