diff options
author | Hannes Kindströmmer <hannes@kindstrommer.se> | 2017-03-20 13:58:46 +0100 |
---|---|---|
committer | Hannes Kindströmmer <hannes@kindstrommer.se> | 2017-03-20 13:58:46 +0100 |
commit | 2e6ef5629e2038a196b94b48a673cdc37b783a59 (patch) | |
tree | c1e0d54b695feb43fdd42930fcb8d942ce71f75f | |
parent | 39d7d133e41e9f8a708e8a8118d5f21007cfd2e5 (diff) | |
download | ip1-php-sdk-2e6ef5629e2038a196b94b48a673cdc37b783a59.zip ip1-php-sdk-2e6ef5629e2038a196b94b48a673cdc37b783a59.tar.gz ip1-php-sdk-2e6ef5629e2038a196b94b48a673cdc37b783a59.tar.bz2 |
Correct and complete BlacklistEntry classes and tests
Signed-off-by: Hannes Kindströmmer <hannes@kindstrommer.se>
-rw-r--r-- | src/Core/Communicator.php | 11 | ||||
-rw-r--r-- | src/Recipient/BlacklistEntry.php | 2 | ||||
-rw-r--r-- | src/Recipient/ProcessedBlacklistEntry.php | 2 | ||||
-rw-r--r-- | tests/Recipient/BlacklistTest.php | 34 |
4 files changed, 47 insertions, 2 deletions
diff --git a/src/Core/Communicator.php b/src/Core/Communicator.php index 0764df1..50a1227 100644 --- a/src/Core/Communicator.php +++ b/src/Core/Communicator.php @@ -12,6 +12,7 @@ namespace IP1\RESTClient\Core; use IP1\RESTClient\Recipient\RecipientFactory; +use IP1\RESTClient\Recipient\ProcessedBlacklistEntry; use IP1\RESTClient\Core\ProcessedComponentInterface; use IP1\RESTClient\Core\UpdatableComponentInterface; use IP1\RESTClient\Core\ProcessableComponentInterface; @@ -63,6 +64,11 @@ class Communicator case "IP1\RESTClient\SMS\OutGoingSMS": $response = $this->sendRequest("api/sms/send", "POST", json_encode($component)); return RecipientFactory::createProcessedOutGoingSMSFromJSONArray($response); + case "IP1\RESTClient\Recipient\BlacklistEntry": + $response = $this->sendRequest("api/blacklist", "POST", json_encode($component)); + $stdResponse = json_decode($response); + $created = new \DateTime($stdResponse->Created); + return new ProcessedBlacklistEntry($stdResponse->Phone, $stdResponse->ID, $created); default: throw new \InvalidArgumentException("Given JsonSerializable not supported."); } @@ -88,6 +94,11 @@ class Communicator case "IP1\RESTClient\Recipient\ProcessedMembership": $response = $this->sendRequest("api/memberships/".$component->getID(), "DELETE"); return RecipientFactory::createProcessedMembershipFromJSON($response); + case "IP1\RESTClient\Recipient\BlacklistEntry": + $response = $this->sendRequest("api/blacklist/".$component->getID(), "DELETE"); + $stdResponse = json_decode($response); + $created = new \DateTime($stdResponse->Created); + return new ProcessedBlacklistEntry($stdResponse->Phone, $stdResponse->ID, $created); default: throw new \InvalidArgumentException("Given JsonSerializable not supported."); } diff --git a/src/Recipient/BlacklistEntry.php b/src/Recipient/BlacklistEntry.php index 9ce14eb..506e8cb 100644 --- a/src/Recipient/BlacklistEntry.php +++ b/src/Recipient/BlacklistEntry.php @@ -26,7 +26,7 @@ class BlacklistEntry implements ProcessableComponentInterface * Returns the phone number of the BlacklistEntry * @return string Phone Number */ - public function getPhone(): string + public function getPhoneNumber(): string { return $this->phone; } diff --git a/src/Recipient/ProcessedBlacklistEntry.php b/src/Recipient/ProcessedBlacklistEntry.php index 8d4c09c..0726a31 100644 --- a/src/Recipient/ProcessedBlacklistEntry.php +++ b/src/Recipient/ProcessedBlacklistEntry.php @@ -7,7 +7,7 @@ use IP1\RESTClient\Core\ProcessedComponentInterface; /** * A BlacklistEntry that has been processed by the API. */ -class ProcessedBlacklistEntry implements ProcessedComponentInterface +class ProcessedBlacklistEntry extends BlacklistEntry implements ProcessedComponentInterface { /** * The ID of the BlacklistEntry diff --git a/tests/Recipient/BlacklistTest.php b/tests/Recipient/BlacklistTest.php index 858dfcd..09aad45 100644 --- a/tests/Recipient/BlacklistTest.php +++ b/tests/Recipient/BlacklistTest.php @@ -17,5 +17,39 @@ class BlacklistTest extends AbstractEnviromentProvider $pbl = new ProcessedBlacklistEntry("12025550125", random_int(0, PHP_INT_MAX), $dateTime); $this->assertTrue(is_int($pbl->getID())); $this->assertTrue(0 < $pbl->getID()); + $this->assertEquals("12025550125", $pbl->getPhoneNumber()); + $this->assertEquals(\DateTime::class, get_class($pbl->getCreated())); + } + /** + * @group api + */ + public function testAPI() + { + $blackListEntry = new BlacklistEntry("12025550125"); + $processed = $this->addBlacklistEntryToAPI($blackListEntry); + $deleted = $this->removeBlacklistEntryToAPI($processed); + $this->assertEquals($blackListEntry->getPhoneNumber(), $deleted->getPhoneNumber()); + } + public function addBlacklistEntryToAPI(BlacklistEntry $entry): ProcessedBlacklistEntry + { + $blackListEntry = $this->getCommunicator()->add($entry); + $this->assertEquals($entry->getPhoneNumber(), $blackListEntry->getPhoneNumber()); + } + public function removeBlacklistEntryToAPI(ProcessedBlacklistEntry $entry): ProcessedBlacklistEntry + { + $blackListEntry = $this->getCommunicator->remove($entry); + $this->assertEquals($entry->getID(), $blackListEntry->getID()); + $this->assertEquals($entry->getCreated(), $blackListEntry->getCreated()); + $this->assertEquals($entry->getPhoneNumber, $blackListEntry->getPhoneNumber()); + return $blackListEntry; + } + public function tearDown() + { + if ($com = $this->getCommunicator()) { + $arrayResponse = json_decode($com->get("api/blacklist")); + foreach ($arrayResponse as $value) { + $com->delete('api/blacklist/'.$value->ID); + } + } } } |