TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/elevenlabs/llms.txt
Use this file to discover all available pages before exploring further.
aisdk/elevenlabs test suite is built on Pest and follows a fixture- and conformance-based approach. No live API credentials are required to run the default suite — all HTTP interactions are intercepted by in-memory fakes that return pre-set responses. Live network verification tests exist separately and are never included in the default composer test run.
Running the Test Suite
Run lint, static analysis, and tests together
Check code style independently
--test mode (reports violations without modifying files).Auto-fix code style
lint, this modifies files).Preview Rector refactors
Test File Structure
The test suite is organised by capability area. Each file covers one slice of the provider surface:| File | What it tests |
|---|---|
tests/ElevenLabsSpeechTest.php | TTS model tests — request shape, query parameters, audio-format mapping |
tests/ElevenLabsTranscriptionTest.php | Scribe v2 batch transcription — multipart form fields, provider option forwarding |
tests/ElevenLabsLiveTest.php | Realtime session driver — WebSocket handshake, event encoding, client-secret flow |
tests/ElevenLabsMediaTest.php | Voice changer, voice isolator, sound effects, and dialogue — endpoint URLs, multipart vs. JSON bodies |
tests/ElevenLabsCreativeMediaTest.php | Music, voice design, dubbing, forced alignment — typed return values, parameter mapping |
FakeHttpClient
FakeHttpClient lives in tests/Fakes/FakeHttpClient.php and implements PSR-18’s ClientInterface. Construct it with a fixed status code, response body string, and optional content type; it records every request it receives so tests can assert on exact URIs, headers, and body payloads.
Creates a fake that always returns a response with the given HTTP status, body string, and
Content-Type header. Pass additional headers as the fourth argument when needed.The most recent PSR-7 request received by the fake. Inspect
getUri(), getHeaderLine(), or getBody() to assert on the outbound call.Decodes the last request’s body as JSON and returns it as an associative array. Returns an empty array when the body is not valid JSON (e.g. for multipart requests; inspect
(string) $client->lastRequest?->getBody() directly in those cases).configureElevenLabsWith(FakeHttpClient $client) is a test-only helper defined at the top of each test file. It constructs a Nyholm\Psr7\Factory\Psr17Factory and passes both the factory and the fake client into Generate::configure() via an AiSdk\Support\Sdk value object. This wires the PSR-17 request/response factory and the PSR-18 HTTP runner together, ensuring the SDK never makes real network calls during the test run.FakeTransport
FakeTransport and the inner FakeTransportConnection class live in tests/Fakes/FakeTransport.php and simulate a WebSocket connection for realtime-session tests. FakeTransport implements TransportInterface and always returns a FakeTransportConnection from connect(). The connection records every frame sent by the SDK and lets tests enqueue incoming frames for the session to consume.
The endpoint the SDK passed to
connect(). Inspect $transport->endpoint->uri to assert the correct WebSocket URL and query parameters.The active connection instance. Use its properties to assert on frames sent and to feed inbound events.
All frames sent by the SDK over this connection, in order.
Adds frames to the inbound queue. The session’s event loop will receive these on the next
receive() call.true after the SDK calls close() on the connection.true after the SDK calls finishSending(), signalling the end of the audio stream.Resetting Singletons Between Tests
TheElevenLabs facade and the core Generate facade both hold a static default instance. Tests must reset these after each case to prevent state leaking between tests:
ElevenLabs::reset() sets the internal $default provider back to null; Generate::reset() clears the configured Sdk instance. The next call to ElevenLabs::create() or Generate::configure() starts from a clean slate.
Live Network Tests
Credentialed live network tests exist in the repository but are kept separate from the main Pest suite. They require a realELEVENLABS_API_KEY environment variable and make actual HTTP requests to the ElevenLabs API. These tests are not run by composer test or composer test:all and should only be executed explicitly in environments where a valid API key is available and network calls are acceptable.