Skip to content

Commit

Permalink
Merge pull request #174 from Xethron/add_failure_code_and_description
Browse files Browse the repository at this point in the history
Add email failure code and description
  • Loading branch information
marcel corso gonzalez authored Jun 28, 2021
2 parents f89d839 + 299bd4a commit 398eb89
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/MessageBird/Objects/EmailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
}
}
85 changes: 85 additions & 0 deletions tests/Unit/MessageBird/Objects/EmailMessageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Tests\Unit\MessageBird\Objects;

use MessageBird\Objects\EmailMessage;
use PHPUnit\Framework\TestCase;

class EmailMessageTest extends TestCase
{
/**
* Load From Array
*
* @dataProvider loadFromArrayDataProvider()
*/
public function testLoadFromArray($array, $expected): void
{
$message = new EmailMessage();

$message->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',
],
],
];
}
}

0 comments on commit 398eb89

Please sign in to comment.