function SecurityAdvisoriesFetcherTest::setTestFeedResponses

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php \Drupal\Tests\system\Kernel\SecurityAdvisories\SecurityAdvisoriesFetcherTest::setTestFeedResponses()
  2. 11.x core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php \Drupal\Tests\system\Kernel\SecurityAdvisories\SecurityAdvisoriesFetcherTest::setTestFeedResponses()

Sets test feed responses.

Parameters

\GuzzleHttp\Psr7\Response[] $responses: The responses for the http_client service to return.

4 calls to SecurityAdvisoriesFetcherTest::setTestFeedResponses()
SecurityAdvisoriesFetcherTest::setFeedItems in core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php
Sets the feed items to be returned for the test.
SecurityAdvisoriesFetcherTest::testHttpFallback in core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php
@covers ::doRequest[[api-linebreak]] @covers ::getSecurityAdvisories[[api-linebreak]]
SecurityAdvisoriesFetcherTest::testInvalidJsonResponse in core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php
Tests that invalid JSON feed responses are not stored.
SecurityAdvisoriesFetcherTest::testNoHttpFallback in core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php
@covers ::doRequest[[api-linebreak]] @covers ::getSecurityAdvisories[[api-linebreak]]

File

core/modules/system/tests/src/Kernel/SecurityAdvisories/SecurityAdvisoriesFetcherTest.php, line 716

Class

SecurityAdvisoriesFetcherTest
@coversDefaultClass \Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher[[api-linebreak]]

Namespace

Drupal\Tests\system\Kernel\SecurityAdvisories

Code

protected function setTestFeedResponses(array $responses) : void {
  // Create a mock and queue responses.
  $mock = new MockHandler($responses);
  $handler_stack = HandlerStack::create($mock);
  $history = Middleware::history($this->history);
  $handler_stack->push($history);
  // Rebuild the container because the 'system.sa_fetcher' service and other
  // services may already have an instantiated instance of the 'http_client'
  // service without these changes.
  $this->container
    ->get('kernel')
    ->rebuildContainer();
  $this->container = $this->container
    ->get('kernel')
    ->getContainer();
  $this->container
    ->get('logger.factory')
    ->addLogger($this);
  $this->container
    ->set('http_client', new Client([
    'handler' => $handler_stack,
  ]));
  $this->container
    ->setAlias(ClientInterface::class, 'http_client');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.