You are here

public function ResponseCspSubscriberTest::setUp in Content-Security-Policy 8

Overrides UnitTestCase::setUp

File

tests/src/Unit/EventSubscriber/ResponseCspSubscriberTest.php, line 62

Class

ResponseCspSubscriberTest
@coversDefaultClass \Drupal\csp\EventSubscriber\ResponseCspSubscriber @group csp

Namespace

Drupal\Tests\csp\Unit\EventSubscriber

Code

public function setUp() : void {
  parent::setUp();
  $this->response = $this
    ->getMockBuilder(HtmlResponse::class)
    ->disableOriginalConstructor()
    ->getMock();
  $this->response->headers = $this
    ->getMockBuilder(ResponseHeaderBag::class)
    ->disableOriginalConstructor()
    ->getMock();
  $responseCacheableMetadata = $this
    ->getMockBuilder(CacheableMetadata::class)
    ->getMock();
  $this->response
    ->method('getCacheableMetadata')
    ->willReturn($responseCacheableMetadata);

  /** @var \Symfony\Component\HttpKernel\Event\FilterResponseEvent|\PHPUnit_Framework_MockObject_MockObject $event */
  $this->event = $this
    ->getMockBuilder(FilterResponseEvent::class)
    ->disableOriginalConstructor()
    ->getMock();
  $this->event
    ->expects($this
    ->any())
    ->method('isMasterRequest')
    ->willReturn(TRUE);
  $this->event
    ->expects($this
    ->any())
    ->method('getResponse')
    ->willReturn($this->response);
  $this->libraryPolicy = $this
    ->getMockBuilder(LibraryPolicyBuilder::class)
    ->disableOriginalConstructor()
    ->getMock();
  $this->reportingHandlerPluginManager = $this
    ->getMockBuilder(ReportingHandlerPluginManager::class)
    ->disableOriginalConstructor()
    ->getMock();
  $this->eventDispatcher = $this
    ->getMockBuilder(EventDispatcher::class)
    ->disableOriginalConstructor()
    ->getMock();
}