Unit Test server and interface - Liturgical-Calendar/LiturgicalCalendarAPI GitHub Wiki

Frontend

The Unit Test frontend can be found at https://litcal-tests.johnromanodorazio.com. This interface has its own repository: Liturgical-Calendar/UnitTestInterface.

The frontend discovers available tests through the API's /tests endpoint, which returns the liturgical event test definitions in JSON format. It communicates with the WebSocket backend to execute tests, gather results, and update the UI accordingly.

Discovery endpoint

The /tests endpoint reads all test definitions from the jsondata/tests/ folder in the LiturgicalCalendarAPI repository and serves them as a JSON response. This endpoint is handled by the TestsHandler class (src/Handlers/TestsHandler.php). It supports GET (list/read), POST (create), PUT/PATCH (update), and DELETE operations on test definitions.

Backend

The Unit Test backend is a WebSocket server that executes tests on demand.

WebSocket server

The WebSocket server entry point is public/LitCalTestServer.php, which uses the Ratchet WebSocket framework (via the plesk/ratchetphp package) along with React PHP for asynchronous operations.

The server can be started and stopped using Composer scripts:

composer ws:start    # Start the WebSocket server (saves PID to ws-server.pid)
composer ws:stop     # Stop the WebSocket server (graceful SIGTERM, then SIGKILL)

Health class

The WebSocket server depends on the Health class (src/Health.php) in the LiturgicalCalendar\Api namespace. This class implements Ratchet's MessageComponentInterface and serves as the orchestrator for test execution:

  • Manages connected WebSocket clients
  • Receives test execution requests from the frontend
  • Runs validation actions including JSON schema validation, calendar validation, and source data checks
  • Formulates responses with test results in JSON format and sends them back to the frontend

The Health class has backend knowledge of the available tests (via TestsMap in src/Test/TestsMap.php) and uses LitTestRunner (src/Test/LitTestRunner.php) to execute individual test definitions against the API's calendar output.


Testing: ← [Liturgical event tests]] ](/Liturgical-Calendar/LiturgicalCalendarAPI/wiki/[[Home)