title | navigation.title |
---|---|
Fake Telegram interaction |
Fake |
In order to avoid sending real messages to Telegram when testing, the Telegraph
facade offers a ::fake()
method to start registering sent messages internally instead of sending them to Telegram APIs.
use DefStudio\Telegraph\Facades\Telegraph;
Telegraph::fake();
Telegraph::message("Hello devs!")->send();
// the message won be actually sent to telegram, but can still be asserted
Telegraph::assertSent('Hello devs!');
If needed for testing purpose, the ::fake()
helper can accept an array of responses to be returned for each endpoint call:
Telegraph::fake([
\DefStudio\Telegraph\Telegraph::ENDPOINT_MESSAGE => ['result' => 'oooook'],
]);
$response = Telegraph::message('foo')->send();
//$response will be a Response containing a json body: {"result":"oooook"}
For debugging purpose, a dump of the sent data can be obtained with:
Telegraph::fake();
// Telegraph requests...
Telegraph::dumpSentData();