From 95c097bc7bf51f5b6718a8630b1a00a48643019e Mon Sep 17 00:00:00 2001 From: japatel Date: Thu, 4 Dec 2014 20:18:34 -0600 Subject: [PATCH] Auto-generated code for Webhooks API --- lib/PayPal/Api/Webhook.php | 321 +++++++++++++++ lib/PayPal/Api/WebhookEvent.php | 372 ++++++++++++++++++ lib/PayPal/Api/WebhookEventList.php | 149 +++++++ lib/PayPal/Api/WebhookEventType.php | 117 ++++++ lib/PayPal/Api/WebhookEventTypeList.php | 96 +++++ lib/PayPal/Api/WebhookList.php | 71 ++++ .../PayPal/Test/Api/WebhookEventListTest.php | 82 ++++ tests/PayPal/Test/Api/WebhookEventTest.php | 190 +++++++++ .../Test/Api/WebhookEventTypeListTest.php | 87 ++++ .../PayPal/Test/Api/WebhookEventTypeTest.php | 133 +++++++ tests/PayPal/Test/Api/WebhookListTest.php | 78 ++++ tests/PayPal/Test/Api/WebhookTest.php | 213 ++++++++++ 12 files changed, 1909 insertions(+) create mode 100644 lib/PayPal/Api/Webhook.php create mode 100644 lib/PayPal/Api/WebhookEvent.php create mode 100644 lib/PayPal/Api/WebhookEventList.php create mode 100644 lib/PayPal/Api/WebhookEventType.php create mode 100644 lib/PayPal/Api/WebhookEventTypeList.php create mode 100644 lib/PayPal/Api/WebhookList.php create mode 100644 tests/PayPal/Test/Api/WebhookEventListTest.php create mode 100644 tests/PayPal/Test/Api/WebhookEventTest.php create mode 100644 tests/PayPal/Test/Api/WebhookEventTypeListTest.php create mode 100644 tests/PayPal/Test/Api/WebhookEventTypeTest.php create mode 100644 tests/PayPal/Test/Api/WebhookListTest.php create mode 100644 tests/PayPal/Test/Api/WebhookTest.php diff --git a/lib/PayPal/Api/Webhook.php b/lib/PayPal/Api/Webhook.php new file mode 100644 index 0000000..fdaa559 --- /dev/null +++ b/lib/PayPal/Api/Webhook.php @@ -0,0 +1,321 @@ +id = $id; + return $this; + } + + /** + * Identifier of the webhook resource. + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Webhook notification endpoint url. + * + * @param string $url + * @throws \InvalidArgumentException + * @return $this + */ + public function setUrl($url) + { + UrlValidator::validate($url, "Url"); + $this->url = $url; + return $this; + } + + /** + * Webhook notification endpoint url. + * + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * List of Webhooks event-types. + * + * @param \PayPal\Api\WebhookEventType[] $event_types + * + * @return $this + */ + public function setEventTypes($event_types) + { + $this->event_types = $event_types; + return $this; + } + + /** + * List of Webhooks event-types. + * + * @return \PayPal\Api\WebhookEventType[] + */ + public function getEventTypes() + { + return $this->event_types; + } + + /** + * Append EventTypes to the list. + * + * @param \PayPal\Api\WebhookEventType $webhookEventType + * @return $this + */ + public function addEventType($webhookEventType) + { + if (!$this->getEventTypes()) { + return $this->setEventTypes(array($webhookEventType)); + } else { + return $this->setEventTypes( + array_merge($this->getEventTypes(), array($webhookEventType)) + ); + } + } + + /** + * Remove EventTypes from the list. + * + * @param \PayPal\Api\WebhookEventType $webhookEventType + * @return $this + */ + public function removeEventType($webhookEventType) + { + return $this->setEventTypes( + array_diff($this->getEventTypes(), array($webhookEventType)) + ); + } + + /** + * List of Webhooks event-types. + * + * @deprecated Instead use setEventTypes + * + * @param \PayPal\Api\WebhookEventType $event_types + * @return $this + */ + public function setEvent_types($event_types) + { + $this->event_types = $event_types; + return $this; + } + + /** + * List of Webhooks event-types. + * @deprecated Instead use getEventTypes + * + * @return \PayPal\Api\WebhookEventType + */ + public function getEvent_types() + { + return $this->event_types; + } + + /** + * Sets Links + * + * @param \PayPal\Api\Links[] $links + * + * @return $this + */ + public function setLinks($links) + { + $this->links = $links; + return $this; + } + + /** + * Gets Links + * + * @return \PayPal\Api\Links[] + */ + public function getLinks() + { + return $this->links; + } + + /** + * Append Links to the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function addLink($links) + { + if (!$this->getLinks()) { + return $this->setLinks(array($links)); + } else { + return $this->setLinks( + array_merge($this->getLinks(), array($links)) + ); + } + } + + /** + * Remove Links from the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function removeLink($links) + { + return $this->setLinks( + array_diff($this->getLinks(), array($links)) + ); + } + + /** + * Creates the Webhook for the application associated with the access token. + * + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return Webhook + */ + public function create($apiContext = null, $restCall = null) + { + $payLoad = $this->toJSON(); + $json = self::executeCall( + "/v1/notifications/webhooks", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + $this->fromJson($json); + return $this; + } + + /** + * Retrieves the Webhook identified by webhook_id for the application associated with access token. + * + * @param string $webhookId + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return Webhook + */ + public static function get($webhookId, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($webhookId, 'webhookId'); + $payLoad = ""; + $json = self::executeCall( + "/v1/notifications/webhooks/$webhookId", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new Webhook(); + $ret->fromJson($json); + return $ret; + } + + /** + * Retrieves all Webhooks for the application associated with access token. + * + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return WebhookList + */ + public static function getAll($apiContext = null, $restCall = null) + { + $payLoad = ""; + $json = self::executeCall( + "/v1/notifications/webhooks", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new WebhookList(); + $ret->fromJson($json); + return $ret; + } + + /** + * Updates the Webhook identified by webhook_id for the application associated with access token. + * + * @param PatchRequest $patchRequest + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return Webhook + */ + public function update($patchRequest, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($patchRequest, 'patchRequest'); + $payLoad = $patchRequest->toJSON(); + $json = self::executeCall( + "/v1/notifications/webhooks/{$this->getId()}", + "PATCH", + $payLoad, + null, + $apiContext, + $restCall + ); + $this->fromJson($json); + return $this; + } + + /** + * Deletes the Webhook identified by webhook_id for the application associated with access token. + * + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return bool + */ + public function delete($apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + $payLoad = ""; + self::executeCall( + "/v1/notifications/webhooks/{$this->getId()}", + "DELETE", + $payLoad, + null, + $apiContext, + $restCall + ); + return true; + } + +} diff --git a/lib/PayPal/Api/WebhookEvent.php b/lib/PayPal/Api/WebhookEvent.php new file mode 100644 index 0000000..44babde --- /dev/null +++ b/lib/PayPal/Api/WebhookEvent.php @@ -0,0 +1,372 @@ +id = $id; + return $this; + } + + /** + * Identifier of the Webhooks event resource. + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Time the resource was created. + * + * @param string $create_time + * + * @return $this + */ + public function setCreateTime($create_time) + { + $this->create_time = $create_time; + return $this; + } + + /** + * Time the resource was created. + * + * @return string + */ + public function getCreateTime() + { + return $this->create_time; + } + + /** + * Time the resource was created. + * + * @deprecated Instead use setCreateTime + * + * @param string $create_time + * @return $this + */ + public function setCreate_time($create_time) + { + $this->create_time = $create_time; + return $this; + } + + /** + * Time the resource was created. + * @deprecated Instead use getCreateTime + * + * @return string + */ + public function getCreate_time() + { + return $this->create_time; + } + + /** + * Name of the resource contained in resource element. + * + * @param string $resource_type + * + * @return $this + */ + public function setResourceType($resource_type) + { + $this->resource_type = $resource_type; + return $this; + } + + /** + * Name of the resource contained in resource element. + * + * @return string + */ + public function getResourceType() + { + return $this->resource_type; + } + + /** + * Name of the resource contained in resource element. + * + * @deprecated Instead use setResourceType + * + * @param string $resource_type + * @return $this + */ + public function setResource_type($resource_type) + { + $this->resource_type = $resource_type; + return $this; + } + + /** + * Name of the resource contained in resource element. + * @deprecated Instead use getResourceType + * + * @return string + */ + public function getResource_type() + { + return $this->resource_type; + } + + /** + * Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event. + * + * @param string $event_type + * + * @return $this + */ + public function setEventType($event_type) + { + $this->event_type = $event_type; + return $this; + } + + /** + * Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event. + * + * @return string + */ + public function getEventType() + { + return $this->event_type; + } + + /** + * Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event. + * + * @deprecated Instead use setEventType + * + * @param string $event_type + * @return $this + */ + public function setEvent_type($event_type) + { + $this->event_type = $event_type; + return $this; + } + + /** + * Name of the event type that occurred on resource, identified by data_resource element, to trigger the Webhooks event. + * @deprecated Instead use getEventType + * + * @return string + */ + public function getEvent_type() + { + return $this->event_type; + } + + /** + * A summary description of the event. E.g. A successful payment authorization was created for $$ + * + * @param string $summary + * + * @return $this + */ + public function setSummary($summary) + { + $this->summary = $summary; + return $this; + } + + /** + * A summary description of the event. E.g. A successful payment authorization was created for $$ + * + * @return string + */ + public function getSummary() + { + return $this->summary; + } + + /** + * This contains the resource that is identified by resource_type element. + * + * @param mixed $resource + * + * @return $this + */ + public function setResource($resource) + { + $this->resource = $resource; + return $this; + } + + /** + * This contains the resource that is identified by resource_type element. + * + * @return mixed + */ + public function getResource() + { + return $this->resource; + } + + /** + * Sets Links + * + * @param \PayPal\Api\Links[] $links + * + * @return $this + */ + public function setLinks($links) + { + $this->links = $links; + return $this; + } + + /** + * Gets Links + * + * @return \PayPal\Api\Links[] + */ + public function getLinks() + { + return $this->links; + } + + /** + * Append Links to the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function addLink($links) + { + if (!$this->getLinks()) { + return $this->setLinks(array($links)); + } else { + return $this->setLinks( + array_merge($this->getLinks(), array($links)) + ); + } + } + + /** + * Remove Links from the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function removeLink($links) + { + return $this->setLinks( + array_diff($this->getLinks(), array($links)) + ); + } + + /** + * Retrieves the Webhooks event resource identified by event_id. Can be used to retrieve the payload for an event. + * + * @param string $eventId + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return WebhookEvent + */ + public static function get($eventId, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($eventId, 'eventId'); + $payLoad = ""; + $json = self::executeCall( + "/v1/notifications/webhooks-events/$eventId", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new WebhookEvent(); + $ret->fromJson($json); + return $ret; + } + + /** + * Resends the Webhooks event resource identified by event_id. + * + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return WebhookEvent + */ + public function resend($apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + $payLoad = ""; + $json = self::executeCall( + "/v1/notifications/webhooks-events/{$this->getId()}/resend", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + $this->fromJson($json); + return $this; + } + + /** + * Retrieves the list of Webhooks events resources for the application associated with token. The developers can use it to see list of past webhooks events. + * + * @param array $params + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return WebhookEventList + */ + public static function all($params, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($params, 'params'); + $payLoad = ""; + $allowedParams = array( + 'page_size' => 1, + 'start_time' => 1, + 'end_time' => 1, + ); + $json = self::executeCall( + "/v1/notifications/webhooks-events" . "?" . http_build_query(array_intersect_key($params, $allowedParams)), + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new WebhookEventList(); + $ret->fromJson($json); + return $ret; + } + +} diff --git a/lib/PayPal/Api/WebhookEventList.php b/lib/PayPal/Api/WebhookEventList.php new file mode 100644 index 0000000..eae4da6 --- /dev/null +++ b/lib/PayPal/Api/WebhookEventList.php @@ -0,0 +1,149 @@ +events = $events; + return $this; + } + + /** + * A list of Webhooks event resources + * + * @return \PayPal\Api\WebhookEvent[] + */ + public function getEvents() + { + return $this->events; + } + + /** + * Append Events to the list. + * + * @param \PayPal\Api\WebhookEvent $webhookEvent + * @return $this + */ + public function addEvent($webhookEvent) + { + if (!$this->getEvents()) { + return $this->setEvents(array($webhookEvent)); + } else { + return $this->setEvents( + array_merge($this->getEvents(), array($webhookEvent)) + ); + } + } + + /** + * Remove Events from the list. + * + * @param \PayPal\Api\WebhookEvent $webhookEvent + * @return $this + */ + public function removeEvent($webhookEvent) + { + return $this->setEvents( + array_diff($this->getEvents(), array($webhookEvent)) + ); + } + + /** + * Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items. + * + * @param int $count + * + * @return $this + */ + public function setCount($count) + { + $this->count = $count; + return $this; + } + + /** + * Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items. + * + * @return int + */ + public function getCount() + { + return $this->count; + } + + /** + * Sets Links + * + * @param \PayPal\Api\Links[] $links + * + * @return $this + */ + public function setLinks($links) + { + $this->links = $links; + return $this; + } + + /** + * Gets Links + * + * @return \PayPal\Api\Links[] + */ + public function getLinks() + { + return $this->links; + } + + /** + * Append Links to the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function addLink($links) + { + if (!$this->getLinks()) { + return $this->setLinks(array($links)); + } else { + return $this->setLinks( + array_merge($this->getLinks(), array($links)) + ); + } + } + + /** + * Remove Links from the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function removeLink($links) + { + return $this->setLinks( + array_diff($this->getLinks(), array($links)) + ); + } + +} diff --git a/lib/PayPal/Api/WebhookEventType.php b/lib/PayPal/Api/WebhookEventType.php new file mode 100644 index 0000000..a3bf71a --- /dev/null +++ b/lib/PayPal/Api/WebhookEventType.php @@ -0,0 +1,117 @@ +name = $name; + return $this; + } + + /** + * Unique event-type name. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Human readable description of the event-type + * + * @param string $description + * + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * Human readable description of the event-type + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Retrieves the list of events-types subscribed by the given Webhook. + * + * @param string $webhookId + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return WebhookEventList + */ + public static function subscribedEventTypes($webhookId, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($webhookId, 'webhookId'); + $payLoad = ""; + $json = self::executeCall( + "/v1/notifications/webhooks/$webhookId/event-types", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new WebhookEventList(); + $ret->fromJson($json); + return $ret; + } + + /** + * Retrieves the master list of available Webhooks events-types resources for any webhook to subscribe to. + * + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return WebhookEventList + */ + public static function availableEventTypes($apiContext = null, $restCall = null) + { + $payLoad = ""; + $json = self::executeCall( + "/v1/notifications/webhooks-event-types", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new WebhookEventList(); + $ret->fromJson($json); + return $ret; + } + +} diff --git a/lib/PayPal/Api/WebhookEventTypeList.php b/lib/PayPal/Api/WebhookEventTypeList.php new file mode 100644 index 0000000..867db39 --- /dev/null +++ b/lib/PayPal/Api/WebhookEventTypeList.php @@ -0,0 +1,96 @@ +event_types = $event_types; + return $this; + } + + /** + * A list of Webhooks event-types + * + * @return \PayPal\Api\WebhookEventType[] + */ + public function getEventTypes() + { + return $this->event_types; + } + + /** + * Append EventTypes to the list. + * + * @param \PayPal\Api\WebhookEventType $webhookEventType + * @return $this + */ + public function addEventType($webhookEventType) + { + if (!$this->getEventTypes()) { + return $this->setEventTypes(array($webhookEventType)); + } else { + return $this->setEventTypes( + array_merge($this->getEventTypes(), array($webhookEventType)) + ); + } + } + + /** + * Remove EventTypes from the list. + * + * @param \PayPal\Api\WebhookEventType $webhookEventType + * @return $this + */ + public function removeEventType($webhookEventType) + { + return $this->setEventTypes( + array_diff($this->getEventTypes(), array($webhookEventType)) + ); + } + + /** + * A list of Webhooks event-types + * + * @deprecated Instead use setEventTypes + * + * @param \PayPal\Api\WebhookEventType $event_types + * @return $this + */ + public function setEvent_types($event_types) + { + $this->event_types = $event_types; + return $this; + } + + /** + * A list of Webhooks event-types + * @deprecated Instead use getEventTypes + * + * @return \PayPal\Api\WebhookEventType + */ + public function getEvent_types() + { + return $this->event_types; + } + +} diff --git a/lib/PayPal/Api/WebhookList.php b/lib/PayPal/Api/WebhookList.php new file mode 100644 index 0000000..c0aa129 --- /dev/null +++ b/lib/PayPal/Api/WebhookList.php @@ -0,0 +1,71 @@ +webhooks = $webhooks; + return $this; + } + + /** + * A list of Webhooks + * + * @return \PayPal\Api\Webhook[] + */ + public function getWebhooks() + { + return $this->webhooks; + } + + /** + * Append Webhooks to the list. + * + * @param \PayPal\Api\Webhook $webhook + * @return $this + */ + public function addWebhook($webhook) + { + if (!$this->getWebhooks()) { + return $this->setWebhooks(array($webhook)); + } else { + return $this->setWebhooks( + array_merge($this->getWebhooks(), array($webhook)) + ); + } + } + + /** + * Remove Webhooks from the list. + * + * @param \PayPal\Api\Webhook $webhook + * @return $this + */ + public function removeWebhook($webhook) + { + return $this->setWebhooks( + array_diff($this->getWebhooks(), array($webhook)) + ); + } + +} diff --git a/tests/PayPal/Test/Api/WebhookEventListTest.php b/tests/PayPal/Test/Api/WebhookEventListTest.php new file mode 100644 index 0000000..759735b --- /dev/null +++ b/tests/PayPal/Test/Api/WebhookEventListTest.php @@ -0,0 +1,82 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getEvents()); + $this->assertNotNull($obj->getCount()); + $this->assertNotNull($obj->getLinks()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEventList $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getEvents(), WebhookEventTest::getObject()); + $this->assertEquals($obj->getCount(), 123); + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEventList $obj + */ + public function testDeprecatedGetters($obj) + { + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEventList $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/WebhookEventTest.php b/tests/PayPal/Test/Api/WebhookEventTest.php new file mode 100644 index 0000000..d009203 --- /dev/null +++ b/tests/PayPal/Test/Api/WebhookEventTest.php @@ -0,0 +1,190 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getCreateTime()); + $this->assertNotNull($obj->getResourceType()); + $this->assertNotNull($obj->getEventType()); + $this->assertNotNull($obj->getSummary()); + $this->assertNotNull($obj->getResource()); + $this->assertNotNull($obj->getLinks()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEvent $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getCreateTime(), "TestSample"); + $this->assertEquals($obj->getResourceType(), "TestSample"); + $this->assertEquals($obj->getEventType(), "TestSample"); + $this->assertEquals($obj->getSummary(), "TestSample"); + $this->assertEquals($obj->getResource(), "TestSampleObject"); + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEvent $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getCreate_time(), "TestSample"); + $this->assertEquals($obj->getResource_type(), "TestSample"); + $this->assertEquals($obj->getEvent_type(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEvent $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Create_time + $obj->setCreateTime(null); + $this->assertNull($obj->getCreate_time()); + $this->assertNull($obj->getCreateTime()); + $this->assertSame($obj->getCreateTime(), $obj->getCreate_time()); + $obj->setCreate_time("TestSample"); + $this->assertEquals($obj->getCreate_time(), "TestSample"); + + // Check for Resource_type + $obj->setResourceType(null); + $this->assertNull($obj->getResource_type()); + $this->assertNull($obj->getResourceType()); + $this->assertSame($obj->getResourceType(), $obj->getResource_type()); + $obj->setResource_type("TestSample"); + $this->assertEquals($obj->getResource_type(), "TestSample"); + + // Check for Event_type + $obj->setEventType(null); + $this->assertNull($obj->getEvent_type()); + $this->assertNull($obj->getEventType()); + $this->assertSame($obj->getEventType(), $obj->getEvent_type()); + $obj->setEvent_type("TestSample"); + $this->assertEquals($obj->getEvent_type(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + /** + * @dataProvider mockProvider + * @param WebhookEvent $obj + */ + public function testGet($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + WebhookEventTest::getJson() + )); + + $result = $obj->get("eventId", $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param WebhookEvent $obj + */ + public function testResend($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + + $result = $obj->resend($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param WebhookEvent $obj + */ + public function testList($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + WebhookEventListTest::getJson() + )); + $params = array(); + + $result = $obj->all($params, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + + public function mockProvider() + { + $obj = self::getObject(); + $mockApiContext = $this->getMockBuilder('ApiContext') + ->disableOriginalConstructor() + ->getMock(); + return array( + array($obj, $mockApiContext), + array($obj, null) + ); + } +} diff --git a/tests/PayPal/Test/Api/WebhookEventTypeListTest.php b/tests/PayPal/Test/Api/WebhookEventTypeListTest.php new file mode 100644 index 0000000..b2cc342 --- /dev/null +++ b/tests/PayPal/Test/Api/WebhookEventTypeListTest.php @@ -0,0 +1,87 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getEventTypes()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEventTypeList $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getEventTypes(), WebhookEventTypeTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEventTypeList $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getEvent_types(), WebhookEventTypeTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEventTypeList $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Event_types + $obj->setEventTypes(null); + $this->assertNull($obj->getEvent_types()); + $this->assertNull($obj->getEventTypes()); + $this->assertSame($obj->getEventTypes(), $obj->getEvent_types()); + $obj->setEvent_types(WebhookEventTypeTest::getObject()); + $this->assertEquals($obj->getEvent_types(), WebhookEventTypeTest::getObject()); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/WebhookEventTypeTest.php b/tests/PayPal/Test/Api/WebhookEventTypeTest.php new file mode 100644 index 0000000..8144df7 --- /dev/null +++ b/tests/PayPal/Test/Api/WebhookEventTypeTest.php @@ -0,0 +1,133 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getName()); + $this->assertNotNull($obj->getDescription()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEventType $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getName(), "TestSample"); + $this->assertEquals($obj->getDescription(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEventType $obj + */ + public function testDeprecatedGetters($obj) + { + } + + /** + * @depends testSerializationDeserialization + * @param WebhookEventType $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + /** + * @dataProvider mockProvider + * @param WebhookEventType $obj + */ + public function testSubscribedEventTypes($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + WebhookEventListTest::getJson() + )); + + $result = $obj->subscribedEventTypes("webhookId", $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param WebhookEventType $obj + */ + public function testAvailableEventTypes($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + WebhookEventListTest::getJson() + )); + + $result = $obj->availableEventTypes($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + + public function mockProvider() + { + $obj = self::getObject(); + $mockApiContext = $this->getMockBuilder('ApiContext') + ->disableOriginalConstructor() + ->getMock(); + return array( + array($obj, $mockApiContext), + array($obj, null) + ); + } +} diff --git a/tests/PayPal/Test/Api/WebhookListTest.php b/tests/PayPal/Test/Api/WebhookListTest.php new file mode 100644 index 0000000..74ab8b6 --- /dev/null +++ b/tests/PayPal/Test/Api/WebhookListTest.php @@ -0,0 +1,78 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getWebhooks()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param WebhookList $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getWebhooks(), WebhookTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param WebhookList $obj + */ + public function testDeprecatedGetters($obj) + { + } + + /** + * @depends testSerializationDeserialization + * @param WebhookList $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/WebhookTest.php b/tests/PayPal/Test/Api/WebhookTest.php new file mode 100644 index 0000000..e849d77 --- /dev/null +++ b/tests/PayPal/Test/Api/WebhookTest.php @@ -0,0 +1,213 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getUrl()); + $this->assertNotNull($obj->getEventTypes()); + $this->assertNotNull($obj->getLinks()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param Webhook $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getUrl(), "http://www.google.com"); + $this->assertEquals($obj->getEventTypes(), WebhookEventTypeTest::getObject()); + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param Webhook $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getEvent_types(), WebhookEventTypeTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param Webhook $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Event_types + $obj->setEventTypes(null); + $this->assertNull($obj->getEvent_types()); + $this->assertNull($obj->getEventTypes()); + $this->assertSame($obj->getEventTypes(), $obj->getEvent_types()); + $obj->setEvent_types(WebhookEventTypeTest::getObject()); + $this->assertEquals($obj->getEvent_types(), WebhookEventTypeTest::getObject()); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Url is not a fully qualified URL + */ + public function testUrlValidationForUrl() + { + $obj = new Webhook(); + $obj->setUrl(null); + } + + /** + * @dataProvider mockProvider + * @param Webhook $obj + */ + public function testCreate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + + $result = $obj->create($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Webhook $obj + */ + public function testGet($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + WebhookTest::getJson() + )); + + $result = $obj->get("webhookId", $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Webhook $obj + */ + public function testGetAll($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + WebhookListTest::getJson() + )); + + $result = $obj->getAll($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Webhook $obj + */ + public function testUpdate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + $patchRequest = PatchRequestTest::getObject(); + + $result = $obj->update($patchRequest, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Webhook $obj + */ + public function testDelete($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + true + )); + + $result = $obj->delete($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + + public function mockProvider() + { + $obj = self::getObject(); + $mockApiContext = $this->getMockBuilder('ApiContext') + ->disableOriginalConstructor() + ->getMock(); + return array( + array($obj, $mockApiContext), + array($obj, null) + ); + } +}