/**
  * When creating a new quantity model, a new
  * quantity model with the provided sku, item id
  * and quantity should be returned.
  */
 public function testCreateQuantity()
 {
     $sku = 'the-sku';
     $itemId = 3;
     $quantity = 345;
     $quantityModel = $this->_quantityFactory->createQuantity($sku, $itemId, $quantity);
     $this->assertInstanceOf('EbayEnterprise_Inventory_Model_Quantity', $quantityModel);
     $this->assertSame($sku, $quantityModel->getSku());
     $this->assertSame($itemId, $quantityModel->getItemId());
     $this->assertSame($quantity, $quantityModel->getQuantity());
 }
 /**
  * When extracting results from the SDK response, a quantity
  * result model with the quantity data extracted from the
  * response should be returned.
  */
 public function testExtractResponseResultsSuccess()
 {
     // Create an expected result, should be returned when successfully
     // extracting results from a response.
     $sdkResult = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_results')->disableOriginalConstructor()->getMock();
     // Mock the API to return an expected response body as the
     // reply to the SDK request.
     $this->_api->expects($this->any())->method('getResponseBody')->will($this->returnValue($this->_responseBody));
     // Mock up some SDK results - doesn't really matter what these
     // are, just that they can be recognized as the "right" results.
     $quantityRecords = [$this->getModelMockBuilder('ebayenteprirse_inventory/quantity')->disableOriginalConstructor()->getMock()];
     // Create a quote response parser capable of returning the
     // proper results from the quantity response.
     $this->_responseParser->expects($this->any())->method('getQuantityResults')->will($this->returnValue($quantityRecords));
     // Setup the quantity factory to be able to provide the proper quote
     // response parser if given the correct response payload and quote.
     $this->_inventoryFactory->expects($this->any())->method('createResponseParser')->with($this->identicalTo($this->_responseBody))->will($this->returnValue($this->_responseParser));
     // Setup the quantity factory to be able to provide the proper SDK result
     // if given the expected quantity data.
     $this->_inventoryFactory->expects($this->any())->method('createQuantityResults')->with($this->identicalTo($quantityRecords))->will($this->returnValue($sdkResult));
     // Ensure that the correct SDK result is returned when extracting
     // results from the SDK. For now, this will return the exact same
     // instance as is expected. In the future this may not be the case and
     // test could be expected to simply ensure the results available in
     // the returned result model match the expected results.
     $this->assertSame($sdkResult, EcomDev_Utils_Reflection::invokeRestrictedMethod($this->_sdkHelper, '_extractResponseResults', [$this->_api, $this->_items]));
 }
 /**
  * When getting quantity results from a response,
  * an array of quantity models populated from the
  * payload data should be returned.
  */
 public function testGetQuantityResults()
 {
     // Create an expected quantity model - created with data
     // expected to be extracted from the response payload.
     $quantityModel = Mage::getModel('ebayenterprise_inventory/quantity', ['sku' => $this->_quantityItemSku, 'item_id' => $this->_quantityItemItemId, 'quantity' => $this->_quantityItemQuantity]);
     // Set the response payload up to return the item iterable
     // containing a quantity item.
     $this->_responsePayload->expects($this->any())->method('getQuantityItems')->will($this->returnValue($this->_quantityItemIterable));
     // Set the quantity factory to return a correct quantity
     // model if given the proper sku, item id and quantity.
     $this->_quantityFactory->expects($this->any())->method('createQuantity')->with($this->identicalTo($this->_quantityItemSku), $this->identicalTo($this->_quantityItemItemId), $this->identicalTo($this->_quantityItemQuantity))->will($this->returnValue($quantityModel));
     $results = $this->_responseParser->getQuantityResults();
     // Verify the extracted results.
     $this->assertCount(1, $results, 'did not extract correct number of results');
     $resultQuantityModel = $results[0];
     $this->assertSame($this->_quantityItemSku, $resultQuantityModel->getSku(), 'sku of extracted quantity model does not match expected sku');
     $this->assertSame($this->_quantityItemItemId, $resultQuantityModel->getItemId(), 'item id of extracted quantity model does not match expected item id');
     $this->assertSame($this->_quantityItemQuantity, $resultQuantityModel->getQuantity(), 'quantity of extracted quantity model does not match expected quantity');
 }
 /**
  * Extract quantity results from the API response body.
  *
  * @param IBidirectionalApi
  * @param Mage_Sales_Model_Order_Quote_Item[]
  * @return EbayEnterprise_Inventory_Model_Quantity_Results
  */
 protected function _extractResponseResults(IBidirectionalApi $api, array $items)
 {
     try {
         $responseBody = $api->getResponseBody();
     } catch (UnsupportedOperation $e) {
         // This exception handling is probably not necessary but
         // is technically possible. If the sdk flow of
         // getRequest->setRequest->send->getResponse is followed,
         // which is is by the one public method of this class, this
         // exception should never be thrown in this instance. If it
         // were to be thrown at all by the SDK, it would have already
         // happened during the "send" step.
         $this->_logger->critical('Inventory quantity service response unsupported by SDK.', $this->_logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     }
     $responseParser = $this->_inventoryQuantityFactory->createResponseParser($responseBody);
     return $this->_inventoryQuantityFactory->createQuantityResults($responseParser->getQuantityResults(), $items);
 }
 /**
  * Create a new quantity model from the response quantity item.
  *
  * @param IReplyQuantityItem
  * @return EbayEnterprise_Inventory_Model_Quantity
  */
 protected function _extractItem(IReplyQuantityItem $item)
 {
     return $this->_quantityFactory->createQuantity($item->getItemId(), $item->getLineId(), $item->getQuantity());
 }