Problem/Motivation

The module has no automated tests. The new MatrixClient API method implementations, the MatrixEvent token handling, and the inbound event deduplication logic are all
untested. This makes it difficult to verify correctness, prevent regressions, or accept contributions with confidence.

Steps to reproduce

Run phpunit web/modules/contrib/matrix_api — no tests found.

Proposed resolution

Add PHPUnit unit tests covering the core classes:

  • tests/src/Unit/MatrixClientTest.php — tests for MatrixClient:
    • sendMessage() returns the event ID string
    • sendThreadReply() sends correct m.thread relation structure
    • redactEvent() calls the correct endpoint
    • getState() returns [] on 404 and false on other HTTP errors
    • setState() returns '' and logs a warning on 403
  • tests/src/Unit/MatrixApiTokenTest.php — tests for MatrixEvent token replacement: verifies that all ECA tokens
    ([matrix_event:body], [matrix_event:sender], [matrix_event:room-id], [matrix_event:event-id],
    [matrix_event:thread-root]) resolve correctly from a MatrixEvent object.
  • tests/src/Event/ — tests for MatrixEvent typed accessors.

Remaining tasks

  • [x] Unit tests for MatrixClient and MatrixEvent implemented.
  • [ ] Kernel/functional tests for the full inbound flow (CronPoller → event dispatch → subscriber) are a follow-up task.
  • [ ] Tests for ECA action plugins are a follow-up task.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

freelock created an issue. See original summary.

  • freelock committed ce747a4a on 3.0.x
    test: #3605360 Add PHPUnit tests for MatrixClient and MatrixEvent
    
    By:...
freelock’s picture

Status: Active » Fixed

Tests added.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.