You are here

protected function EdgeExceptionSubscriberTest::setUp in Apigee Edge 8

Overrides UnitTestCase::setUp

File

tests/src/Unit/EventSubscriber/EdgeExceptionSubscriberTest.php, line 104

Class

EdgeExceptionSubscriberTest
Test EdgeExceptionSubscriber.

Namespace

Drupal\Tests\apigee_edge\Unit\EventSubscriber

Code

protected function setUp() {
  parent::setUp();
  $this->exception = new ApiException("API response error message.");
  $this->logger = $this
    ->prophesize(LoggerInterface::class);
  $this->messenger = $this
    ->prophesize(MessengerInterface::class);
  $response = $this
    ->prophesize(Response::class);
  $this->mainContentRenderers = [
    'html' => 'main_content_renderer.html',
  ];
  $htmlRenderer = $this
    ->prophesize(HtmlRenderer::class);
  $htmlRenderer
    ->renderResponse(Argument::cetera())
    ->willReturn($response
    ->reveal());
  $errorPageController = $this
    ->prophesize(ErrorPageController::class);
  $errorPageController
    ->render()
    ->willReturn([]);
  $errorPageController
    ->getPageTitle()
    ->willReturn('');
  $this->classResolver = $this
    ->prophesize(ClassResolverInterface::class);
  $this->classResolver
    ->getInstanceFromDefinition(Argument::is($this->mainContentRenderers['html']))
    ->willReturn($htmlRenderer
    ->reveal());
  $this->classResolver
    ->getInstanceFromDefinition(Argument::is(ErrorPageController::class))
    ->willReturn($errorPageController
    ->reveal());
  $this->routeMatch = $this
    ->prophesize(RouteMatchInterface::class);

  // Drupal 9 / Symfony 4.x and up.
  if (class_exists('\\Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent')) {
    $this->getResponseForExceptionEvent = $this
      ->prophesize('\\Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent');
    $this->getResponseForExceptionEvent
      ->getThrowable()
      ->willReturn($this->exception);
  }
  else {
    $this->getResponseForExceptionEvent = $this
      ->prophesize(GetResponseForExceptionEvent::class);
    $this->getResponseForExceptionEvent
      ->getException()
      ->willReturn($this->exception);
  }
  $this->getResponseForExceptionEvent
    ->getRequest()
    ->willReturn(new Request());
  $this->getResponseForExceptionEvent
    ->setResponse(Argument::any())
    ->willReturn();
}