diff --git a/src/Mail/Client/Folder/MailFolderChildList.php b/src/Mail/Client/Folder/MailFolderChildList.php index 30e46f57..25be7610 100644 --- a/src/Mail/Client/Folder/MailFolderChildList.php +++ b/src/Mail/Client/Folder/MailFolderChildList.php @@ -52,7 +52,7 @@ * * @package Conjoon\Mail\Client\Folder */ -class MailFolderChildList extends AbstractList implements Arrayable +class MailFolderChildList extends AbstractList implements Arrayable, Jsonable { // ------------------------- // AbstractList @@ -68,7 +68,7 @@ public function getEntityType(): string // ------------------------- -// Jsonable +// Arrayable, Jsonable // ------------------------- /** @@ -83,7 +83,26 @@ public function toArray(): array $data[] = $mailFolder->toArray(); } + return $data; + } + + + /** + * @inheritdoc + */ + public function toJson(JsonStrategy $jsonStrategy = null): array + { + $data = []; + + foreach ($this->data as $mailFolder) { + $data[] = $jsonStrategy + ? $jsonStrategy->toJson($mailFolder) + : $mailFolder->toArray(); + } return $data; } + + + } diff --git a/tests/Mail/Client/Data/MailAccountTest.php b/tests/Mail/Client/Data/MailAccountTest.php index 6a6bb5ce..519ea963 100644 --- a/tests/Mail/Client/Data/MailAccountTest.php +++ b/tests/Mail/Client/Data/MailAccountTest.php @@ -159,9 +159,6 @@ public function testToJson() ->willReturn($account->toArray()); $this->assertEquals($config, $account->toJson($strategyMock)); - - - } diff --git a/tests/Mail/Client/Folder/MailFolderChildListTest.php b/tests/Mail/Client/Folder/MailFolderChildListTest.php index 9560c968..f17152d6 100644 --- a/tests/Mail/Client/Folder/MailFolderChildListTest.php +++ b/tests/Mail/Client/Folder/MailFolderChildListTest.php @@ -34,6 +34,8 @@ use Conjoon\Mail\Client\Folder\MailFolderChildList; use Conjoon\Util\AbstractList; use Conjoon\Util\Arrayable; +use Conjoon\Util\Jsonable; +use Conjoon\Util\JsonStrategy; use Tests\TestCase; /** @@ -55,6 +57,7 @@ public function testClass() $mailFolderChildList = new MailFolderChildList(); $this->assertInstanceOf(AbstractList::class, $mailFolderChildList); $this->assertInstanceOf(Arrayable::class, $mailFolderChildList); + $this->assertInstanceOf(Jsonable::class, $mailFolderChildList); $this->assertSame(MailFolder::class, $mailFolderChildList->getEntityType()); } @@ -93,4 +96,52 @@ public function testToArray() "data" => [] ]], $mailFolderChildList->toArray()); } + + + /** + * Tests constructor + */ + public function testToJson() + { + + $data = [ + "name" => "INBOX", + "unreadMessages" => 5, + "totalMessages" => 10, + "folderType" => MailFolder::TYPE_INBOX + ]; + + $folder = new MailFolder( + new FolderKey("dev", "INBOX"), + $data + ); + + $mailFolderChildList = new MailFolderChildList(); + + $mailFolderChildList[] = $folder; + + $this->assertEquals( + $mailFolderChildList->toArray(), + $mailFolderChildList->toJson() + ); + + // w/ strategy + + + + $strategyMock = + $this->getMockBuilder(JsonStrategy::class) + ->getMockForAbstractClass(); + + $strategyMock + ->expects($this->exactly(1)) + ->method("toJson") + ->with($folder) + ->willReturn($folder->toArray()); + + $this->assertEquals($folder->toArray(), $folder->toJson($strategyMock)); + + + } + }