mailgun-php/tests/Api/EventTest.php
2018-08-08 20:48:35 +01:00

83 lines
2.0 KiB
PHP

<?php
namespace Mailgun\Tests\Api;
use GuzzleHttp\Psr7\Response;
use Mailgun\Api\Event;
use Mailgun\Exception\InvalidArgumentException;
use Mailgun\Model\Event\EventResponse;
class EventTest extends TestCase
{
protected function getApiClass()
{
return Event::class;
}
public function testGet()
{
$this->setRequestMethod('GET');
$this->setRequestUri('/v3/example.com/events');
$this->setHttpResponse(new Response(200, ['Content-Type'=>'application/json'], <<<JSON
{
"items": [
{
"tags": [],
"id": "czsjqFATSlC3QtAK-C80nw",
"timestamp": 1376325780.160809,
"envelope": {
"sender": "me@samples.mailgun.org",
"transport": ""
},
"event": "accepted",
"campaigns": [],
"user-variables": {},
"flags": {
"is-authenticated": true,
"is-test-mode": false
},
"message": {
"headers": {
"to": "foo@example.com",
"message-id": "20130812164300.28108.52546@samples.mailgun.org",
"from": "Excited User <me@samples.mailgun.org>",
"subject": "Hello"
},
"attachments": [],
"recipients": [
"foo@example.com",
"baz@example.com",
"bar@example.com"
],
"size": 69
},
"recipient": "baz@example.com",
"method": "http"
}
],
"paging": {
"next":
"https://api.mailgun.net/v3/samples.mailgun.org/events/W3siY...",
"previous":
"https://api.mailgun.net/v3/samples.mailgun.org/events/Lkawm..."
}
}
JSON
));
$api = $this->getApiMock();
$event = $api->get('example.com');
$this->assertInstanceOf(EventResponse::class, $event);
$this->assertCount(1, $event->getItems());
$this->assertEquals('accepted', $event->getItems()[0]->getEvent());
}
public function testGetWithEmptyDomain()
{
$api = $this->getApiMock();
$this->expectException(InvalidArgumentException::class);
$api->get('');
}
}