|
| 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