Merge pull request #1034 from benjaminpick/master

Re-Order the array keys so that JSON will be an array, not an object
This commit is contained in:
Jay
2018-02-14 15:07:34 -06:00
committed by GitHub
2 changed files with 23 additions and 3 deletions

View File

@@ -27,7 +27,7 @@ class ItemList extends PayPalModel
*/
public function setItems($items)
{
$this->items = $items;
$this->items = array_values($items);
return $this;
}

View File

@@ -2,6 +2,7 @@
namespace PayPal\Test\Api;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PHPUnit\Framework\TestCase;
@@ -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"}';
}
/**
@@ -53,9 +54,28 @@ class ItemListTest extends TestCase
*/
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());
}
}