A common usecase is mocking external systems; which are often called via drupal_http_request().

Instead of prividing an example on how to mock those (with mockable_crm_example), it might be relevant to split mockable_crm_example into two modules: mockable_crm_example and a new mockable_http_request module, which does the heavy lifting.

drupal_http_request()'s documentation shows how the function can be overrided without requiring modules to change their code (see also #2100519: Don't require modules to change their code).

  $override_function = variable_get('drupal_http_request_function', FALSE);
  if (!empty($override_function) && function_exists($override_function)) {
    return $override_function($url, $options);
  }

Comments

alberto56’s picture

Status: Active » Needs work

I created a branch 2100523 for this.

alberto56’s picture

Now on the main 7.x-1.x-unstable branch, I deleted the branch 2100523