Manual mocking responses for the http_client service

Created on 30 July 2024, 4 months ago
Updated 22 November 2024, 3 days ago

Problem/Motivation

Would be good to implement an API for manual mocking of the responses for the http_client service, maybe even with a custom callback function.

Feature request
Status

Active

Version

1.5

Component

Code

Created by

🇦🇲Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @murz
  • Pipeline finished with Skipped
    3 days ago
    #346672
    • murz committed 4d5893de on 1.5.x
      Issue #3464623 by murz: Manual mocking responses for the http_client...
  • 🇦🇲Armenia murz Yerevan, Armenia

    Implemented two new functions in the HttpClientFactoryStub for mocking responses as stack and dynamically:

      /**
       * Adds a custom response to the stack.
       *
       * @param \Psr\Http\Message\ResponseInterface $response
       *   A response to add.
       */
      public function stubAddCustomResponseToStack(ResponseInterface $response);
    
      /**
       * Sets a custom handler for the HTTP client.
       *
       * @param callable|null $handler
       *   A custom handler or null to unset the handler.
       */
      public function stubSetCustomHandler(?callable $handler);
    

    Together with this, I added the "stub" prefix to all stub functions, to indicate that they are available only in the stub of the service.

  • 🇦🇲Armenia murz Yerevan, Armenia
Production build 0.71.5 2024