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. 10 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 @covers ::getSecurityAdvisories
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 @covers ::getSecurityAdvisories

File

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

Class

SecurityAdvisoriesFetcherTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21system%21src%21SecurityAdvisories%21SecurityAdvisoriesFetcher.php/class/SecurityAdvisoriesFetcher/11.x" title="Defines a service to get security advisories." class="local">\Drupal\system\SecurityAdvisories\SecurityAdvisoriesFetcher</a>

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.