From 299bd4a3c4afa9e33bdbaf80d9268fdbfd729f7f Mon Sep 17 00:00:00 2001 From: Bernhard Breytenbach Date: Mon, 28 Jun 2021 14:27:03 +0200 Subject: [PATCH] Add email failure code and description --- src/MessageBird/Objects/EmailMessage.php | 30 +++++++ .../MessageBird/Objects/EmailMessageTest.php | 85 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 tests/Unit/MessageBird/Objects/EmailMessageTest.php diff --git a/src/MessageBird/Objects/EmailMessage.php b/src/MessageBird/Objects/EmailMessage.php index cebec096..3be5b1ad 100644 --- a/src/MessageBird/Objects/EmailMessage.php +++ b/src/MessageBird/Objects/EmailMessage.php @@ -24,6 +24,20 @@ class EmailMessage extends Base */ protected $status; + /** + * Failure code in the event that something went wrong + * + * @var int|null + */ + protected $failure_code; + + /** + * Failure description in the event that something went wrong + * + * @var string|null + */ + protected $failure_description; + /** * Get the created id * @@ -43,4 +57,20 @@ public function getStatus() { return $this->status; } + + /** + * @return int|null + */ + public function getFailureCode() + { + return $this->failure_code; + } + + /** + * @return string|null + */ + public function getFailureDescription() + { + return $this->failure_description; + } } diff --git a/tests/Unit/MessageBird/Objects/EmailMessageTest.php b/tests/Unit/MessageBird/Objects/EmailMessageTest.php new file mode 100644 index 00000000..4209e002 --- /dev/null +++ b/tests/Unit/MessageBird/Objects/EmailMessageTest.php @@ -0,0 +1,85 @@ +loadFromArray($array); + + self::assertSame($expected['id'], $message->getId()); + self::assertSame($expected['status'], $message->getStatus()); + self::assertSame($expected['failure_code'], $message->getFailureCode()); + self::assertSame($expected['failure_description'], $message->getFailureDescription()); + } + + public function loadFromArrayDataProvider(): array + { + return [ + 'as array' => [ + 'array' => [ + 'id' => '123456789', + 'status' => 'sent', + ], + 'expected' => [ + 'id' => '123456789', + 'status' => 'sent', + 'failure_code' => null, + 'failure_description' => null, + ], + ], + 'as object' => [ + 'array' => (object) [ + 'id' => 'aa12bb34cc56dd78ee90ff', + 'status' => 'queued', + ], + 'expected' => [ + 'id' => 'aa12bb34cc56dd78ee90ff', + 'status' => 'queued', + 'failure_code' => null, + 'failure_description' => null, + ], + ], + 'failed as array' => [ + 'array' => [ + 'id' => 'test_id', + 'status' => 'failed', + 'failure_code' => 20, + 'failure_description' => 'channel not found', + + ], + 'expected' => [ + 'id' => 'test_id', + 'status' => 'failed', + 'failure_code' => 20, + 'failure_description' => 'channel not found', + ], + ], + 'failed as object' => [ + 'array' => json_decode(json_encode([ + 'id' => 'test_object_id', + 'status' => 'failed', + 'failure_code' => 10, + 'failure_description' => 'test error', + ])), + 'expected' => [ + 'id' => 'test_object_id', + 'status' => 'failed', + 'failure_code' => 10, + 'failure_description' => 'test error', + ], + ], + ]; + } +}