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

Commit

Permalink
Merge pull request #1034 from benjaminpick/master
Browse files Browse the repository at this point in the history
Re-Order the array keys so that JSON will be an array, not an object
  • Loading branch information
jaypatel512 authored Feb 14, 2018
2 parents 619d89a + 1950b15 commit 263fe31
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
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());
}
}

0 comments on commit 263fe31

Please sign in to comment.