NAME
Twilio::Http::FakeClient - HTTP transport for tests, with no network
SYNOPSIS
use Twilio::Http::FakeClient;
use Twilio::Rest::Client;
my $http = Twilio::Http::FakeClient->new;
my $client = Twilio::Rest::Client->new('ACxxxx', 'token', { http_client => $http });
$http->mock(200, { sid => 'SMxxxx', status => 'queued' });
my $response = $client->request('GET', 'https://api.twilio.com/2010-04-01/Accounts.json');
my ($request) = $http->requests;
print $request->{url}, "\n";
DESCRIPTION
Records every request in its final wire format and answers from a queue of mocked responses. Use it to test your own code without a Twilio account.
METHODS
new
my $http = Twilio::Http::FakeClient->new;
mock
$http->mock($status_code, $content, \%headers);
Adds a response to the queue. Responses are used in the order they were added. A reference as $content is encoded as JSON, and a string is used as it is. Returns the client, so calls can be chained.
send_request
Records the request and returns the next mocked response. It croaks when the queue is empty, so an unexpected request fails the test.
requests
Returns the recorded requests, in the format described in "prepare_request" in Twilio::Http::Client.
LICENSE
Copyright (c) 2026 Francisco Zarabozo. Released under the MIT License.