function AnnounceTestBase::setTestFeedResponses

Same name in other branches
  1. 10 core/modules/announcements_feed/tests/src/Kernel/AnnounceTestBase.php \Drupal\Tests\announcements_feed\Kernel\AnnounceTestBase::setTestFeedResponses()

Sets test feed responses.

Parameters

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

4 calls to AnnounceTestBase::setTestFeedResponses()
AnnounceFetcherTest::setFeedItems in core/modules/announcements_feed/tests/src/Kernel/AnnounceFetcherTest.php
Sets the feed items to be returned for the test.
AnnounceFetcherUserTest::setFeedItems in core/modules/announcements_feed/tests/src/Kernel/AnnounceFetcherUserTest.php
Sets the feed items to be returned for the test.
AnnounceRendererTest::testRendererException in core/modules/announcements_feed/tests/src/Kernel/AnnounceRendererTest.php
Tests rendered valid when something goes wrong.
AnnounceTestBase::setFeedItems in core/modules/announcements_feed/tests/src/Kernel/AnnounceTestBase.php
Sets the feed items to be returned for the test.

File

core/modules/announcements_feed/tests/src/Kernel/AnnounceTestBase.php, line 70

Class

AnnounceTestBase
Base class for Announce Kernel tests.

Namespace

Drupal\Tests\announcements_feed\Kernel

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
        ->set('http_client', new Client([
        'handler' => $handler_stack,
    ]));
}

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