From edac81cf74ec6e454d473e8626785c9627a2b4da Mon Sep 17 00:00:00 2001 From: Joshua Roe Date: Mon, 2 Mar 2015 17:18:44 -0800 Subject: [PATCH 1/2] Adding coupon delete methods --- src/Bigcommerce/Api/Client.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index a7d40ab9..f5390ef6 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -1041,6 +1041,27 @@ public static function updateCoupon($id, $object) return self::updateResource('/coupons/' . $id, $object); } + /** + * Delete the given coupon. + * + * @param int $id coupon id + * @return hash|bool|mixed + */ + public static function deleteCoupon($id) + { + return self::deleteResource('/coupons/' . $id); + } + + /** + * Delete all Coupons. + * + * @return hash|bool|mixed + */ + public static function deleteAllCoupons() + { + return self::deleteResource('/coupons'); + } + /** * The request logs with usage history statistics. */ From cf1ab880958d812b144e10aa6d100528f1a46c92 Mon Sep 17 00:00:00 2001 From: Joshua Roe Date: Tue, 3 Mar 2015 10:41:06 -0800 Subject: [PATCH 2/2] Adding some tests and a coupon getter --- src/Bigcommerce/Api/Client.php | 10 ++++++++++ test/Unit/Api/ClientTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Bigcommerce/Api/Client.php b/src/Bigcommerce/Api/Client.php index f5390ef6..7042bdb2 100644 --- a/src/Bigcommerce/Api/Client.php +++ b/src/Bigcommerce/Api/Client.php @@ -1005,6 +1005,16 @@ public static function updateSku($id, $object) return self::updateResource('/product/skus/' . $id, $object); } + /** + * Get a single coupon by given id. + * + * @param int $id customer id + * @return Coupon + */ + public static function getCoupon($id) + { + return self::getResource('/coupon/' . $id, 'Coupon'); + } /** * Get coupons diff --git a/test/Unit/Api/ClientTest.php b/test/Unit/Api/ClientTest.php index 1460aecc..405ce6e5 100644 --- a/test/Unit/Api/ClientTest.php +++ b/test/Unit/Api/ClientTest.php @@ -532,4 +532,33 @@ public function testDeletingACustomerDeletesToTheCustomerResource() Client::deleteCustomers(); } + + public function testDeletingAllCouponDeletesToTheCouponResource() + { + $this->connection->expects($this->once()) + ->method('delete') + ->with('/coupons'); + + Client::deleteAllCoupons(); + } + + public function testDeletingACouponDeletesToTheCouponResource() + { + $this->connection->expects($this->once()) + ->method('delete') + ->with('/coupons/1'); + + Client::deleteCoupon(1); + } + + public function testGettingASpecifiedCouponReturnsThatCoupon() + { + $this->connection->expects($this->once()) + ->method('get') + ->with('/coupon/1', false) + ->will($this->returnValue(array(array(), array()))); + + $resource = Client::getCoupon(1); + $this->assertInstanceOf('Bigcommerce\\Api\\Resources\\Coupon', $resource); + } }