From 365cc3ee1f664bff89eaeca151b983e3a1907512 Mon Sep 17 00:00:00 2001 From: Benjamin Pick Date: Wed, 3 Jan 2018 11:14:05 +0100 Subject: [PATCH 1/6] Re-Order the array keys so that JSON will be an array, not an object --- lib/PayPal/Api/CartBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/PayPal/Api/CartBase.php b/lib/PayPal/Api/CartBase.php index 1f7ef1e8..86f1f20b 100644 --- a/lib/PayPal/Api/CartBase.php +++ b/lib/PayPal/Api/CartBase.php @@ -290,7 +290,7 @@ public function getPaymentOptions() */ public function setItemList($item_list) { - $this->item_list = $item_list; + $this->item_list = array_values($item_list); return $this; } From 9cca21756a0e76b5246f53f5924601b6a2e6b3c2 Mon Sep 17 00:00:00 2001 From: Benjamin Pick Date: Wed, 3 Jan 2018 11:40:25 +0100 Subject: [PATCH 2/6] Fix code ... --- lib/PayPal/Api/CartBase.php | 2 +- lib/PayPal/Api/ItemList.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/PayPal/Api/CartBase.php b/lib/PayPal/Api/CartBase.php index 86f1f20b..1f7ef1e8 100644 --- a/lib/PayPal/Api/CartBase.php +++ b/lib/PayPal/Api/CartBase.php @@ -290,7 +290,7 @@ public function getPaymentOptions() */ public function setItemList($item_list) { - $this->item_list = array_values($item_list); + $this->item_list = $item_list; return $this; } diff --git a/lib/PayPal/Api/ItemList.php b/lib/PayPal/Api/ItemList.php index 262047ab..63ff0543 100644 --- a/lib/PayPal/Api/ItemList.php +++ b/lib/PayPal/Api/ItemList.php @@ -27,7 +27,7 @@ class ItemList extends PayPalModel */ public function setItems($items) { - $this->items = $items; + $this->items = array_values($items); return $this; } From d5c585f65b9fa3bfa10df7ad5bac4d0758f361c1 Mon Sep 17 00:00:00 2001 From: Benjamin Pick Date: Tue, 9 Jan 2018 15:40:03 +0100 Subject: [PATCH 3/6] Fixing Unit Test: Items must be array --- tests/PayPal/Test/Api/ItemListTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PayPal/Test/Api/ItemListTest.php b/tests/PayPal/Test/Api/ItemListTest.php index e248c569..ce3adfe7 100644 --- a/tests/PayPal/Test/Api/ItemListTest.php +++ b/tests/PayPal/Test/Api/ItemListTest.php @@ -18,7 +18,7 @@ class ItemListTest extends TestCase */ public static function getJson() { - return '{"items":' . ItemTest::getJson() . ',"shipping_address":' . ShippingAddressTest::getJson() . ',"shipping_method":"TestSample","shipping_phone_number":"TestSample"}'; + return '{"items":[' . ItemTest::getJson() . '],"shipping_address":' . ShippingAddressTest::getJson() . ',"shipping_method":"TestSample","shipping_phone_number":"TestSample"}'; } /** From 1f1522436b45198af2cfabfc7b13fd0cdc2db5b4 Mon Sep 17 00:00:00 2001 From: Benjamin Pick Date: Wed, 10 Jan 2018 13:57:12 +0100 Subject: [PATCH 4/6] Fixing tests ... --- tests/PayPal/Test/Api/ItemListTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PayPal/Test/Api/ItemListTest.php b/tests/PayPal/Test/Api/ItemListTest.php index ce3adfe7..399cb7f6 100644 --- a/tests/PayPal/Test/Api/ItemListTest.php +++ b/tests/PayPal/Test/Api/ItemListTest.php @@ -53,7 +53,7 @@ public function testSerializationDeserialization() */ public function testGetters($obj) { - $this->assertEquals($obj->getItems(), ItemTest::getObject()); + $this->assertEquals($obj->getItems(), [ItemTest::getObject()]); $this->assertEquals($obj->getShippingAddress(), ShippingAddressTest::getObject()); $this->assertEquals($obj->getShippingMethod(), "TestSample"); $this->assertEquals($obj->getShippingPhoneNumber(), "TestSample"); From f5c5325ae8583d6365f06a66a81e145b043aa6ee Mon Sep 17 00:00:00 2001 From: Benjamin Pick Date: Wed, 10 Jan 2018 14:01:01 +0100 Subject: [PATCH 5/6] Fixing tests ... --- tests/PayPal/Test/Api/ItemListTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PayPal/Test/Api/ItemListTest.php b/tests/PayPal/Test/Api/ItemListTest.php index 399cb7f6..ebf4b3a4 100644 --- a/tests/PayPal/Test/Api/ItemListTest.php +++ b/tests/PayPal/Test/Api/ItemListTest.php @@ -53,7 +53,7 @@ public function testSerializationDeserialization() */ public function testGetters($obj) { - $this->assertEquals($obj->getItems(), [ItemTest::getObject()]); + $this->assertEquals($obj->getItems(), array(ItemTest::getObject())); $this->assertEquals($obj->getShippingAddress(), ShippingAddressTest::getObject()); $this->assertEquals($obj->getShippingMethod(), "TestSample"); $this->assertEquals($obj->getShippingPhoneNumber(), "TestSample"); From 1950b156efc0686224881e9601f3e07efa1651f8 Mon Sep 17 00:00:00 2001 From: Benjamin Pick Date: Wed, 10 Jan 2018 14:34:06 +0100 Subject: [PATCH 6/6] Adding a test that will fail with the current code --- tests/PayPal/Test/Api/ItemListTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/PayPal/Test/Api/ItemListTest.php b/tests/PayPal/Test/Api/ItemListTest.php index ebf4b3a4..3b07a940 100644 --- a/tests/PayPal/Test/Api/ItemListTest.php +++ b/tests/PayPal/Test/Api/ItemListTest.php @@ -2,6 +2,7 @@ namespace PayPal\Test\Api; +use PayPal\Api\Item; use PayPal\Api\ItemList; use PHPUnit\Framework\TestCase; @@ -58,4 +59,23 @@ public function testGetters($obj) $this->assertEquals($obj->getShippingMethod(), "TestSample"); $this->assertEquals($obj->getShippingPhoneNumber(), "TestSample"); } + + /** + * @depends testSerializationDeserialization + * @param ItemList $obj + */ + public function testAddRemove($obj) + { + $item2 = new Item(ItemTest::getJSON()); + $item2->setSku('TestSample2'); + $item3 = new Item(ItemTest::getJSON()); + $item3->setSku('TestSample3'); + $obj->addItem($item2); + $obj->addItem($item3); + $this->assertCount(3, $obj->getItems()); + $obj->removeItem($item2); + + $this->assertCount(2, $obj->getItems()); + $this->assertContains('"items":[', $obj->toJSON()); + } }