Allow overriding non-drupal namespaces

Created on 2 March 2023, over 1 year ago
Updated 3 March 2023, over 1 year ago

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

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡­πŸ‡ΊHungary huzooka Hungary πŸ‡­πŸ‡ΊπŸ‡ͺπŸ‡Ί

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

Comments & Activities

Production build 0.69.0 2024