public function setUp() { // Create a mock of the quantity results for the quote. $this->_quantityResults = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_results')->disableOriginalConstructor()->setMethods(['getQuantityBySku', 'getQuantityByItemId'])->getMock(); // Create a quote object to use within tests. Expected by // default by the quantity collector when getting results for a quote. $this->_quote = $this->getModelMock('sales/quote', ['addErrorInfo', 'getAllItems']); // Mock the quantity collector to simply always return // the mocked quantity results throughout the tests. $this->_quantityCollector = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_collector')->disableOriginalConstructor()->setMethods(['getQuantityResultsForQuote', 'clearResults'])->getMock(); $this->_quantityCollector->expects($this->any())->method('getQuantityResultsForQuote')->with($this->identicalTo($this->_quote))->will($this->returnValue($this->_quantityResults)); // Mock of the item selection helper, used to filter // down quote items down to just the items that need // to be checked by the inventory service. $this->_inventoryItemSelection = $this->getHelperMock('ebayenterprise_inventory/item_selection', ['selectFrom']); // Mock the inventory's data helper to control // expected results from translations doing translations. $this->_inventoryHelper = $this->getHelperMock('ebayenterprise_inventory/data', ['__']); // Mock out the translate method, while it would be nice to ensure // strings are getting translated through this method, the complexity // of doing so is not currently worth the effort. $this->_inventoryHelper->expects($this->any())->method('__')->will($this->returnArgument(0)); // Mock calculations of total item quantity. $this->_quantityHelper = $this->getHelperMock('ebayenterprise_inventory/quantity', ['calculateTotalQuantityRequested']); // Instance of the model being tested, injected // with the mocked dependencies. $this->_quantityService = Mage::getModel('ebayenterprise_inventory/quantity_service', ['quantity_collector' => $this->_quantityCollector, 'inventory_item_selection' => $this->_inventoryItemSelection, 'inventory_helper' => $this->_inventoryHelper, 'quantity_helper' => $this->_quantityHelper]); $this->_product = Mage::getModel('catalog/product', ['stock_item' => Mage::getModel('catalogInventory/stock_item', ['backorders' => Mage_CatalogInventory_Model_Stock::BACKORDERS_NO])]); }
public function setUp() { $logContext = $this->getHelperMock('ebayenterprise_magelog/context', ['getMetaData']); $logContext->expects($this->any())->method('getMetaData')->will($this->returnValue([])); $this->_api = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Api\\IBidirectionalApi'); // Create two request bodies - one to serve as the "empty" request // body that needs to be populated with data and one to serve as // the "complete" payload that has been populated with data. $this->_emptyRequestBody = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Payload\\Inventory\\IQuantityRequest'); $this->_completeRequestBody = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Payload\\Inventory\\IQuantityRequest'); $this->_responseBody = $this->getMockForAbstractClass('eBayEnterprise\\RetailOrderManagement\\Payload\\Inventory\\IQuantityReply'); $this->_coreHelper = $this->getHelperMock('ebayenterprise_eb2ccore', ['getSdkApi']); $this->_inventoryConfig = $this->buildCoreConfigRegistry(['apiService' => $this->_apiService, 'quantityApiOperation' => $this->_apiOperation]); $this->_inventoryHelper = $this->getHelperMock('ebayenterprise_inventory/data', ['__']); $this->_inventoryHelper->expects($this->any())->method('__')->will($this->returnArgument(0)); $this->_inventoryFactory = $this->getHelperMock('ebayenterprise_inventory/quantity_factory', ['createRequestBuilder', 'createResponseParser', 'createQuantityResults']); $this->_requestBuilder = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_request_builder')->disableOriginalConstructor()->setMethods(['getRequest'])->getMock(); $this->_responseParser = $this->getModelMockBuilder('ebayenterprise_inventory/quantity_response_parser')->disableOriginalConstructor()->setMethods(['getQuantityResults'])->getMock(); $this->_items = [$this->getModelMock('sales/quote_item')]; $this->_sdkHelper = Mage::helper('ebayenterprise_inventory/quantity_sdk'); // As helpers do not support constructor injection, inject // dependencies by directly setting the class properties. EcomDev_Utils_Reflection::setRestrictedPropertyValues($this->_sdkHelper, ['_coreHelper' => $this->_coreHelper, '_inventoryHelper' => $this->_inventoryHelper, '_inventoryConfig' => $this->_inventoryConfig, '_logContext' => $logContext, '_inventoryQuantityFactory' => $this->_inventoryFactory]); }