Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

http_request_mock

13 sites Security covered
View on drupal.org

Inspired by Danny Sipos's (Upchuk) article: https://www.webomelette.com/simple-guzzle-api-mocking-functional-testing...

Description

When running tests, you don't want to perform external HTTP requests while you still want to test code that consumes such webservices. This module intercepts the requests made by the Drupal http_client service and allows a plugin to respond with a mocked response.

Usage

In order to mock a webservice, you'll need to create a service mock plugin. Such a plugin implements the ServiceMockPluginInterface. The plugin manager will pickup the first plugin that matches the HTTP request and will call the plugin's ::getResponse() method. Note that several plugins may qualify for the same request, but you can specify a weight in plugin's attribute so that such plugins are prioritized.

Implement one or more plugins for each webservice that you want to mock. In your tests, enable this module, and the modules that are shipping such plugins. This module ships a testing plugin that intercepts all outgoing HTTP requests made to example.com.

In some cases, tests may narrow the list of plugins to a limited set. Such tests should pass an array of plugin IDs to the http_request_mock.allowed_plugins state variable. Leaving this variable empty or not set, will allow all plugins to apply to the following outgoing HTTP requests.

Activity

Total releases
1
First release
Feb 2025
Latest release
1 year ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.2.0 Stable Feb 7, 2025