ProfilerListenerTest.php in Zircon Profile 8
File
vendor/symfony/http-kernel/Tests/EventListener/ProfilerListenerTest.php
View source
<?php
namespace Symfony\Component\HttpKernel\Tests\EventListener;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\EventListener\ProfilerListener;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Kernel;
class ProfilerListenerTest extends \PHPUnit_Framework_TestCase {
public function testLegacyEventsWithoutRequestStack() {
$profile = $this
->getMockBuilder('Symfony\\Component\\HttpKernel\\Profiler\\Profile')
->disableOriginalConstructor()
->getMock();
$profiler = $this
->getMockBuilder('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')
->disableOriginalConstructor()
->getMock();
$profiler
->expects($this
->once())
->method('collect')
->will($this
->returnValue($profile));
$kernel = $this
->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$request = $this
->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')
->disableOriginalConstructor()
->getMock();
$response = $this
->getMockBuilder('Symfony\\Component\\HttpFoundation\\Response')
->disableOriginalConstructor()
->getMock();
$listener = new ProfilerListener($profiler);
$listener
->onKernelRequest(new GetResponseEvent($kernel, $request, Kernel::MASTER_REQUEST));
$listener
->onKernelResponse(new FilterResponseEvent($kernel, $request, Kernel::MASTER_REQUEST, $response));
$listener
->onKernelTerminate(new PostResponseEvent($kernel, $request, $response));
}
public function testKernelTerminate() {
$profile = $this
->getMockBuilder('Symfony\\Component\\HttpKernel\\Profiler\\Profile')
->disableOriginalConstructor()
->getMock();
$profiler = $this
->getMockBuilder('Symfony\\Component\\HttpKernel\\Profiler\\Profiler')
->disableOriginalConstructor()
->getMock();
$profiler
->expects($this
->once())
->method('collect')
->will($this
->returnValue($profile));
$kernel = $this
->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$masterRequest = $this
->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')
->disableOriginalConstructor()
->getMock();
$subRequest = $this
->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')
->disableOriginalConstructor()
->getMock();
$response = $this
->getMockBuilder('Symfony\\Component\\HttpFoundation\\Response')
->disableOriginalConstructor()
->getMock();
$requestStack = new RequestStack();
$requestStack
->push($masterRequest);
$onlyException = true;
$listener = new ProfilerListener($profiler, null, $onlyException, false, $requestStack);
$listener
->onKernelResponse(new FilterResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response));
$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));
}
}