Problem/Motivation

Yesterday I've faced a problem what I can easily solve with Crema.

I have a buggy feature which is provided by two packages. One of them is a Drupal module, the other one is a Composer package. Basically, the latter is a middleware-like project that communicates with a remote server; the Drupal module acts like a client that sends requests and parses responses by using the objects from the Composer package.

The logic of the the Drupal module is quite complex. I decided to write a detailed test to debug all the endpoints what the module defines. But unfortunately the "services" in the middleware are written in a way that does not allows neither using HTTP middlewares or service decorators - because constructors look like this:

public function __construct() {
  $this->httpService = new CurlHttpService();
}

This CurlHttpService is a handcrafted HTTP client that uses PHP's libcurl to perform HTTP get/post etc requests. If I could replace this with a Guzzle Client created from Drupal 's service container, I could easily write HTTP Middleware, with which I could then mock the responses of the remote server in my PHPUnit kernel tests (and I also would notice where else the Drupal module sends requests to).

Long story short: Crema must be able to replace any class, not just the ones under Drupal\* namespace.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

huzooka created an issue. See original summary.

huzooka’s picture

Status: Active » Needs review
StatusFileSize
new11.97 KB
huzooka’s picture

It would be nice to confirm with test that this works, but since this module is still in alpha, and because it is still insance, I'll go ahead and merge then release this.

  • huzooka committed 4849afc9 on 1.0.x
    Issue #3345558 by huzooka: Allow overriding non-drupal namespaces
    
huzooka’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.