public function testOnKernelException()
 {
     $response = $this->getMock(Response::class);
     $exception = $this->getNoConstructorMock(NotModifiedException::class);
     $exception->expects($this->once())->method('getResponse')->will($this->returnValue($response));
     $this->event->expects($this->once())->method('getException')->will($this->returnValue($exception));
     $this->event->expects($this->once())->method('setResponse')->with($response);
     $this->listener->onKernelException($this->event);
 }
 /**
  * Set up mocking
  */
 protected function setUp()
 {
     $this->exception = new \Exception("Mary had a little lamb");
     $reflection = new \ReflectionClass($this->exception);
     $codeProperty = $reflection->getProperty('code');
     $this->codeProperty = $codeProperty;
     $this->codeProperty->setAccessible(true);
     $this->event = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent')->disableOriginalConstructor()->setMethods(['getException'])->getMock();
     $this->event->expects($this->any())->method('getException')->willReturn($this->exception);
     /** @var LoggerInterface $logger */
     $logger = $this->getMockForAbstractClass('Psr\\Log\\LoggerInterface');
     $this->exceptionListener = new ExceptionListener($logger);
 }
 /**
  * Test RqlOperatorNotAllowedListener::onKernelException()
  *
  * @return void
  */
 public function testOnKernelException()
 {
     $serializedContent = 'serialized content';
     $response = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock();
     $response->expects($this->once())->method('setStatusCode')->with(Response::HTTP_BAD_REQUEST)->willReturnSelf();
     $response->expects($this->once())->method('setContent')->with($serializedContent)->willReturnSelf();
     $exception = new RqlOperatorNotAllowedException('limit');
     $exception->setResponse($response);
     $this->serializer->expects($this->once())->method('serialize')->with(['message' => $exception->getMessage()], 'json', $this->context)->willReturn($serializedContent);
     $this->event->expects($this->once())->method('getException')->willReturn($exception);
     $this->event->expects($this->once())->method('setResponse');
     $listener = new RqlOperatorNotAllowedListener($this->serializer, $this->context);
     $listener->onKernelException($this->event);
 }
 /**
  * Set up mocking
  */
 protected function setUp()
 {
     $this->event = $this->getMockBuilder(GetResponseForExceptionEvent::class)->disableOriginalConstructor()->setMethods(['getException', 'getRequest'])->getMock();
     $this->exception = new \Exception("Mary had a little lamb");
     $reflection = new \ReflectionClass($this->exception);
     $codeProperty = $reflection->getProperty('code');
     $this->codeProperty = $codeProperty;
     $this->codeProperty->setAccessible(true);
     $attributes = [RequestMeta::ATTRIBUTE_URI => '/foo/bar'];
     $this->request = new Request($query = [], $request = [], $attributes);
     $this->event->expects($this->any())->method('getException')->willReturn($this->exception);
     $this->event->expects($this->any())->method('getRequest')->willReturn($this->request);
     /** @var ErrorResponseFactory $errorResponseFactory */
     $errorResponseFactory = $this->getMockBuilder(ErrorResponseFactory::class)->disableOriginalConstructor()->getMock();
     /** @var LogRefBuilder $logRefBuilder */
     $lofRefBuilderMock = $logRefBuilder = $this->getMockForAbstractClass(LogRefBuilder::class);
     $lofRefBuilderMock->expects($this->any())->method('create')->willReturn((string) rand());
     $this->logger = $this->getMockForAbstractClass(LoggerInterface::class);
     $this->exceptionListener = new ExceptionListener($errorResponseFactory, $logRefBuilder, $this->logger);
 }