diff --git a/src/Mailgun/Model/Message/ShowResponse.php b/src/Mailgun/Model/Message/ShowResponse.php index 45e0926..1a1a553 100644 --- a/src/Mailgun/Model/Message/ShowResponse.php +++ b/src/Mailgun/Model/Message/ShowResponse.php @@ -105,7 +105,7 @@ class ShowResponse implements ApiResponse /** * @param array $data * - * @return SendResponse + * @return ShowResponse */ public static function create(array $data) { diff --git a/src/Mailgun/Model/Tag/Tag.php b/src/Mailgun/Model/Tag/Tag.php index 34a6bac..1a88ff5 100644 --- a/src/Mailgun/Model/Tag/Tag.php +++ b/src/Mailgun/Model/Tag/Tag.php @@ -37,7 +37,7 @@ class Tag * @param \DateTime $firstSeen * @param \DateTime $lastSeen */ - public function __construct($tag, $description, \DateTime $firstSeen, \DateTime $lastSeen) + public function __construct($tag, $description, \DateTime $firstSeen = null, \DateTime $lastSeen = null) { $this->tag = $tag; $this->description = $description; @@ -52,7 +52,10 @@ class Tag */ public static function create(array $data) { - return new self($data['tag'], $data['description'], new \DateTime($data['first-seen']), new \DateTime($data['last-seen'])); + $firstSeen = isset($data['first-seen']) ? new \DateTime($data['first-seen']) : null; + $lastSeen = isset($data['last-seen']) ? new \DateTime($data['last-seen']) : null; + + return new self($data['tag'], $data['description'], $firstSeen, $lastSeen); } /** diff --git a/tests/Model/Event/EventResponseTest.php b/tests/Model/Event/EventResponseTest.php new file mode 100644 index 0000000..8f75f33 --- /dev/null +++ b/tests/Model/Event/EventResponseTest.php @@ -0,0 +1,71 @@ +", + "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; + $model = EventResponse::create(json_decode($json, true)); + $events = $model->getItems(); + $this->assertCount(1, $events); + $event = $events[0]; + $this->assertEquals('czsjqFATSlC3QtAK-C80nw', $event->getId()); + } +} diff --git a/tests/Model/Message/SendResponseTest.php b/tests/Model/Message/SendResponseTest.php new file mode 100644 index 0000000..32cbffe --- /dev/null +++ b/tests/Model/Message/SendResponseTest.php @@ -0,0 +1,30 @@ +" +} +JSON; + $model = SendResponse::create(json_decode($json, true)); + $this->assertEquals('<20111114174239.25659.5817@samples.mailgun.org>', $model->getId()); + $this->assertEquals('Queued. Thank you.', $model->getMessage()); + } +} diff --git a/tests/Model/Route/CreateResponseTest.php b/tests/Model/Route/CreateResponseTest.php new file mode 100644 index 0000000..b08fa5c --- /dev/null +++ b/tests/Model/Route/CreateResponseTest.php @@ -0,0 +1,42 @@ +assertEquals('Route has been created', $model->getMessage()); + $route = $model->getRoute(); + $this->assertEquals('Sample route', $route->getDescription()); + } +} diff --git a/tests/Model/Route/IndexResponseTest.php b/tests/Model/Route/IndexResponseTest.php new file mode 100644 index 0000000..c4826eb --- /dev/null +++ b/tests/Model/Route/IndexResponseTest.php @@ -0,0 +1,46 @@ +assertEquals('266', $model->getTotalCount()); + $routes = $model->getRoutes(); + $this->assertCount(1, $routes); + $route = $routes[0]; + $this->assertEquals('Sample route', $route->getDescription()); + } +} diff --git a/tests/Model/Route/ShowResponseTest.php b/tests/Model/Route/ShowResponseTest.php new file mode 100644 index 0000000..8f9ac4f --- /dev/null +++ b/tests/Model/Route/ShowResponseTest.php @@ -0,0 +1,38 @@ +assertEquals('Sample route', $model->getRoute()->getDescription()); + } +} diff --git a/tests/Model/Tag/IndexResponseTest.php b/tests/Model/Tag/IndexResponseTest.php new file mode 100644 index 0000000..4f81efc --- /dev/null +++ b/tests/Model/Tag/IndexResponseTest.php @@ -0,0 +1,51 @@ +getItems(); + $this->assertCount(2, $tags); + $tag = $tags[0]; + $this->assertEquals('red', $tag->getTag()); + } +}