As part of #2828197, it is recommended to write object-oriented so unit tests are easier or even possible. Drupal 7 has so much dependent code in functions without any OOP concepts that it is far easier to bootstrap Drupal and write functional tests.

However, this module can be converted to use OOP concepts. The first step is defining some basic objects to create classes for. When I think about inviting a user, there are three parts:

  • The invite
  • The invite service
  • The mail service

The invite holds the data: user IDs, email addresses, the status of the invite, etc.

The invite service takes an invite object and grants, rejects, and makes calls to send emails. To properly create this class, a mail service and user service need to be passed in. The user service would be a completely fake object that gathers imaginary roles and users and the information associated to those systems.

The mail service sends emails when the invite service asks it to do so.

The goal of this issue will be to start from scratch on the new 2.x branch and instantiate objects into the necessary Drupal hooks. Interfaces need to be created so fake tests objects can be created alongside the real classes.

Comments

afinnarn created an issue. See original summary.

afinnarn’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev