You are here

class ProfilerListenerTest in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-kernel/Tests/EventListener/ProfilerListenerTest.php \Symfony\Component\HttpKernel\Tests\EventListener\ProfilerListenerTest

Hierarchy

  • class \Symfony\Component\HttpKernel\Tests\EventListener\ProfilerListenerTest extends \Symfony\Component\HttpKernel\Tests\EventListener\PHPUnit_Framework_TestCase

Expanded class hierarchy of ProfilerListenerTest

File

vendor/symfony/http-kernel/Tests/EventListener/ProfilerListenerTest.php, line 23

Namespace

Symfony\Component\HttpKernel\Tests\EventListener
View source
class ProfilerListenerTest extends \PHPUnit_Framework_TestCase {

  /**
   * Test to ensure BC without RequestStack.
   *
   * @group legacy
   */
  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));
  }

  /**
   * Test a master and sub request with an exception and `onlyException` profiler option enabled.
   */
  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);

    // 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));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ProfilerListenerTest::testKernelTerminate public function Test a master and sub request with an exception and `onlyException` profiler option enabled.
ProfilerListenerTest::testLegacyEventsWithoutRequestStack public function Test to ensure BC without RequestStack.