Файл: gapps/vendor/symfony/http-kernel/Tests/EventListener/ProfilerListenerTest.php
Строк: 171
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SymfonyComponentHttpKernelTestsEventListener;
use SymfonyComponentHttpFoundationRequestStack;
use SymfonyComponentHttpKernelEventListenerProfilerListener;
use SymfonyComponentHttpKernelEventFilterResponseEvent;
use SymfonyComponentHttpKernelEventGetResponseForExceptionEvent;
use SymfonyComponentHttpKernelEventPostResponseEvent;
use SymfonyComponentHttpKernelExceptionHttpException;
use SymfonyComponentHttpKernelKernel;
class ProfilerListenerTest extends PHPUnit_Framework_TestCase
{
/**
* Test a master and sub request with an exception and `onlyException` profiler option enabled.
*/
public function testKernelTerminate()
{
$profile = $this->getMockBuilder('SymfonyComponentHttpKernelProfilerProfile')
->disableOriginalConstructor()
->getMock();
$profiler = $this->getMockBuilder('SymfonyComponentHttpKernelProfilerProfiler')
->disableOriginalConstructor()
->getMock();
$profiler->expects($this->once())
->method('collect')
->will($this->returnValue($profile));
$kernel = $this->getMock('SymfonyComponentHttpKernelHttpKernelInterface');
$masterRequest = $this->getMockBuilder('SymfonyComponentHttpFoundationRequest')
->disableOriginalConstructor()
->getMock();
$subRequest = $this->getMockBuilder('SymfonyComponentHttpFoundationRequest')
->disableOriginalConstructor()
->getMock();
$response = $this->getMockBuilder('SymfonyComponentHttpFoundationResponse')
->disableOriginalConstructor()
->getMock();
$requestStack = new RequestStack();
$requestStack->push($masterRequest);
$onlyException = true;
$listener = new ProfilerListener($profiler, $requestStack, null, $onlyException);
// master request
$listener->onKernelResponse(new FilterResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response));
// sub request
$listener->onKernelException(new GetResponseForExceptionEvent($kernel, $subRequest, Kernel::SUB_REQUEST, new HttpException(404)));
$listener->onKernelResponse(new FilterResponseEvent($kernel, $subRequest, Kernel::SUB_REQUEST, $response));
$listener->onKernelTerminate(new PostResponseEvent($kernel, $masterRequest, $response));
}
}