diff --git a/src/Mailgun/Api/HttpApi.php b/src/Mailgun/Api/HttpApi.php index b612add..08ef0bf 100644 --- a/src/Mailgun/Api/HttpApi.php +++ b/src/Mailgun/Api/HttpApi.php @@ -29,7 +29,7 @@ abstract class HttpApi * * @var HttpClient */ - private $httpClient; + protected $httpClient; /** * @var Hydrator diff --git a/src/Mailgun/Api/MailingList.php b/src/Mailgun/Api/MailingList.php new file mode 100644 index 0000000..7091657 --- /dev/null +++ b/src/Mailgun/Api/MailingList.php @@ -0,0 +1,154 @@ +httpClient, $this->requestBuilder, $this->hydrator); + } + + /** + * Returns a paginated list of mailing lists on the domain. + * + * @param int $limit Maximum number of records to return (optional: 100 by default) + * + * @return PagesResponse + * + * @throws \Exception + */ + public function pages($limit = 100) + { + Assert::integer($limit); + Assert::greaterThan($limit, 0); + + $params = [ + 'limit' => $limit, + ]; + + $response = $this->httpGet('/v3/lists/pages', $params); + + return $this->hydrateResponse($response, PagesResponse::class); + } + + /** + * Creates a new mailing list on the current domain. + * + * @param string $address Address for the new mailing list + * @param string $name Name for the new mailing list (optional) + * @param string $description Description for the new mailing list (optional) + * @param string $accessLevel List access level, one of: readonly (default), members, everyone + * + * @return CreateResponse + * + * @throws \Exception + */ + public function create($address, $name = null, $description = null, $accessLevel = 'readonly') + { + Assert::stringNotEmpty($address); + Assert::nullOrStringNotEmpty($name); + Assert::nullOrStringNotEmpty($description); + Assert::oneOf($accessLevel, ['readonly', 'members', 'everyone']); + + $params = [ + 'address' => $address, + 'name' => $name, + 'description' => $description, + 'access_level' => $accessLevel, + ]; + + $response = $this->httpPost('/v3/lists', $params); + + return $this->hydrateResponse($response, CreateResponse::class); + } + + /** + * Returns a single mailing list. + * + * @param string $address Address of the mailing list + * + * @return ShowResponse + * + * @throws \Exception + */ + public function show($address) + { + Assert::stringNotEmpty($address); + + $response = $this->httpGet(sprintf('/v3/lists/%s', $address)); + + return $this->hydrateResponse($response, ShowResponse::class); + } + + /** + * Updates a mailing list. + * + * @param string $address Address of the mailing list + * @param array $parameters Array of field => value pairs to update + * + * @return UpdateResponse + * + * @throws \Exception + */ + public function update($address, $parameters = []) + { + Assert::stringNotEmpty($address); + Assert::isArray($parameters); + + foreach ($parameters as $field => $value) { + switch ($field) { + case 'address': + case 'name': + case 'description': + Assert::stringNotEmpty($value); + + break; + case 'access_level': + Assert::oneOf($value, ['readonly', 'members', 'everyone']); + + break; + } + } + + $response = $this->httpPut(sprintf('/v3/lists/%s', $address), $parameters); + + return $this->hydrateResponse($response, UpdateResponse::class); + } + + /** + * Removes a mailing list from the domain. + * + * @param string $address Address of the mailing list + * + * @return DeleteResponse + * + * @throws \Exception + */ + public function delete($address) + { + Assert::stringNotEmpty($address); + + $response = $this->httpDelete(sprintf('/v3/lists/%s', $address)); + + return $this->hydrateResponse($response, DeleteResponse::class); + } +} diff --git a/src/Mailgun/Api/MailingList/Member.php b/src/Mailgun/Api/MailingList/Member.php new file mode 100644 index 0000000..e91585a --- /dev/null +++ b/src/Mailgun/Api/MailingList/Member.php @@ -0,0 +1,233 @@ + $limit, + 'subscribed' => $subscribed, + ]; + + $response = $this->httpGet(sprintf('/v3/lists/%s/members/pages', $address), $params); + + return $this->hydrateResponse($response, IndexResponse::class); + } + + /** + * Shows a single member of the mailing list. + * + * @param string $list Address of the mailing list + * @param string $address Address of the member + * + * @return ShowResponse + * + * @throws \Exception + */ + public function show($list, $address) + { + Assert::stringNotEmpty($list); + Assert::stringNotEmpty($address); + + $response = $this->httpGet(sprintf('/v3/lists/%s/members/%s', $list, $address)); + + return $this->hydrateResponse($response, ShowResponse::class); + } + + /** + * Creates (or updates) a member of the mailing list. + * + * @param string $list Address of the mailing list + * @param string $address Address for the member + * @param string $name Name for the member (optional) + * @param array $vars Array of field => value pairs to store additional data + * @param string $subscribed `yes` to add as subscribed (default), `no` as unsubscribed + * @param string $upsert `yes` to update member if present, `no` to raise error in case of a duplicate member (default) + * + * @return CreateResponse + * + * @throws \Exception + */ + public function create($list, $address, $name = null, array $vars = [], $subscribed = 'yes', $upsert = 'no') + { + Assert::stringNotEmpty($list); + Assert::stringNotEmpty($address); + Assert::nullOrStringNotEmpty($name); + Assert::oneOf($subscribed, ['yes', 'no']); + Assert::oneOf($upsert, ['yes', 'no']); + + $params = [ + 'address' => $address, + 'name' => $name, + 'vars' => $vars, + 'subscribed' => $subscribed, + 'upsert' => $upsert, + ]; + + $response = $this->httpPost(sprintf('/v3/lists/%s/members', $list), $params); + + return $this->hydrateResponse($response, CreateResponse::class); + } + + /** + * Adds multiple members (up to 1000) to the mailing list. + * + * @param string $list Address of the mailing list + * @param array $members Array of members, each item should be either a single string address or an array of member properties + * @param string $upsert `yes` to update existing members, `no` (default) to ignore duplicates + * + * @return UpdateResponse + * + * @throws \Exception + */ + public function createMultiple($list, array $members, $upsert = 'no') + { + Assert::stringNotEmpty($list); + Assert::isArray($members); + + // workaround for webmozart/asserts <= 1.2 + if (count($members) > 1000) { + throw new InvalidArgumentException(sprintf('Expected an Array to contain at most %2$d elements. Got: %d', + 1000, + count($members) + )); + } + + Assert::oneOf($upsert, ['yes', 'no']); + + foreach ($members as $data) { + if (is_string($data)) { + Assert::stringNotEmpty($data); + // single address - no additional validation required + continue; + } + + Assert::isArray($data); + + foreach ($data as $field => $value) { + switch ($field) { + case 'address': + Assert::stringNotEmpty($value); + + break; + case 'name': + Assert::string($value); + + break; + case 'vars': + Assert::isArray($value); + + break; + case 'subscribed': + Assert::oneOf($value, ['yes', 'no']); + + break; + } + } + } + + $params = [ + 'members' => json_encode($members), + 'upsert' => $upsert, + ]; + + $response = $this->httpPost(sprintf('/v3/lists/%s/members.json', $list), $params); + + return $this->hydrateResponse($response, MailingListUpdateResponse::class); + } + + /** + * Updates a member on the mailing list. + * + * @param string $list Address of the mailing list + * @param string $address Address of the member + * @param array $parameters Array of key => value pairs to update + * + * @return UpdateResponse + * + * @throws \Exception + */ + public function update($list, $address, $parameters = []) + { + Assert::stringNotEmpty($list); + Assert::stringNotEmpty($address); + Assert::isArray($parameters); + + foreach ($parameters as $field => $value) { + switch ($field) { + case 'address': + case 'name': + Assert::stringNotEmpty($value); + + break; + case 'vars': + Assert::isArray($value); + + break; + case 'subscribed': + Assert::oneOf($value, ['yes', 'no']); + + break; + } + } + + $response = $this->httpPut(sprintf('/v3/lists/%s/members/%s', $list, $address), $parameters); + + return $this->hydrateResponse($response, UpdateResponse::class); + } + + /** + * Removes a member from the mailing list. + * + * @param string $list Address of the mailing list + * @param string $address Address of the member + * + * @return DeleteResponse + * + * @throws \Exception + */ + public function delete($list, $address) + { + Assert::stringNotEmpty($list); + Assert::stringNotEmpty($address); + + $response = $this->httpDelete(sprintf('/v3/lists/%s/members/%s', $list, $address)); + + return $this->hydrateResponse($response, DeleteResponse::class); + } +} diff --git a/src/Mailgun/Model/MailingList/CreateResponse.php b/src/Mailgun/Model/MailingList/CreateResponse.php new file mode 100644 index 0000000..1328272 --- /dev/null +++ b/src/Mailgun/Model/MailingList/CreateResponse.php @@ -0,0 +1,60 @@ +list = $list; + $this->message = $message; + } + + /** + * @return string + */ + public function getMessage() + { + return $this->message; + } + + /** + * @return MailingList + */ + public function getList() + { + return $this->list; + } +} diff --git a/src/Mailgun/Model/MailingList/DeleteResponse.php b/src/Mailgun/Model/MailingList/DeleteResponse.php new file mode 100644 index 0000000..492262f --- /dev/null +++ b/src/Mailgun/Model/MailingList/DeleteResponse.php @@ -0,0 +1,61 @@ +address = $address; + $this->message = $message; + } + + /** + * @return string + */ + public function getMessage() + { + return $this->message; + } + + /** + * @return string + */ + public function getAddress() + { + return $this->address; + } +} diff --git a/src/Mailgun/Model/MailingList/MailingList.php b/src/Mailgun/Model/MailingList/MailingList.php new file mode 100644 index 0000000..af9c42d --- /dev/null +++ b/src/Mailgun/Model/MailingList/MailingList.php @@ -0,0 +1,130 @@ +name = $name; + $this->address = $address; + $this->accessLevel = $accessLevel; + $this->description = $description; + $this->membersCount = $membersCount; + $this->createdAt = $createdAt; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @return string + */ + public function getAddress() + { + return $this->address; + } + + /** + * @return string + */ + public function getAccessLevel() + { + return $this->accessLevel; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @return int + */ + public function getMembersCount() + { + return $this->membersCount; + } + + /** + * @return \DateTime + */ + public function getCreatedAt() + { + return $this->createdAt; + } +} diff --git a/src/Mailgun/Model/MailingList/Member/CreateResponse.php b/src/Mailgun/Model/MailingList/Member/CreateResponse.php new file mode 100644 index 0000000..78ad7d0 --- /dev/null +++ b/src/Mailgun/Model/MailingList/Member/CreateResponse.php @@ -0,0 +1,61 @@ +member = $member; + $this->message = $message; + } + + /** + * @return Member + */ + public function getMember() + { + return $this->member; + } + + /** + * @return string + */ + public function getMessage() + { + return $this->message; + } +} diff --git a/src/Mailgun/Model/MailingList/Member/DeleteResponse.php b/src/Mailgun/Model/MailingList/Member/DeleteResponse.php new file mode 100644 index 0000000..a674bd9 --- /dev/null +++ b/src/Mailgun/Model/MailingList/Member/DeleteResponse.php @@ -0,0 +1,61 @@ +member = $member; + $this->message = $message; + } + + /** + * @return Member + */ + public function getMember() + { + return $this->member; + } + + /** + * @return string + */ + public function getMessage() + { + return $this->message; + } +} diff --git a/src/Mailgun/Model/MailingList/Member/IndexResponse.php b/src/Mailgun/Model/MailingList/Member/IndexResponse.php new file mode 100644 index 0000000..f5ca264 --- /dev/null +++ b/src/Mailgun/Model/MailingList/Member/IndexResponse.php @@ -0,0 +1,60 @@ +items = $items; + $this->paging = $paging; + } + + /** + * @return Member[] + */ + public function getItems() + { + return $this->items; + } +} diff --git a/src/Mailgun/Model/MailingList/Member/Member.php b/src/Mailgun/Model/MailingList/Member/Member.php new file mode 100644 index 0000000..f60f53a --- /dev/null +++ b/src/Mailgun/Model/MailingList/Member/Member.php @@ -0,0 +1,90 @@ +name = $name; + $this->address = $address; + $this->vars = $vars; + $this->subscribed = $subscribed; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @return string + */ + public function getAddress() + { + return $this->address; + } + + /** + * @return array + */ + public function getVars() + { + return $this->vars; + } + + /** + * @return bool + */ + public function isSubscribed() + { + return $this->subscribed; + } +} diff --git a/src/Mailgun/Model/MailingList/Member/ShowResponse.php b/src/Mailgun/Model/MailingList/Member/ShowResponse.php new file mode 100644 index 0000000..9de59d1 --- /dev/null +++ b/src/Mailgun/Model/MailingList/Member/ShowResponse.php @@ -0,0 +1,40 @@ +member = $member; + } + + /** + * @return Member + */ + public function getMember() + { + return $this->member; + } +} diff --git a/src/Mailgun/Model/MailingList/Member/UpdateResponse.php b/src/Mailgun/Model/MailingList/Member/UpdateResponse.php new file mode 100644 index 0000000..048bb3b --- /dev/null +++ b/src/Mailgun/Model/MailingList/Member/UpdateResponse.php @@ -0,0 +1,61 @@ +member = $member; + $this->message = $message; + } + + /** + * @return Member + */ + public function getMember() + { + return $this->member; + } + + /** + * @return string + */ + public function getMessage() + { + return $this->message; + } +} diff --git a/src/Mailgun/Model/MailingList/PagesResponse.php b/src/Mailgun/Model/MailingList/PagesResponse.php new file mode 100644 index 0000000..385722d --- /dev/null +++ b/src/Mailgun/Model/MailingList/PagesResponse.php @@ -0,0 +1,60 @@ +items = $items; + $this->paging = $paging; + } + + /** + * @return MailingList[] + */ + public function getLists() + { + return $this->items; + } +} diff --git a/src/Mailgun/Model/MailingList/ShowResponse.php b/src/Mailgun/Model/MailingList/ShowResponse.php new file mode 100644 index 0000000..bf4149e --- /dev/null +++ b/src/Mailgun/Model/MailingList/ShowResponse.php @@ -0,0 +1,40 @@ +list = $list; + } + + /** + * @return MailingList + */ + public function getList() + { + return $this->list; + } +} diff --git a/src/Mailgun/Model/MailingList/UpdateResponse.php b/src/Mailgun/Model/MailingList/UpdateResponse.php new file mode 100644 index 0000000..65aa533 --- /dev/null +++ b/src/Mailgun/Model/MailingList/UpdateResponse.php @@ -0,0 +1,60 @@ +list = $list; + $this->message = $message; + } + + /** + * @return string + */ + public function getMessage() + { + return $this->message; + } + + /** + * @return MailingList + */ + public function getList() + { + return $this->list; + } +} diff --git a/tests/Api/MailingList/MemberTest.php b/tests/Api/MailingList/MemberTest.php new file mode 100644 index 0000000..cc8f0ae --- /dev/null +++ b/tests/Api/MailingList/MemberTest.php @@ -0,0 +1,212 @@ + 100, + 'subscribed' => null, + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpGet') + ->with('/v3/lists/address/members/pages', $data) + ->willReturn(new Response()); + + $api->index('address', 100, null); + } + + public function testIndexSubscribed() + { + $data = [ + 'limit' => 100, + 'subscribed' => 'yes', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpGet') + ->with('/v3/lists/address/members/pages', $data) + ->willReturn(new Response()); + + $api->index('address', 100, 'yes'); + } + + public function testIndexUnsubscribed() + { + $data = [ + 'limit' => 100, + 'subscribed' => 'no', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpGet') + ->with('/v3/lists/address/members/pages', $data) + ->willReturn(new Response()); + + $api->index('address', 100, 'no'); + } + + public function testCreate() + { + $data = [ + 'address' => 'foo@example.com', + 'name' => 'Foo', + 'vars' => [], + 'subscribed' => 'yes', + 'upsert' => 'no', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpPost') + ->with('/v3/lists/address/members', $data) + ->willReturn(new Response()); + + $api->create($list = 'address', $address = 'foo@example.com', $name = 'Foo', $vars = [], $subscribed = 'yes', $upsert = 'no'); + } + + public function testCreateInvalidAddress() + { + $this->setExpectedException(InvalidArgumentException::class); + + $api = $this->getApiMock(); + $api->create('address', ''); + } + + public function testCreateInvalidSubscribed() + { + $this->setExpectedException(InvalidArgumentException::class); + + $api = $this->getApiMock(); + $api->create('address', 'foo@example.com', null, [], true); + } + + public function testCreateMultiple() + { + $data = [ + 'members' => json_encode([ + 'bob@example.com', + 'foo@example.com', + [ + 'address' => 'billy@example.com', + 'name' => 'Billy', + 'subscribed' => 'yes', + ], + ]), + 'upsert' => 'no', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpPost') + ->with('/v3/lists/address/members.json', $data) + ->willReturn(new Response()); + + $api->createMultiple($list = 'address', [ + 'bob@example.com', + 'foo@example.com', + [ + 'address' => 'billy@example.com', + 'name' => 'Billy', + 'subscribed' => 'yes', + ], + ], $upsert = 'no'); + } + + public function testCreateMultipleInvalidMemberArgument() + { + $this->setExpectedException(InvalidArgumentException::class); + + $data = [ + 'bob@example.com', + 'foo@example.com', + [ + 'address' => 'billy@example.com', + 'name' => 'Billy', + 'subscribed' => true, + ], + ]; + + $api = $this->getApiMock(); + $api->createMultiple('address', $data); + } + + public function testCreateMultipleCountMax1000() + { + $this->setExpectedException(InvalidArgumentException::class); + + $members = range(1, 1001); + $members = array_map('strval', $members); + + $api = $this->getApiMock(); + $api->createMultiple('address', $members); + } + + public function testUpdate() + { + $data = [ + 'vars' => [ + 'foo' => 'bar', + ], + 'subscribed' => 'yes', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpPut') + ->with('/v3/lists/address/members/member', $data) + ->willReturn(new Response()); + + $api->update('address', 'member', $data); + } + + public function testUpdateInvalidArgument() + { + $this->setExpectedException(InvalidArgumentException::class); + + $data = [ + 'vars' => 'foo=bar', + 'subscribed' => 'yes', + ]; + + $api = $this->getApiMock(); + $api->update('address', 'member', $data); + } + + public function testDelete() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpDelete') + ->with('/v3/lists/address/members/member') + ->willReturn(new Response()); + + $api->delete('address', 'member'); + } + + /** + * {@inheritdoc} + */ + protected function getApiClass() + { + return MailingList\Member::class; + } +} diff --git a/tests/Api/MailingListTest.php b/tests/Api/MailingListTest.php new file mode 100644 index 0000000..6fe4115 --- /dev/null +++ b/tests/Api/MailingListTest.php @@ -0,0 +1,140 @@ + 10, + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpGet') + ->with('/v3/lists/pages', $data) + ->willReturn(new Response()); + + $api->pages(10); + } + + public function testPagesInvalidArgument() + { + $this->setExpectedException(InvalidArgumentException::class); + $api = $this->getApiMock(); + $limit = -1; + + $api->pages($limit); + } + + public function testCreate() + { + $data = [ + 'address' => 'foo@example.com', + 'name' => 'Foo', + 'description' => 'Description', + 'access_level' => 'readonly', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpPost') + ->with('/v3/lists', $data) + ->willReturn(new Response()); + + $api->create($address = 'foo@example.com', $name = 'Foo', $description = 'Description', $accessLevel = 'readonly'); + } + + public function testCreateInvalidAddress() + { + $this->setExpectedException(InvalidArgumentException::class); + + $api = $this->getApiMock(); + $api->create($address = '', $name = 'Foo', $description = 'Description', $accessLevel = 'readonly'); + } + + public function testCreateInvalidAccessLevel() + { + $this->setExpectedException(InvalidArgumentException::class); + + $api = $this->getApiMock(); + $api->create($address = '', $name = 'Foo', $description = 'Description', $accessLevel = 'admin'); + } + + public function testShow() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpGet') + ->with('/v3/lists/address') + ->willReturn(new Response()); + + $api->show('address'); + } + + public function testShowInvalidAddress() + { + $this->setExpectedException(InvalidArgumentException::class); + + $api = $this->getApiMock(); + $api->show(''); + } + + public function testUpdate() + { + $data = [ + 'description' => 'desc', + ]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpPut') + ->with('/v3/lists/address', $data) + ->willReturn(new Response()); + + $api->update('address', $data); + } + + public function testUpdateInvalidArgument() + { + $this->setExpectedException(InvalidArgumentException::class); + + $data = [ + 'access_level' => 'foo', + ]; + + $api = $this->getApiMock(); + $api->update('address', $data); + } + + public function testDelete() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('httpDelete') + ->with('/v3/lists/address') + ->willReturn(new Response()); + + $api->delete('address'); + } + + /** + * {@inheritdoc} + */ + protected function getApiClass() + { + return MailingList::class; + } +} diff --git a/tests/Model/MailingList/CreateResponseTest.php b/tests/Model/MailingList/CreateResponseTest.php new file mode 100644 index 0000000..12faf34 --- /dev/null +++ b/tests/Model/MailingList/CreateResponseTest.php @@ -0,0 +1,38 @@ +assertEquals('Mailing list has been created', $model->getMessage()); + $this->assertInstanceOf(MailingList::class, $model->getList()); + $this->assertEquals(0, $model->getList()->getMembersCount()); + } +} diff --git a/tests/Model/MailingList/DeleteResponseTest.php b/tests/Model/MailingList/DeleteResponseTest.php new file mode 100644 index 0000000..40899e3 --- /dev/null +++ b/tests/Model/MailingList/DeleteResponseTest.php @@ -0,0 +1,30 @@ +assertEquals('Mailing list has been deleted', $model->getMessage()); + $this->assertEquals('dev@samples.mailgun.org', $model->getAddress()); + } +} diff --git a/tests/Model/MailingList/Member/CreateResponseTest.php b/tests/Model/MailingList/Member/CreateResponseTest.php new file mode 100644 index 0000000..d58e875 --- /dev/null +++ b/tests/Model/MailingList/Member/CreateResponseTest.php @@ -0,0 +1,39 @@ +assertEquals('Mailing list member has been created', $model->getMessage()); + $this->assertInstanceOf(Member::class, $model->getMember()); + $this->assertEquals('Bob Bar', $model->getMember()->getName()); + } +} diff --git a/tests/Model/MailingList/Member/DeleteResponseTest.php b/tests/Model/MailingList/Member/DeleteResponseTest.php new file mode 100644 index 0000000..614d401 --- /dev/null +++ b/tests/Model/MailingList/Member/DeleteResponseTest.php @@ -0,0 +1,35 @@ +assertEquals('Mailing list member has been deleted', $model->getMessage()); + $member = $model->getMember(); + $this->assertInstanceOf(Member::class, $member); + $this->assertEquals('bar@example.com', $member->getAddress()); + } +} diff --git a/tests/Model/MailingList/Member/IndexResponseTest.php b/tests/Model/MailingList/Member/IndexResponseTest.php new file mode 100644 index 0000000..4530eab --- /dev/null +++ b/tests/Model/MailingList/Member/IndexResponseTest.php @@ -0,0 +1,49 @@ +getItems(); + $this->assertCount(1, $members); + $member = $members[0]; + $this->assertInstanceOf(Member::class, $member); + $this->assertEquals('Foo Bar', $member->getName()); + } +} diff --git a/tests/Model/MailingList/Member/UpdateResponseTest.php b/tests/Model/MailingList/Member/UpdateResponseTest.php new file mode 100644 index 0000000..4cea23b --- /dev/null +++ b/tests/Model/MailingList/Member/UpdateResponseTest.php @@ -0,0 +1,39 @@ +assertEquals('Mailing list member has been updated', $model->getMessage()); + $this->assertInstanceOf(Member::class, $model->getMember()); + $this->assertEquals('Foo Bar', $model->getMember()->getName()); + } +} diff --git a/tests/Model/MailingList/PagesResponseTest.php b/tests/Model/MailingList/PagesResponseTest.php new file mode 100644 index 0000000..92f6a32 --- /dev/null +++ b/tests/Model/MailingList/PagesResponseTest.php @@ -0,0 +1,55 @@ +getLists(); + $this->assertCount(2, $lists); + $list = $lists[0]; + + $this->assertEquals('everyone', $list->getAccessLevel()); + } +} diff --git a/tests/Model/MailingList/UpdateResponseTest.php b/tests/Model/MailingList/UpdateResponseTest.php new file mode 100644 index 0000000..0bcad8e --- /dev/null +++ b/tests/Model/MailingList/UpdateResponseTest.php @@ -0,0 +1,39 @@ +assertEquals('Mailing list has been updated', $model->getMessage()); + $this->assertInstanceOf(MailingList::class, $model->getList()); + $this->assertEquals(7, $model->getList()->getMembersCount()); + } +}