Add PHPUnit tests for MatrixClient and MatrixEvent
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3605360. --> Reported by: [freelock](https://www.drupal.org/user/313537) >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p> The module has no automated tests. The new MatrixClient API method implementations, the MatrixEvent token handling, and the inbound event deduplication logic are all<br> untested. This makes it difficult to verify correctness, prevent regressions, or accept contributions with confidence.</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p> Run <code>phpunit web/modules/contrib/matrix_api</code> &mdash; no tests found.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p> Add PHPUnit unit tests covering the core classes:</p> <ul> <li><code>tests/src/Unit/MatrixClientTest.php</code> &mdash; tests for <code>MatrixClient</code>: <ul> <li><code>sendMessage()</code> returns the event ID string</li> <li><code>sendThreadReply()</code> sends correct <code>m.thread</code> relation structure</li> <li><code>redactEvent()</code> calls the correct endpoint</li> <li><code>getState()</code> returns <code>[]</code> on 404 and <code>false</code> on other HTTP errors</li> <li><code>setState()</code> returns <code>''</code> and logs a warning on 403</li> </ul> </li> <li><code>tests/src/Unit/MatrixApiTokenTest.php</code> &mdash; tests for <code>MatrixEvent</code> token replacement: verifies that all ECA tokens<br> (<code>[matrix_event:body]</code>, <code>[matrix_event:sender]</code>, <code>[matrix_event:room-id]</code>, <code>[matrix_event:event-id]</code>,<br> <code>[matrix_event:thread-root]</code>) resolve correctly from a <code>MatrixEvent</code> object.</li> <li><code>tests/src/Event/</code> &mdash; tests for <code>MatrixEvent</code> typed accessors.</li> </ul> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <ul> <li>[x] Unit tests for MatrixClient and MatrixEvent implemented.</li> <li>[ ] Kernel/functional tests for the full inbound flow (CronPoller &rarr; event dispatch &rarr; subscriber) are a follow-up task.</li> <li>[ ] Tests for ECA action plugins are a follow-up task.</li> </ul> <h3 id="summary-ui-changes">User interface changes</h3> <p> None.</p> <h3 id="summary-api-changes">API changes</h3> <p> None.</p> <h3 id="summary-data-model-changes">Data model changes</h3> <p> None.</p>
issue