Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Re-Order the array keys so that JSON will be an array, not an object #1034

Merged
merged 6 commits into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/PayPal/Api/ItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ItemList extends PayPalModel
*/
public function setItems($items)
{
$this->items = $items;
$this->items = array_values($items);
return $this;
}

Expand Down
24 changes: 22 additions & 2 deletions tests/PayPal/Test/Api/ItemListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PayPal\Test\Api;

use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PHPUnit\Framework\TestCase;

Expand All @@ -18,7 +19,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"}';
}

/**
Expand Down Expand Up @@ -53,9 +54,28 @@ 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");
}

/**
* @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());
}
}