From 8e0e15e3c244cb8c6d23df4dfdda88e593de29a3 Mon Sep 17 00:00:00 2001 From: Adena Internet Date: Thu, 8 Feb 2018 14:17:25 +0100 Subject: [PATCH 1/3] Create Mock system --- examples/MockExample.php | 41 ++++++++++ src/Mock.php | 149 ++++++++++++++++++++++++++++++++++++ src/Mock/acceptOrders.xml | 6 ++ src/Mock/addShipments.xml | 6 ++ src/Mock/cancelOrders.xml | 6 ++ src/Mock/deleteProducts.xml | 6 ++ src/Mock/finishOrders.xml | 6 ++ src/Mock/getFeedResult.xml | 15 ++++ src/Mock/getFeedStatus.xml | 7 ++ src/Mock/listOrders.xml | 60 +++++++++++++++ src/Mock/listProducts.xml | 80 +++++++++++++++++++ src/Mock/listShipments.xml | 37 +++++++++ src/Mock/rejectOrders.xml | 6 ++ src/Mock/updateProducts.xml | 6 ++ 14 files changed, 431 insertions(+) create mode 100644 examples/MockExample.php create mode 100644 src/Mock.php create mode 100644 src/Mock/acceptOrders.xml create mode 100644 src/Mock/addShipments.xml create mode 100644 src/Mock/cancelOrders.xml create mode 100644 src/Mock/deleteProducts.xml create mode 100644 src/Mock/finishOrders.xml create mode 100644 src/Mock/getFeedResult.xml create mode 100644 src/Mock/getFeedStatus.xml create mode 100644 src/Mock/listOrders.xml create mode 100644 src/Mock/listProducts.xml create mode 100644 src/Mock/listShipments.xml create mode 100644 src/Mock/rejectOrders.xml create mode 100644 src/Mock/updateProducts.xml diff --git a/examples/MockExample.php b/examples/MockExample.php new file mode 100644 index 0000000..3e906dc --- /dev/null +++ b/examples/MockExample.php @@ -0,0 +1,41 @@ + array( + array('OrderID' => '-- ORDER ID --') + ) + )); + $result = $client->acceptOrders($request); + + if ($result->hasFeeds()) { + foreach ($result->getFeeds() as $feed) { + var_dump($feed->getRequestID()); + } + } +} catch (Vleks\SDK\Exceptions\ClientException $clientException) { + var_dump($clientException->getMessage()); +} catch (Vleks\SDK\Exceptions\ServiceException $serviceException) { + var_dump($serviceException->getMessage()); +} \ No newline at end of file diff --git a/src/Mock.php b/src/Mock.php new file mode 100644 index 0000000..52cba07 --- /dev/null +++ b/src/Mock.php @@ -0,0 +1,149 @@ +invoke('listProducts')); + } + + /** + * Insert/Update products + * + * @param Vleks\SDK\Requests\UpdateProducts $request + * @return Vleks\SDK\Results\FeedStatus + */ + public function updateProducts($request) + { + return Results\FeedStatus::fromXML($this->invoke('updateProducts')); + } + + /** + * Delete products + * + * @param Vleks\SDK\Requests\DeleteProducts $request + * @return Vleks\SDK\Results\FeedStatus + */ + public function deleteProducts($request) + { + return Results\FeedStatus::fromXML($this->invoke('deleteProducts')); + } + + /** + * Get statusses of requested feeds (changes) + * + * @param Vleks\SDK\Requests\FeedStatus $request + * @return Vleks\SDK\Results\FeedStatus + */ + public function getFeedStatus($request) + { + return Results\FeedStatus::fromXML($this->invoke('getFeedStatus')); + } + + /** + * Get results of requested feeds (changes) + * + * @param Vleks\SDK\Requests\FeedResult $request + * @return Vleks\SDK\Results\FeedResult + */ + public function getFeedResult($request) + { + return Results\FeedResult::fromXML($this->invoke('getFeedResult')); + } + + /** + * List Orders + * + * @param Vleks\SDK\Requests\ListOrders $request + * @return Vleks\SDK\Results\ListOrders + */ + public function listOrders($request) + { + return Results\ListOrders::fromXML($this->invoke('listOrders')); + } + + /** + * Reject Orders + * + * @param Vleks\SDK\Requests\RejectOrders $request + * @param Vleks\SDK\Results\FeedStatus + */ + public function rejectOrders($request) + { + return Results\FeedStatus::fromXML($this->invoke('rejectOrders')); + } + + /** + * Accept Orders + * + * @param Vleks\SDK\Requests\AcceptOrders $request + * @param Vleks\SDK\Results\FeedStatus + */ + public function acceptOrders($request) + { + return Results\FeedStatus::fromXML($this->invoke('acceptOrders')); + } + + /** + * Cancel Orders + * + * @param Vleks\SDK\Requests\CancelOrders $request + * @param Vleks\SDK\Results\FeedStatus + */ + public function cancelOrders($request) + { + return Results\FeedStatus::fromXML($this->invoke('cancelOrders')); + } + + /** + * Finish Orders + * + * @param Vleks\SDK\Requests\FinishOrders $request + * @param Vleks\SDK\Results\FeedStatus + */ + public function finishOrders($request) + { + return Results\FeedStatus::fromXML($this->invoke('finishOrders')); + } + + /** + * List Shipments + * + * @param Vleks\SDK\Requests\ListShipments $request + * @return Vleks\SDK\Results\ListShipments + */ + public function listShipments($request) + { + return Results\ListShipments::fromXML($this->invoke('listShipments')); + } + + /** + * Add Shipments + * + * @param Vleks\SDK\Requests\AddShipments $request + * @return Vleks\SDK\Results\FeedStatus + */ + public function addShipments($request) + { + return Results\FeedStatus::fromXML($this->invoke('addShipments')); + } + + /** + * Load required response files + * + * @param string $actionName + * @return string + */ + private function invoke($actionName) + { + return file_get_contents('Mock/' . $actionName . '.xml', true); + } +} diff --git a/src/Mock/acceptOrders.xml b/src/Mock/acceptOrders.xml new file mode 100644 index 0000000..0dbc7d1 --- /dev/null +++ b/src/Mock/acceptOrders.xml @@ -0,0 +1,6 @@ + + + + ********-****-****-****-************ + + diff --git a/src/Mock/addShipments.xml b/src/Mock/addShipments.xml new file mode 100644 index 0000000..0dbc7d1 --- /dev/null +++ b/src/Mock/addShipments.xml @@ -0,0 +1,6 @@ + + + + ********-****-****-****-************ + + diff --git a/src/Mock/cancelOrders.xml b/src/Mock/cancelOrders.xml new file mode 100644 index 0000000..0dbc7d1 --- /dev/null +++ b/src/Mock/cancelOrders.xml @@ -0,0 +1,6 @@ + + + + ********-****-****-****-************ + + diff --git a/src/Mock/deleteProducts.xml b/src/Mock/deleteProducts.xml new file mode 100644 index 0000000..0dbc7d1 --- /dev/null +++ b/src/Mock/deleteProducts.xml @@ -0,0 +1,6 @@ + + + + ********-****-****-****-************ + + diff --git a/src/Mock/finishOrders.xml b/src/Mock/finishOrders.xml new file mode 100644 index 0000000..0dbc7d1 --- /dev/null +++ b/src/Mock/finishOrders.xml @@ -0,0 +1,6 @@ + + + + ********-****-****-****-************ + + diff --git a/src/Mock/getFeedResult.xml b/src/Mock/getFeedResult.xml new file mode 100644 index 0000000..ef1bb9f --- /dev/null +++ b/src/Mock/getFeedResult.xml @@ -0,0 +1,15 @@ + + + + Success + 5304MS + DS25634 + Product with SKU "5304MS" processed. + + + Success + 5304MSA + B056951 + Product with SKU "5304MSA" processed. + + diff --git a/src/Mock/getFeedStatus.xml b/src/Mock/getFeedStatus.xml new file mode 100644 index 0000000..06e7c9a --- /dev/null +++ b/src/Mock/getFeedStatus.xml @@ -0,0 +1,7 @@ + + + + ********-****-****-****-************ + DONE + + diff --git a/src/Mock/listOrders.xml b/src/Mock/listOrders.xml new file mode 100644 index 0000000..b8bce1e --- /dev/null +++ b/src/Mock/listOrders.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Mock/listProducts.xml b/src/Mock/listProducts.xml new file mode 100644 index 0000000..e2a18d2 --- /dev/null +++ b/src/Mock/listProducts.xml @@ -0,0 +1,80 @@ + + + + B0009ML + + B00001G + + true + 21 + GOOD + 24 + 48 + 5304MS + + 8711871037386 + 8711871037387 + 8711871037388 + 8711871037389 + 8711871037380 + + Minuet Santhee Theepot + Bredemeijer + Theepot + De Bredemeijer Minuet Santhee serie is een prachtige elegante serie van dit theepotten merk. De theepotten uit deze serie zijn praktisch, modern en elegant. Wat verlangt u nog meer van een theepot? De Bredemeijer Minuet theepotten zijn allen vaatwasserbestendig. Dit maakt de theepot nog praktischer. Dit is de kleine 0,5 liter theepot. Ideaal voor een kopje thee tussendoor. + + EUR + 25 + + + EUR + 2 + + + 10.56 + + + EUR + 4 + 10.56 + + + EUR + 5 + 10.56 + + + 10.00 + + + EUR + 40 + + + EUR + 150 + + + EUR + 47.95 + + + EUR + 45.5 + + + + B000009 + 10 + + + B00000N + 7 + + + 117 + 183 + 182 + 449 + + \ No newline at end of file diff --git a/src/Mock/listShipments.xml b/src/Mock/listShipments.xml new file mode 100644 index 0000000..5081400 --- /dev/null +++ b/src/Mock/listShipments.xml @@ -0,0 +1,37 @@ + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/src/Mock/rejectOrders.xml b/src/Mock/rejectOrders.xml new file mode 100644 index 0000000..0dbc7d1 --- /dev/null +++ b/src/Mock/rejectOrders.xml @@ -0,0 +1,6 @@ + + + + ********-****-****-****-************ + + diff --git a/src/Mock/updateProducts.xml b/src/Mock/updateProducts.xml new file mode 100644 index 0000000..0dbc7d1 --- /dev/null +++ b/src/Mock/updateProducts.xml @@ -0,0 +1,6 @@ + + + + ********-****-****-****-************ + + From 5a1b6b908db337da1b0215c468a9212f357ab6d1 Mon Sep 17 00:00:00 2001 From: Adena Internet Date: Thu, 8 Feb 2018 16:11:41 +0100 Subject: [PATCH 2/3] Add Count endpoints --- src/Client.php | 72 +++++++++++++++ src/Entities/Count.php | 31 +++++++ src/Mock.php | 158 +++++++++++++++++++++++++++++++++ src/Mock/countOrders.xml | 6 ++ src/Mock/countProducts.xml | 6 ++ src/Requests/CountOrders.php | 83 +++++++++++++++++ src/Requests/CountProducts.php | 22 +++++ src/Requests/ListOrders.php | 13 +-- src/Results/CountOrders.php | 112 +++++++++++++++++++++++ src/Results/CountProducts.php | 112 +++++++++++++++++++++++ tests/ClientTest.php | 74 ++++++++++++++- tests/EntityTest.php | 11 +++ 12 files changed, 687 insertions(+), 13 deletions(-) create mode 100644 src/Entities/Count.php create mode 100644 src/Mock.php create mode 100644 src/Mock/countOrders.xml create mode 100644 src/Mock/countProducts.xml create mode 100644 src/Requests/CountOrders.php create mode 100644 src/Requests/CountProducts.php create mode 100644 src/Results/CountOrders.php create mode 100644 src/Results/CountProducts.php diff --git a/src/Client.php b/src/Client.php index c266f9a..a386814 100644 --- a/src/Client.php +++ b/src/Client.php @@ -56,6 +56,25 @@ public function listProducts($request) return $result; } + /** + * Count Products + * + * @param Vleks\SDK\Requests\CountProducts $request + * @return Vleks\SDK\Results\CountProducts + */ + public function countProducts($request) + { + if (!$request instanceof Requests\CountProducts) { + $request = new Requests\CountProducts($request); + } + + $response = $this->invoke($this->convertCountProductsRequest($request)); + $result = Results\CountProducts::fromXML($response['ResponseBody']); + $result->setResponseHeaders($response['ResponseHeaders']); + + return $result; + } + /** * Insert/Update products * @@ -150,6 +169,25 @@ public function listOrders($request) return $result; } + + /** + * Count Orders + * + * @param Vleks\SDK\Requests\CountOrders $request + * @return Vleks\SDK\Results\CountOrders + */ + public function countOrders($request) + { + if (!$request instanceof Requests\CountOrders) { + $request = new Requests\CountOrders($request); + } + + $response = $this->invoke($this->convertCountOrdersRequest($request)); + $result = Results\CountOrders::fromXML($response['ResponseBody']); + $result->setResponseHeaders($response['ResponseHeaders']); + + return $result; + } /** * Reject Orders @@ -269,6 +307,19 @@ public function addShipments($request) # INFORMATION CONVERTION METHODS ############################################################################ + private function convertCountProductsRequest($request) + { + $messageHeaders = array ( + 'Entity' => 'Product', + 'Action' => 'Count' + ); + + return array( + self::MESSAGE_HEADERS => $messageHeaders, + self::MESSAGE_BODY => null + ); + } + private function convertListProductsRequest($request) { $messageContent = array (); @@ -368,6 +419,23 @@ private function convertFeedResultRequest($request) self::MESSAGE_BODY => $messageContent ); } + + private function convertCountOrdersRequest($request) + { + $messageHeaders = array ( + 'Entity' => 'Order', + 'Action' => 'Count' + ); + + if ($request->hasPeriod()) { + $messageHeaders['Period'] = $request->getPeriod(); + } + + return array( + self::MESSAGE_HEADERS => $messageHeaders, + self::MESSAGE_BODY => null + ); + } private function convertListOrdersRequest($request) { @@ -384,6 +452,10 @@ private function convertListOrdersRequest($request) $messageHeaders['Offset'] = $request->getOffset(); } + if ($request->hasPeriod()) { + $messageHeaders['Period'] = $request->getPeriod(); + } + return array( self::MESSAGE_HEADERS => $messageHeaders, self::MESSAGE_BODY => null diff --git a/src/Entities/Count.php b/src/Entities/Count.php new file mode 100644 index 0000000..7582042 --- /dev/null +++ b/src/Entities/Count.php @@ -0,0 +1,31 @@ +fields = array ( + 'Result' => array ('value' => null, 'type' => 'int') + ); + + parent::__construct($data); + } + + public function setResult ($value) + { + $this->fields['Result']['value'] = $value; + return $this; + } + + public function getResult () + { + return $this->fields['Result']['value']; + } + + public function hasResult () + { + return !is_null($this->fields['Result']['value']); + } +} diff --git a/src/Mock.php b/src/Mock.php new file mode 100644 index 0000000..3df3c95 --- /dev/null +++ b/src/Mock.php @@ -0,0 +1,158 @@ +invoke('listProducts')); + } + /** + * Insert/Update products + * + * @param Vleks\SDK\Requests\UpdateProducts $request + * @return Vleks\SDK\Results\FeedStatus + */ + public function updateProducts($request) + { + return Results\FeedStatus::fromXML($this->invoke('updateProducts')); + } + /** + * Delete products + * + * @param Vleks\SDK\Requests\DeleteProducts $request + * @return Vleks\SDK\Results\FeedStatus + */ + public function deleteProducts($request) + { + return Results\FeedStatus::fromXML($this->invoke('deleteProducts')); + } + /** + * Get statusses of requested feeds (changes) + * + * @param Vleks\SDK\Requests\FeedStatus $request + * @return Vleks\SDK\Results\FeedStatus + */ + public function getFeedStatus($request) + { + return Results\FeedStatus::fromXML($this->invoke('getFeedStatus')); + } + /** + * Get results of requested feeds (changes) + * + * @param Vleks\SDK\Requests\FeedResult $request + * @return Vleks\SDK\Results\FeedResult + */ + public function getFeedResult($request) + { + return Results\FeedResult::fromXML($this->invoke('getFeedResult')); + } + /** + * List Orders + * + * @param Vleks\SDK\Requests\ListOrders $request + * @return Vleks\SDK\Results\ListOrders + */ + public function listOrders($request) + { + return Results\ListOrders::fromXML($this->invoke('listOrders')); + } + /** + * Reject Orders + * + * @param Vleks\SDK\Requests\RejectOrders $request + * @param Vleks\SDK\Results\FeedStatus + */ + public function rejectOrders($request) + { + return Results\FeedStatus::fromXML($this->invoke('rejectOrders')); + } + /** + * Accept Orders + * + * @param Vleks\SDK\Requests\AcceptOrders $request + * @param Vleks\SDK\Results\FeedStatus + */ + public function acceptOrders($request) + { + return Results\FeedStatus::fromXML($this->invoke('acceptOrders')); + } + /** + * Cancel Orders + * + * @param Vleks\SDK\Requests\CancelOrders $request + * @param Vleks\SDK\Results\FeedStatus + */ + public function cancelOrders($request) + { + return Results\FeedStatus::fromXML($this->invoke('cancelOrders')); + } + /** + * Finish Orders + * + * @param Vleks\SDK\Requests\FinishOrders $request + * @param Vleks\SDK\Results\FeedStatus + */ + public function finishOrders($request) + { + return Results\FeedStatus::fromXML($this->invoke('finishOrders')); + } + /** + * List Shipments + * + * @param Vleks\SDK\Requests\ListShipments $request + * @return Vleks\SDK\Results\ListShipments + */ + public function listShipments($request) + { + return Results\ListShipments::fromXML($this->invoke('listShipments')); + } + /** + * Add Shipments + * + * @param Vleks\SDK\Requests\AddShipments $request + * @return Vleks\SDK\Results\FeedStatus + */ + public function addShipments($request) + { + return Results\FeedStatus::fromXML($this->invoke('addShipments')); + } + + /** + * Count Products + * + * @param Vleks\SDK\Requests\CountProducts $request + * @return Vleks\SDK\Results\CountProducts + */ + public function countProducts($request) + { + return Results\CountProducts::fromXML($this->invoke('countProducts')); + } + + /** + * Count Orders + * + * @param Vleks\SDK\Requests\CountOrders $request + * @return Vleks\SDK\Results\CountOrders + */ + public function countOrders($request) + { + return Results\CountOrders::fromXML($this->invoke('countOrders')); + } + + /** + * Load required response files + * + * @param string $actionName + * @return string + */ + private function invoke($actionName) + { + return file_get_contents('Mock/' . $actionName . '.xml', true); + } +} \ No newline at end of file diff --git a/src/Mock/countOrders.xml b/src/Mock/countOrders.xml new file mode 100644 index 0000000..58a2cc8 --- /dev/null +++ b/src/Mock/countOrders.xml @@ -0,0 +1,6 @@ + + + + 4 + + \ No newline at end of file diff --git a/src/Mock/countProducts.xml b/src/Mock/countProducts.xml new file mode 100644 index 0000000..6767941 --- /dev/null +++ b/src/Mock/countProducts.xml @@ -0,0 +1,6 @@ + + + + 2 + + \ No newline at end of file diff --git a/src/Requests/CountOrders.php b/src/Requests/CountOrders.php new file mode 100644 index 0000000..a27dee0 --- /dev/null +++ b/src/Requests/CountOrders.php @@ -0,0 +1,83 @@ +fields = array ( + 'Period' => array ('value' => null, 'type' => 'string') + ); + + parent::__construct($data); + } + + /** + * Sets the value of the Period property + * + * @param int $value + * @return this instance + */ + public function setPeriod($value) + { + if (preg_match ('/\//', $value)) { + + # Seperate the datetimes + $dates = explode('/', $value); + + # Set the current date + $current_time = strtotime('now'); + + # Set the start date + $start_time = strtotime($dates[0]); + + # Set the end date + $end_time = strtotime($dates[1]); + + # Set the time of the start time + 31 days + $start_time_plus_one_month = strtotime("+31 days", $start_time); + + if ( + ($start_time < $end_time) && + ($end_time < $current_time) && + ($end_time < $start_time_plus_one_month) + ) { + $this->fields['Period']['value'] = $value; + return $this; + } else { + throw new Exceptions\ClientException('Given period is out of bounds.'); + } + } else { + throw new Exceptions\ClientException('Given period uses "/" as delimiter.'); + } + } + + /** + * Gets the value of the Period property + * + * @return mixed Period property value + */ + public function getPeriod() + { + return $this->fields['Period']['value']; + } + + /** + * Checks if the Period property has been set + * + * @return bool True if the Period property has been set, false otherwise + */ + public function hasPeriod() + { + return !is_null($this->fields['Period']['value']); + } + +} diff --git a/src/Requests/CountProducts.php b/src/Requests/CountProducts.php new file mode 100644 index 0000000..3055887 --- /dev/null +++ b/src/Requests/CountProducts.php @@ -0,0 +1,22 @@ +fields = array ( + + ); + + parent::__construct($data); + } +} diff --git a/src/Requests/ListOrders.php b/src/Requests/ListOrders.php index 0221917..23d7d02 100644 --- a/src/Requests/ListOrders.php +++ b/src/Requests/ListOrders.php @@ -128,18 +128,7 @@ public function setPeriod($value) } else { throw new Exceptions\ClientException('Given period is out of bounds.'); } - - // $dates = explode ('/', $value); - // $start_date = strtotime ($dates[0]); - // $end_date = strtotime ($dates[1]); - // $now = strtotime ('now'); - // if ($start_date < $end_date && $now > $end_date && $end_date < strtotime ($start_date. "+31 days")) { - // $this->fields['Period']['value'] = $value; - // return $this; - // } else { - // throw new Exceptions\ClientException('Given period is out of bounds.'); - // } - + } else { throw new Exceptions\ClientException('Given period uses "/" as delimiter.'); } diff --git a/src/Results/CountOrders.php b/src/Results/CountOrders.php new file mode 100644 index 0000000..1ee3a33 --- /dev/null +++ b/src/Results/CountOrders.php @@ -0,0 +1,112 @@ +fields = array ( + 'Count' => array ('value' => null, 'type' => Count::class), + 'ResponseHeaders' => array ('value' => array (), 'type' => 'array') + ); + + parent::__construct($data); + } + + /** + * Construct new Vleks\SDK\Results\ListOrders from XML string + * + * @param string $xml + * @return object Vleks\SDK\Results\CountOrders + * @throws Vleks\SDK\Exceptions\ClientException + */ + public static function fromXML($xml) + { + $dom = new DOMDocument(); + $dom->loadXML($xml); + + $xpath = new DOMXPath($dom); + $response = $xpath->query('//VleksResponse'); + + if (1 === $response->length) { + return new CountOrders($response->item(0)); + } else { + throw new ClientException('Unable to construct CountOrder response from provided XML.'); + } + } + + /** + * Sets the value of the Count property + * + * @param array $value + * @return this instance + */ + public function setCount($value) + { + $this->fields['Count']['value'] = (int) $value; + return $this; + } + + /** + * Gets the value of the Count property + * + * @return array Product property value + */ + public function getCount() + { + return $this->fields['Count']['value']; + } + + /** + * Checks if the Count property has been set + * + * @return bool True if the Product property has been set, false otherwise + */ + public function hasCount() + { + return !is_null($this->fields['Count']['value']); + } + + /** + * Sets the ResponseHeaders property + * + * @param array $value + * @return this instance + */ + public function setResponseHeaders(array $value) + { + $this->fields['ResponseHeaders']['value'] = $value; + return $this; + } + + /** + * Gets the value of the ResponseHeaders property + * + * @return array ResponseHeaders property value + */ + public function getResponseHeaders() + { + return $this->fields['ResponseHeaders']['value']; + } + + /** + * Checks if the ResponseHeaders property had been set + * + * @return bool True if the ResponseHeaders property has been set, false otherwise + */ + public function hasResponseHeaders() + { + return !empty($this->fields['ResponseHeaders']['value']); + } +} diff --git a/src/Results/CountProducts.php b/src/Results/CountProducts.php new file mode 100644 index 0000000..a0835af --- /dev/null +++ b/src/Results/CountProducts.php @@ -0,0 +1,112 @@ +fields = array ( + 'Count' => array ('value' => null, 'type' => Count::class), + 'ResponseHeaders' => array ('value' => array (), 'type' => 'array') + ); + + parent::__construct($data); + } + + /** + * Construct new Vleks\SDK\Results\ListProducts from XML string + * + * @param string $xml + * @return object Vleks\SDK\Results\CountProducts + * @throws Vleks\SDK\Exceptions\ClientException + */ + public static function fromXML($xml) + { + $dom = new DOMDocument(); + $dom->loadXML($xml); + + $xpath = new DOMXPath($dom); + $response = $xpath->query('//VleksResponse'); + + if (1 === $response->length) { + return new CountProducts($response->item(0)); + } else { + throw new ClientException('Unable to construct CountProducts response from provided XML.'); + } + } + + /** + * Sets the value of the Count property + * + * @param array $value + * @return this instance + */ + public function setCount($value) + { + $this->fields['Count']['value'] = (int) $value; + return $this; + } + + /** + * Gets the value of the Count property + * + * @return array Product property value + */ + public function getCount() + { + return $this->fields['Count']['value']; + } + + /** + * Checks if the Count property has been set + * + * @return bool True if the Product property has been set, false otherwise + */ + public function hasCount() + { + return !is_null($this->fields['Count']['value']); + } + + /** + * Sets the ResponseHeaders property + * + * @param array $value + * @return this instance + */ + public function setResponseHeaders(array $value) + { + $this->fields['ResponseHeaders']['value'] = $value; + return $this; + } + + /** + * Gets the value of the ResponseHeaders property + * + * @return array ResponseHeaders property value + */ + public function getResponseHeaders() + { + return $this->fields['ResponseHeaders']['value']; + } + + /** + * Checks if the ResponseHeaders property had been set + * + * @return bool True if the ResponseHeaders property has been set, false otherwise + */ + public function hasResponseHeaders() + { + return !empty($this->fields['ResponseHeaders']['value']); + } +} diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 43ea479..a09549e 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -271,6 +271,78 @@ public function testFeedResults() $this->assertEquals(count($result->getFeeds()), 2); $this->assertEquals($result->getFeeds()[0]->getRequestID(), $request->getFeeds()[0]->getRequestID()); } + + public function testCountOrdersOptions() + { + $exceptionThrown = false; + $request = new Requests\CountOrders(); + + try { + $request->setPeriod('01-01-2018/02-02-2018'); + } catch (Exceptions\ClientException $clientException) { + $exceptionThrown = true; + } + + $this->assertTrue($exceptionThrown); + $exceptionThrown = false; + + try { + $request->setPeriod('2018-01-30T09:00:00/2018-02-31T10:00:00'); + } catch (Exceptions\ClientException $clientException) { + $exceptionThrown = true; + } + + $this->assertTrue($exceptionThrown); + $exceptionThrown = false; + + try { + $request = new Requests\CountOrders(array('Period' => '01-01-2018/02-02-2018')); + } catch (Exceptions\ClientException $clientException) { + $exceptionThrown = true; + } + + $this->assertTrue($exceptionThrown); + $exceptionThrown = false; + + try { + $request = new Requests\CountOrders(array('Period' => '2018-01-30T09:00:00/2018-02-31T10:00:00')); + } catch (Exceptions\ClientException $clientException) { + $exceptionThrown = true; + } + + $this->assertTrue($exceptionThrown); + } + + public function testCountOrders() + { + $request = new Requests\CountOrders(array ('Period' => '2018-01-02T09:00:00/2018-02-01T10:00:00')); + $result = $this->client->countOrders($request); + $count = $result->getCount(); + + $this->assertInstanceOf(Requests\CountOrders::class, $request); + $this->assertInstanceOf(Results\CountOrders::class, $result); + $this->assertTrue($count->hasResult()); + + $request = new Requests\CountOrders(array ('Period' => '2010-01-02T09:00:00/2010-02-01T10:00:00')); + $result = $this->client->countOrders($request); + $count = $result->getCount(); + + $this->assertInstanceOf(Requests\CountOrders::class, $request); + $this->assertInstanceOf(Results\CountOrders::class, $result); + $this->assertTrue($count->hasResult()); + $this->assertEquals($count->getResult(), 0); + } + + public function testCountProducts() + { + $request = new Requests\CountProducts(); + $result = $this->client->countProducts($request); + $count = $result->getCount(); + + $this->assertInstanceOf(Requests\CountProducts::class, $request); + $this->assertInstanceOf(Results\CountProducts::class, $result); + $this->assertTrue($count->hasResult()); + } public function testListOrdersOptions() { @@ -315,7 +387,7 @@ public function testListOrdersOptions() public function testListOrders() { - $request = new Requests\listOrders(array ('Period' => '2018-01-30T09:00:00/2018-02-01T10:00:00')); + $request = new Requests\listOrders(array ('Period' => '2018-01-03T09:00:00/2018-02-01T10:00:00')); $result = $this->client->listOrders($request); $firstSet = array (); $lastSet = array (); diff --git a/tests/EntityTest.php b/tests/EntityTest.php index b8490cd..45e5392 100644 --- a/tests/EntityTest.php +++ b/tests/EntityTest.php @@ -152,6 +152,17 @@ public function testFeedResult() $this->entityTestLoop($entity, $individual_fields, $entity_fields); } + public function testCount() + { + $entity = Entities\Count::class; + + $individual_fields = array( + 'Result' => 5 + ); + + $this->entityTestLoop($entity, $individual_fields); + } + public function testOrder() { $entity = Entities\Order::class; From 9fe2f016da398f22b762f97d195ace5259353b1b Mon Sep 17 00:00:00 2001 From: Adena Internet Date: Thu, 8 Feb 2018 16:24:03 +0100 Subject: [PATCH 3/3] Bumped version to 2.1.0 --- composer.json | 2 +- src/Client.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 70502c3..9a4bd9d 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "vleks/sdk", "description": "A PHP client SDK for the Vleks.com API", - "version": "2.0.0", + "version": "2.1.0", "type": "library", "keywords": ["api", "sdk", "vleks", "vleks.com"], "homepage": "https://www.vleks.com", diff --git a/src/Client.php b/src/Client.php index c211355..80b3066 100644 --- a/src/Client.php +++ b/src/Client.php @@ -7,7 +7,7 @@ class Client { - const VERSION = '2.0.0'; + const VERSION = '2.1.0'; const ENDPOINT = 'https://%s/api/vleks/2017-05/'; const MESSAGE_HEADERS = 'HEADERS'; const MESSAGE_BODY = 'BODY'; @@ -169,7 +169,7 @@ public function listOrders($request) return $result; } - + /** * Count Orders * @@ -319,7 +319,7 @@ private function convertCountProductsRequest($request) self::MESSAGE_BODY => null ); } - + private function convertListProductsRequest($request) { $messageContent = array (); @@ -419,7 +419,7 @@ private function convertFeedResultRequest($request) self::MESSAGE_BODY => $messageContent ); } - + private function convertCountOrdersRequest($request) { $messageHeaders = array (