Skip to content

Commit 398eb89

Browse files
author
marcel corso gonzalez
authored
Merge pull request #174 from Xethron/add_failure_code_and_description
Add email failure code and description
2 parents f89d839 + 299bd4a commit 398eb89

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

src/MessageBird/Objects/EmailMessage.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ class EmailMessage extends Base
2424
*/
2525
protected $status;
2626

27+
/**
28+
* Failure code in the event that something went wrong
29+
*
30+
* @var int|null
31+
*/
32+
protected $failure_code;
33+
34+
/**
35+
* Failure description in the event that something went wrong
36+
*
37+
* @var string|null
38+
*/
39+
protected $failure_description;
40+
2741
/**
2842
* Get the created id
2943
*
@@ -43,4 +57,20 @@ public function getStatus()
4357
{
4458
return $this->status;
4559
}
60+
61+
/**
62+
* @return int|null
63+
*/
64+
public function getFailureCode()
65+
{
66+
return $this->failure_code;
67+
}
68+
69+
/**
70+
* @return string|null
71+
*/
72+
public function getFailureDescription()
73+
{
74+
return $this->failure_description;
75+
}
4676
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Tests\Unit\MessageBird\Objects;
4+
5+
use MessageBird\Objects\EmailMessage;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class EmailMessageTest extends TestCase
9+
{
10+
/**
11+
* Load From Array
12+
*
13+
* @dataProvider loadFromArrayDataProvider()
14+
*/
15+
public function testLoadFromArray($array, $expected): void
16+
{
17+
$message = new EmailMessage();
18+
19+
$message->loadFromArray($array);
20+
21+
self::assertSame($expected['id'], $message->getId());
22+
self::assertSame($expected['status'], $message->getStatus());
23+
self::assertSame($expected['failure_code'], $message->getFailureCode());
24+
self::assertSame($expected['failure_description'], $message->getFailureDescription());
25+
}
26+
27+
public function loadFromArrayDataProvider(): array
28+
{
29+
return [
30+
'as array' => [
31+
'array' => [
32+
'id' => '123456789',
33+
'status' => 'sent',
34+
],
35+
'expected' => [
36+
'id' => '123456789',
37+
'status' => 'sent',
38+
'failure_code' => null,
39+
'failure_description' => null,
40+
],
41+
],
42+
'as object' => [
43+
'array' => (object) [
44+
'id' => 'aa12bb34cc56dd78ee90ff',
45+
'status' => 'queued',
46+
],
47+
'expected' => [
48+
'id' => 'aa12bb34cc56dd78ee90ff',
49+
'status' => 'queued',
50+
'failure_code' => null,
51+
'failure_description' => null,
52+
],
53+
],
54+
'failed as array' => [
55+
'array' => [
56+
'id' => 'test_id',
57+
'status' => 'failed',
58+
'failure_code' => 20,
59+
'failure_description' => 'channel not found',
60+
61+
],
62+
'expected' => [
63+
'id' => 'test_id',
64+
'status' => 'failed',
65+
'failure_code' => 20,
66+
'failure_description' => 'channel not found',
67+
],
68+
],
69+
'failed as object' => [
70+
'array' => json_decode(json_encode([
71+
'id' => 'test_object_id',
72+
'status' => 'failed',
73+
'failure_code' => 10,
74+
'failure_description' => 'test error',
75+
])),
76+
'expected' => [
77+
'id' => 'test_object_id',
78+
'status' => 'failed',
79+
'failure_code' => 10,
80+
'failure_description' => 'test error',
81+
],
82+
],
83+
];
84+
}
85+
}

0 commit comments

Comments
 (0)