|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of the PHPFUI\ConstantContact package |
| 5 | + * |
| 6 | + * (c) Bruce Wells |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view |
| 9 | + * the LICENSE.md file that was distributed with this source |
| 10 | + * code |
| 11 | + */ |
| 12 | +class HydrateTest extends \PHPUnit\Framework\TestCase |
| 13 | + { |
| 14 | + public function testHydration() : void |
| 15 | + { |
| 16 | + $json = '{ |
| 17 | + "contacts": [ |
| 18 | + { |
| 19 | + "contact_id": "d5e4dc88-9dbf-11ef-9af2-fa163e4d7501", |
| 20 | + "email_address": { |
| 21 | + "address": "xxxx@mailinator.com", |
| 22 | + "permission_to_send": "explicit", |
| 23 | + "created_at": "2024-11-08T10:54:32Z", |
| 24 | + "updated_at": "2024-11-08T10:54:32Z", |
| 25 | + "opt_in_source": "Contact", |
| 26 | + "opt_in_date": "2024-11-08T10:54:32Z", |
| 27 | + "confirm_status": "off" |
| 28 | + }, |
| 29 | + "first_name": "Petr", |
| 30 | + "last_name": "Pavel", |
| 31 | + "create_source": "Contact", |
| 32 | + "created_at": "2024-11-08T10:54:32Z", |
| 33 | + "updated_at": "2024-11-08T10:54:32Z" |
| 34 | + } |
| 35 | + ] |
| 36 | +}'; |
| 37 | + $this->assertJson($json); |
| 38 | + $dataArray = \json_decode($json, true); |
| 39 | + $this->assertIsArray($dataArray); |
| 40 | + $this->assertIsArray($dataArray['contacts']); |
| 41 | + $this->assertEquals('Petr', $dataArray['contacts'][0]['first_name']); |
| 42 | + $this->assertIsArray($dataArray['contacts'][0]['email_address']); |
| 43 | + $this->assertEquals('xxxx@mailinator.com', $dataArray['contacts'][0]['email_address']['address']); |
| 44 | + $contacts = new \PHPFUI\ConstantContact\Definition\Contacts($dataArray); |
| 45 | + $this->assertIsArray($contacts->contacts); |
| 46 | + $this->assertEquals('d5e4dc88-9dbf-11ef-9af2-fa163e4d7501', $contacts->contacts[0]->contact_id); |
| 47 | + $this->assertEquals('xxxx@mailinator.com', $contacts->contacts[0]->email_address->address); |
| 48 | + $this->assertEquals('xxxx@mailinator.com', $contacts->contacts[0]->email_address->address); |
| 49 | + $this->assertEquals('2024-11-08T10:54:32Z', $contacts->contacts[0]->created_at); |
| 50 | + $newJson = $contacts->getJSON(); |
| 51 | + $this->assertJson($newJson); |
| 52 | + $newDataArray = $contacts->toArray(); |
| 53 | + $this->assertEquals($dataArray, $newDataArray); |
| 54 | + } |
| 55 | + } |
0 commit comments