/**
  * Inject data from the quote into the quantity request
  * payload.
  *
  * @return self
  */
 protected function _populatePayload()
 {
     $itemIterable = $this->_quantityPayload->getQuantityItems();
     foreach ($this->_items as $item) {
         $itemPayload = $this->_payloadHelper->itemToRequestQuantityItem($item, $itemIterable->getEmptyQuantityItem());
         $itemIterable[$itemPayload] = $itemPayload;
     }
     $this->_quantityPayload->setQuantityItems($itemIterable);
     $this->_isPayloadPopulated = true;
     return $this;
 }
 /**
  * When transferring item data to an item payload, the item sku should
  * be set on the payload, and a unique line id generated and set. Items
  * without an existing item id should not result in an empty line id.
  */
 public function testItemToQuantityItemNoItemId()
 {
     $sku = '45-12345';
     $id = null;
     $locationId = null;
     $locationType = null;
     $item = $this->_mockQuoteItem($sku, $id, $locationId, $locationType);
     $itemPayload = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Payload\\Inventory\\IQuantityItem', ['setItemId', 'setLineId']);
     $itemPayload->expects($this->once())->method('setItemId')->with($this->identicalTo($sku))->will($this->returnSelf());
     // Line id will be set to null - item->getId is currently null - so
     // SDK will autogenerate the line id when creating the request payload.
     $itemPayload->expects($this->once())->method('setLineId')->with($this->isNull())->will($this->returnSelf());
     $this->assertSame($itemPayload, $this->_payloadHelper->itemToQuantityItem($item, $itemPayload));
 }
 /**
  * When getting the request from a request builder
  * the payload the builder has should be populated with
  * item data and returned.
  */
 public function testGetRequest()
 {
     // Create a set of items for the quote and set the quote
     // up to return them.
     $quoteItems = [$this->_item];
     // Connect SDK payloads.
     $this->_requestPayload->expects($this->any())->method('getQuantityItems')->will($this->returnValue($this->_quantityItemIterable));
     // Side effect test - ensure the mutated quantity items iterable
     // is set back to the payload.
     $this->_requestPayload->expects($this->once())->method('setQuantityItems')->with($this->identicalTo($this->_quantityItemIterable));
     // Testing that proper item is added to the iterable:
     // Rig the iterable to return the "empty" item.
     $this->_quantityItemIterable->expects($this->any())->method('getEmptyQuantityItem')->will($this->returnValue($this->_emptyItem));
     // Set the payload helper to fill out the payload:
     // given the expected item and the empty payload,
     // the helper should return the populated item payload.
     $this->_payloadHelper->expects($this->any())->method('itemToRequestQuantityItem')->with($this->identicalTo($this->_item), $this->identicalTo($this->_emptyItem))->will($this->returnValue($this->_populatedItem));
     // Side-effect test: there should be one - and only one - payload
     // added to the iterable: the populated item payload.
     $this->_quantityItemIterable->expects($this->once())->method('offsetSet')->with($this->identicalTo($this->_populatedItem))->will($this->returnValue(null));
     $requestBuilder = Mage::getModel('ebayenterprise_inventory/quantity_request_builder', ['items' => $quoteItems, 'request_payload' => $this->_requestPayload, 'payload_helper' => $this->_payloadHelper, 'item_selection' => $this->_itemSelection]);
     $this->assertSame($this->_requestPayload, $requestBuilder->getRequest());
 }