history example

/** * Mocks the HTTP client. * * @param \GuzzleHttp\Psr7\Response ... * Variable number of Response objects that the mocked client should return. */
  protected function mockClient(Response ...$responses) {
    // Create a mock and queue responses.     $mock_handler = new MockHandler($responses);
    $handler_stack = HandlerStack::create($mock_handler);
    $history = Middleware::history($this->history);
    $handler_stack->push($history);
    $this->mockHttpClient = new Client(['handler' => $handler_stack]);
  }

  /** * @covers ::doRequest * @covers ::fetchProjectData */
  public function testUpdateFetcherNoFallback() {
    // First, try without the HTTP fallback setting, and HTTPS mocked to fail.     $settings = new Settings([]);
    
class GuzzleHistoryCollector
{
    /** * @var array<int, mixed> */
    private static array $historyContainer;

    public function getHistoryMiddleWare(): callable /* @phpstan-ignore-line callable can not be typed as it is recursive */
    {
        self::$historyContainer = [];

        return Middleware::history(self::$historyContainer);
    }

    /** * @return array<int, mixed> */
    public function getHistory(): array
    {
        return self::$historyContainer;
    }

    public function resetHistory(): void
    {
/** * Sets test feed responses. * * @param \GuzzleHttp\Psr7\Response[] $responses * The responses for the http_client service to return. */
  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]));
  }

}
/** * Sets test feed responses. * * @param \GuzzleHttp\Psr7\Response[] $responses * The responses for the http_client service to return. */
  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');
  }

  
Home | Imprint | This part of the site doesn't use cookies.