Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

HTTP Request Mock

61 sites Security covered
View on drupal.org

This module intercepts outgoing HTTP requests made by Drupal's http_client service during testing. It allows custom plugins to provide mocked responses for these requests, preventing actual external calls and enabling more reliable functional testing.

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
Releases (12 mo)
0 ▼ from 1
Maintenance
Dormant

Releases

Version Type Release date
1.2.0 Stable Feb 7, 2025