Problem/Motivation

As pointed out in #3627430: [META] Adopt the Test Pyramid approach, we currently don't have clear guidelines on how to write code that's easy to unit test. A few ideas were demoed in this session but nothing has been officially agreed upon.

Proposed resolution

Provide best practices to:

  • Introduce interfaces wherever a test double would be useful and appropriate.
    • Do not replace concrete classes with test doubles.
  • Break code down into meaningful and cohesive units adhering to the SRP principle
  • Isolate logic that reaches outside the PHP process (DB queries, HTTP requests) or interacts with third-party libraries behind thin adapter layers, such as the Repository pattern.
  • Ban entity terminology from modules as much as possible, rely on domain-specific terminology instead.

Details TBD.

Remaining tasks

  • Discuss, validate, and finalize the proposed solution
  • Define the desired deliverable
  • Produce the deliverable
  • Review it

Introduced terminology

TBD

API changes

None foreseen

Data model changes

None foreseen

Release notes snippet

TBD

Comments

plach created an issue. See original summary.

plach’s picture

Assigned: plach » Unassigned
Status: Active » Needs review
Related issues: +#3627449: Add example module to promote best practices

A first attempt at providing a deliverable – an example/template core module, hidden from the UI – was posted at #3627449: Add example module to promote best practices via https://git.drupalcode.org/project/drupal/-/merge_requests/17315.