diff options
author | Hannes Kindströmmer <hannes@kindstrommer.se> | 2017-03-17 16:53:05 +0100 |
---|---|---|
committer | Hannes Kindströmmer <hannes@kindstrommer.se> | 2017-03-17 16:53:05 +0100 |
commit | d678de2563c4fce7ccbcd530e1051af5c63a352e (patch) | |
tree | a5b3f3b47b58278e15d173714c3ea967314a039c | |
parent | 2cb45bae7080166abb1a0834562f6c1194924bae (diff) | |
parent | a65c428f6f15bd06048e5796ab5e2f29cae719b7 (diff) | |
download | ip1-php-sdk-d678de2563c4fce7ccbcd530e1051af5c63a352e.zip ip1-php-sdk-d678de2563c4fce7ccbcd530e1051af5c63a352e.tar.gz ip1-php-sdk-d678de2563c4fce7ccbcd530e1051af5c63a352e.tar.bz2 |
Merge branch 'feature/recipient-testing' into develop
-rw-r--r-- | src/Recipient/ProcessedGroup.php | 8 | ||||
-rw-r--r-- | tests/Core/AbstractEnviromentProvider.php | 2 | ||||
-rw-r--r-- | tests/Recipient/ContactTest.php | 71 | ||||
-rw-r--r-- | tests/Recipient/ProcessedContactTest.php | 71 | ||||
-rw-r--r-- | tests/Recipient/ProcessedGroupTest.php | 79 |
5 files changed, 155 insertions, 76 deletions
diff --git a/src/Recipient/ProcessedGroup.php b/src/Recipient/ProcessedGroup.php index eef4f79..76deca3 100644 --- a/src/Recipient/ProcessedGroup.php +++ b/src/Recipient/ProcessedGroup.php @@ -145,6 +145,14 @@ class ProcessedGroup extends Group implements UpdatableComponentInterface, Membe return $this->contacts; } /** + * Tells whether contacts has been fetched from the API or not. + * @return boolean Whether the contacts has been fetched from the API or not. + */ + public function contactsFetched(): bool + { + return $this->contactsFetched; + } + /** * @param Communicator $communicator Used to add the membership to the API. * @param ProcessedContact $contact The contact that is to be added to the Group. * @return ProcessedMembership diff --git a/tests/Core/AbstractEnviromentProvider.php b/tests/Core/AbstractEnviromentProvider.php index 2dc4494..38847ce 100644 --- a/tests/Core/AbstractEnviromentProvider.php +++ b/tests/Core/AbstractEnviromentProvider.php @@ -9,7 +9,7 @@ abstract class AbstractEnviromentProvider extends TestCase { private $communicator; private $communicatorEnabled = false; - public function __construct() + public function setUp() { if (getenv("USER") || getenv("PASS")) { // Uses Enviroment Variables provided by Travis CI for security reasons. diff --git a/tests/Recipient/ContactTest.php b/tests/Recipient/ContactTest.php index 09f2444..529c0b6 100644 --- a/tests/Recipient/ContactTest.php +++ b/tests/Recipient/ContactTest.php @@ -16,12 +16,11 @@ use IP1\RESTClient\Recipient\Contact; use IP1\RESTClient\Recipient\RecipientFactory; use IP1\RESTClient\Recipient\ProcessedContact; use PHPUnit\Framework\TestCase; -use IP1\RESTClient\Test\Core\AbstractEnviromentProvider; /** * @covers Contact */ -class ContactTest extends AbstractEnviromentProvider +class ContactTest extends TestCase { private $completeContactString; @@ -31,9 +30,8 @@ class ContactTest extends AbstractEnviromentProvider private $minimalContactString; private $minimalContactStd; - public function __construct() + public function setUp() { - parent::__construct(); $this->completeContactString = trim(file_get_contents("tests/resources/contact/contact.json")); $this->incompleteContactString = trim(file_get_contents("tests/resources/contact/incomplete_contact.json")); $this->minimalContactString = trim(file_get_contents("tests/resources/contact/minimal_contact.json")); @@ -41,71 +39,6 @@ class ContactTest extends AbstractEnviromentProvider $this->incompleteContactStd = json_decode($this->incompleteContactString); $this->minimalContactStd = json_decode($this->minimalContactString); } - public function tearDown() - { - if ($this->isCommunicatorEnabled()) { - $contacts = RecipientFactory::createProcessedContactFromStdClassArray( - json_decode($this->getCommunicator()->get('api/contacts')) - ); - foreach ($contacts as $c) { - $this->getCommunicator()->remove($c); - } - } - } - /** - * @group api - */ - public function testAPI() - { - $contact = RecipientFactory::createContactFromJSON($this->completeContactString); - $newContact = $this->getCommunicator()->add($contact); - $this->assertEquals(ProcessedContact::class, get_class($newContact)); - $this->assertEquals($contact->getEmail(), $newContact->getEmail()); - $this->assertEquals($contact->getFirstName(), $newContact->getFirstName()); - $this->assertEquals($contact->getNotes(), $newContact->getNotes()); - $this->assertEquals($contact->getLastName(), $newContact->getLastName()); - $this->assertEquals($contact->getOrganization(), $newContact->getOrganization()); - $this->assertEquals($contact->getPhoneNumber(), $newContact->getPhoneNumber()); - $this->assertEquals($contact->getTitle(), $newContact->getTitle()); - $this->assertTrue(is_int($newContact->getID())); - - $newContact->setLastName("Swann"); - $newContact->setTitle("Queen"); - - $alteredContact = $this->getCommunicator()->edit($newContact); - $this->assertEquals(ProcessedContact::class, get_class($alteredContact)); - $this->assertEquals($newContact->getEmail(), $alteredContact->getEmail()); - $this->assertEquals($newContact->getFirstName(), $alteredContact->getFirstName()); - $this->assertEquals($newContact->getNotes(), $alteredContact->getNotes()); - $this->assertEquals($newContact->getLastName(), $alteredContact->getLastName()); - $this->assertEquals($newContact->getOrganization(), $alteredContact->getOrganization()); - $this->assertEquals($newContact->getPhoneNumber(), $alteredContact->getPhoneNumber()); - $this->assertEquals($newContact->getTitle(), $alteredContact->getTitle()); - $this->assertEquals($newContact->getID(), $alteredContact->getID()); - - $deletedContact = $this->getCommunicator()->remove($newContact); - $this->assertEquals(ProcessedContact::class, get_class($deletedContact)); - $this->assertEquals($newContact->getEmail(), $deletedContact->getEmail()); - $this->assertEquals($newContact->getFirstName(), $deletedContact->getFirstName()); - $this->assertEquals($newContact->getNotes(), $deletedContact->getNotes()); - $this->assertEquals($newContact->getLastName(), $deletedContact->getLastName()); - $this->assertEquals($newContact->getOrganization(), $deletedContact->getOrganization()); - $this->assertEquals($newContact->getPhoneNumber(), $deletedContact->getPhoneNumber()); - $this->assertEquals($newContact->getTitle(), $deletedContact->getTitle()); - $this->assertEquals($newContact->getID(), $deletedContact->getID()); - } - /** - * @group api - */ - public function testIsContactBookEmpty() - { - $contacts = RecipientFactory::createProcessedContactFromStdClassArray( - json_decode( - $this->getCommunicator()->get("api/contacts") - ) - ); - $this->assertEquals([], $contacts->getArrayCopy()); - } public function testCreateFromStdClass() { $contact = RecipientFactory::createContactFromStdClass($this->completeContactStd); diff --git a/tests/Recipient/ProcessedContactTest.php b/tests/Recipient/ProcessedContactTest.php index ef061f9..493c967 100644 --- a/tests/Recipient/ProcessedContactTest.php +++ b/tests/Recipient/ProcessedContactTest.php @@ -28,9 +28,9 @@ class ProcessedContactTest extends AbstractEnviromentProvider private $minimalContactString; private $minimalContactStd; - public function __construct() + public function setUp() { - parent::__construct(); + parent::setUp(); $this->completeContactString = trim( file_get_contents("tests/resources/processed_contact/processed_contact.json") ); @@ -44,7 +44,18 @@ class ProcessedContactTest extends AbstractEnviromentProvider $this->incompleteContactStd = json_decode($this->incompleteContactString); $this->minimalContactStd = json_decode($this->minimalContactString); } - + public function tearDown() + { + if ($this->isCommunicatorEnabled()) { + $contacts = RecipientFactory::createProcessedContactFromStdClassArray( + json_decode($this->getCommunicator()->get('api/contacts')) + ); + foreach ($contacts as $c) { + $this->getCommunicator()->remove($c); + } + } + } + public function testCreateCompleteFromStdClass() { $contact = RecipientFactory::createProcessedContactFromStdClass($this->completeContactStd); @@ -70,4 +81,58 @@ class ProcessedContactTest extends AbstractEnviromentProvider $this->assertEquals(ProcessedContact::IS_READ_ONLY, $contact->isReadOnly()); $this->assertEquals(false, $contact->isReadOnly()); } + /** + * @group api + */ + public function testAPI() + { + $contact = RecipientFactory::createContactFromJSON($this->completeContactString); + $newContact = $this->getCommunicator()->add($contact); + $this->assertEquals(ProcessedContact::class, get_class($newContact)); + $this->assertEquals($contact->getEmail(), $newContact->getEmail()); + $this->assertEquals($contact->getFirstName(), $newContact->getFirstName()); + $this->assertEquals($contact->getNotes(), $newContact->getNotes()); + $this->assertEquals($contact->getLastName(), $newContact->getLastName()); + $this->assertEquals($contact->getOrganization(), $newContact->getOrganization()); + $this->assertEquals($contact->getPhoneNumber(), $newContact->getPhoneNumber()); + $this->assertEquals($contact->getTitle(), $newContact->getTitle()); + $this->assertTrue(is_int($newContact->getID())); + + $newContact->setLastName("Swann"); + $newContact->setTitle("Queen"); + + $alteredContact = $this->getCommunicator()->edit($newContact); + $this->assertEquals(ProcessedContact::class, get_class($alteredContact)); + $this->assertEquals($newContact->getEmail(), $alteredContact->getEmail()); + $this->assertEquals($newContact->getFirstName(), $alteredContact->getFirstName()); + $this->assertEquals($newContact->getNotes(), $alteredContact->getNotes()); + $this->assertEquals($newContact->getLastName(), $alteredContact->getLastName()); + $this->assertEquals($newContact->getOrganization(), $alteredContact->getOrganization()); + $this->assertEquals($newContact->getPhoneNumber(), $alteredContact->getPhoneNumber()); + $this->assertEquals($newContact->getTitle(), $alteredContact->getTitle()); + $this->assertEquals($newContact->getID(), $alteredContact->getID()); + + $deletedContact = $this->getCommunicator()->remove($newContact); + $this->assertEquals(ProcessedContact::class, get_class($deletedContact)); + $this->assertEquals($newContact->getEmail(), $deletedContact->getEmail()); + $this->assertEquals($newContact->getFirstName(), $deletedContact->getFirstName()); + $this->assertEquals($newContact->getNotes(), $deletedContact->getNotes()); + $this->assertEquals($newContact->getLastName(), $deletedContact->getLastName()); + $this->assertEquals($newContact->getOrganization(), $deletedContact->getOrganization()); + $this->assertEquals($newContact->getPhoneNumber(), $deletedContact->getPhoneNumber()); + $this->assertEquals($newContact->getTitle(), $deletedContact->getTitle()); + $this->assertEquals($newContact->getID(), $deletedContact->getID()); + } + /** + * @group api + */ + public function testIsContactBookEmpty() + { + $contacts = RecipientFactory::createProcessedContactFromStdClassArray( + json_decode( + $this->getCommunicator()->get("api/contacts") + ) + ); + $this->assertEquals([], $contacts->getArrayCopy()); + } } diff --git a/tests/Recipient/ProcessedGroupTest.php b/tests/Recipient/ProcessedGroupTest.php index 52cc71b..22f598d 100644 --- a/tests/Recipient/ProcessedGroupTest.php +++ b/tests/Recipient/ProcessedGroupTest.php @@ -2,19 +2,38 @@ namespace IP1\RESTClient\Test\Recipient; -use PHPUnit\Framework\TestCase; +use IP1\RESTClient\Recipient\RecipientFactory; use IP1\RESTClient\Recipient\ProcessedGroup; +use IP1\RESTClient\Recipient\Group; +use IP1\RESTClient\Test\Core\AbstractEnviromentProvider; use IP1\RESTClient\Test\Util\Util; +use \DateTime; +use \DateTimeZone; +use PHPUnit\Framework\TestCase; -class ProcessedGroupTest extends TestCase +class ProcessedGroupTest extends AbstractEnviromentProvider { /** * @dataProvider getProcessedGroups */ - public function testGetters(ProcessedGroup $group) + public function testGetters($group) { $this->assertTrue(is_int($group->getID())); $this->assertTrue(0 < $group->getID()); + $this->assertEquals(\DateTime::class, get_class($group->getCreated())); + $this->assertEquals(\DateTime::class, get_class($group->getUpdated())); + $this->assertEquals($group->getCreated(), $group->getCreated(new \DateTimeZone("UTC"))); + $this->assertEquals($group->getUpdated(), $group->getUpdated(new \DateTimeZone("UTC"))); + if ($group->getCreated(new \DateTimeZone("Indian/Reunion")) !== $group->getCreated()) { + $this->addToAssertionCount(1); + } else { + $this->fail(); + } + if ($group->getUpdated(new \DateTimeZone("Indian/Reunion")) !== $group->getCreated()) { + $this->addToAssertionCount(1); + } else { + $this->fail(); + } } public static function getProcessedGroups(): array { @@ -30,4 +49,58 @@ class ProcessedGroupTest extends TestCase } return [$retval]; } + /** + * @group api + */ + public function testAPI() + { + for ($i=0; $i < 50; $i++) { + // + $group = new Group(Util::getRandomAlphaString(), Util::getRandomHex()); + $processedGroup = $this->addGroupToAPI($group); + + $processedGroup->setName(Util::getRandomAlphaString()); + $processedGroup->setColor(Util::getRandomHex()); + + $editedGroup = $this->editGroupToAPI($processedGroup); + $this->removeGroupToAPI($editedGroup); + } + } + public function addGroupToAPI(Group $group): ProcessedGroup + { + $processedGroup = $this->getCommunicator()->add($group); + $this->assertEquals($group->getName(), $processedGroup->getName()); + $this->assertEquals($group->getColor(), $processedGroup->getColor()); + $this->assertTrue(is_int($processedGroup->getID())); + $this->assertTrue(0 < $processedGroup->getID()); + + return $processedGroup; + } + public function editGroupToAPI(ProcessedGroup $processedGroup): ProcessedGroup + { + $editedGroup = $this->getCommunicator()->edit($processedGroup); + + $this->assertEquals($processedGroup->getName(), $editedGroup->getName()); + $this->assertEquals($processedGroup->getColor(), $editedGroup->getColor()); + if ($editedGroup->getUpdated() !== $processedGroup->getUpdated()) { + $this->addToAssertionCount(1); + } else { + $this->fail(); + } + $this->assertEquals($editedGroup->getCreated(), $processedGroup->getCreated()); + return $editedGroup; + } + public function removeGroupToAPI(ProcessedGroup $editedGroup): ProcessedGroup + { + $removedGroup = $this->getCommunicator()->remove($editedGroup); + $this->assertEquals($editedGroup->getID(), $removedGroup->getID()); + $this->assertEquals($editedGroup->getName(), $removedGroup->getName()); + $this->assertEquals($editedGroup->getColor(), $removedGroup->getColor()); + $this->assertEquals($editedGroup->getCreated(), $removedGroup->getCreated()); + $this->assertEquals($editedGroup->getUpdated(), $removedGroup->getUpdated()); + $this->assertEquals($editedGroup->getContacts(), $removedGroup->getContacts()); + $this->assertEquals($editedGroup->getMemberships(), $removedGroup->getMemberships()); + $this->assertEquals($editedGroup->memberShipsFetched(), $removedGroup->memberShipsFetched()); + $this->assertEquals($editedGroup->contactsFetched(), $removedGroup->contactsFetched()); + } } |