A small CLI tool that drives the analytics-php SDK in end-to-end tests.
- PHP 7.4 or 8.x
No composer install is required — main.php uses a simple spl_autoload_register
to load the SDK classes directly from ../lib/.
php main.php --input '<json>'{
"writeKey": "YOUR_WRITE_KEY",
"apiHost": "https://api.segment.io",
"sequences": [
{
"delayMs": 0,
"events": [
{
"type": "track",
"event": "Test Event",
"userId": "user-1",
"properties": { "plan": "pro" }
},
{
"type": "identify",
"userId": "user-1",
"traits": { "email": "user@example.com" }
},
{
"type": "page",
"userId": "user-1",
"name": "Home",
"category": "Nav"
},
{
"type": "screen",
"userId": "user-1",
"name": "Main Screen"
},
{
"type": "alias",
"userId": "new-id",
"previousId": "old-id"
},
{
"type": "group",
"userId": "user-1",
"groupId": "group-1",
"traits": { "name": "Acme Corp" }
}
]
}
],
"config": {
"flushAt": 15,
"timeout": 10
}
}| Field | Description |
|---|---|
writeKey |
Segment write key |
apiHost |
Full URL of the Segment API host (scheme is stripped; PHP SDK always uses HTTPS) |
sequences[].delayMs |
Milliseconds to wait before processing this sequence |
sequences[].events |
List of events to send |
config.flushAt |
Number of events to accumulate before auto-flushing (maps to flush_at) |
config.timeout |
cURL timeout in seconds (maps to curl_timeout) |
track, identify, page, screen, alias, group
On success:
{"success": true, "sentBatches": 1}On failure:
{"success": false, "sentBatches": 0, "error": "HTTP 400: Bad Request"}Exit code is 0 on success and 1 on failure. Debug logs are written to stderr.
./run-e2e.shBy default this expects the sdk-e2e-tests repo to be checked out alongside
the analytics-php repo:
parent/
analytics-php/
e2e-cli/ ← you are here
sdk-e2e-tests/
Override the location with an environment variable:
E2E_TESTS_DIR=/path/to/sdk-e2e-tests ./run-e2e.shAny additional arguments are forwarded to sdk-e2e-tests/scripts/run-tests.sh.
main.phpparses--inputJSON from$argv.- A
Segment\Clientis created withlib_curlconsumer and the provided options. - Each sequence is processed in order;
delayMsintroduces an optional pause. - After all events are enqueued,
flush()is called to send them synchronously. - Errors captured by the
error_handlercallback or afalsereturn fromflush()cause the script to exit with code1.