tests/api/runner.php

Source: tests/api/runner.php · 186 lines, ~883 statements · namespace: (global) · `declare(strict_types=1)`: no


API Test Subprocess Runner

Executes a single API controller action (or routes a request through a fresh ApiRouter) inside an isolated PHP process and reports the resulting HTTP status code, response body, headers, and rate-limit state.

This runner exists because ApiResponse::send() terminates the process (exit) — a controller action cannot be invoked safely in the PHPUnit process itself. Each invocation is a clean, isolated request.

Usage:

php tests/api/runner.php <env-json-path>

The environment JSON supports two execution modes:

1. Direct controller action:
     {
       "controller": "Scriptlog\\Controller\\Api\\PostsApiController",
       "action": "index",
       "params": { "id": "1" }
     }
2. Router dispatch:
     {
       "dispatch": { "method": "GET", "uri": "posts", "query": {} },
       "routes": [ { "method": "get", "pattern": "posts", "handler": "PostsApiController@index" } ]
     }

Both modes accept the following optional keys: \ - “server”: $_SERVER overrides (REQUEST_METHOD, HTTP_ACCEPT, …) \ - “get”/“post”/“files”: superglobal values to install \ - “api_key”: plaintext API key to send as the X-API-Key header \ - “session_user”: associative array passed to ApiAuth::setSessionUser() \ - “session”: $_SESSION values to install before dispatch

Output protocol (STDOUT):

API_RESULT_START

\ <single-line JSON: {“code”:<int>,“headers”:[…],“body”:“…”,“rate”:…}>

Includes

Mode Target Line
require require_once DIR . '/../bootstrap_api.php'; 64

Generated by 'tools/gendoc'.