コード例 #1
0
ファイル: StockTest.php プロジェクト: Doability/magento2dev
 public function testAddStockStatusToProducts()
 {
     $storeId = 1;
     $productId = 2;
     $status = 'test';
     $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['setIsSalable', 'getId'])->getMock();
     $productMock->expects($this->once())->method('setIsSalable')->with($status);
     $stockStatusMock = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockStatusInterface')->disableOriginalConstructor()->getMock();
     $stockStatusMock->expects($this->once())->method('getStockStatus')->willReturn($status);
     $productCollectionMock = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Collection\\AbstractCollection')->disableOriginalConstructor()->getMock();
     $productCollectionMock->expects($this->any())->method('getItemById')->with($productId)->willReturn($productMock);
     $productCollectionMock->expects($this->any())->method('getStoreId')->willReturn($storeId);
     $productMock->expects($this->any())->method('getId')->willReturn($productId);
     $iteratorMock = new \ArrayIterator([$productMock]);
     $productCollectionMock->expects($this->any())->method('getIterator')->willReturn($iteratorMock);
     $this->stockRegistryProviderMock->expects($this->once())->method('getStockStatus')->withAnyParameters()->willReturn($stockStatusMock);
     $this->assertNull($this->stock->addStockStatusToProducts($productCollectionMock));
 }
コード例 #2
0
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', ['__wakeup', 'getIdBySku'], [], '', false);
     $this->product->expects($this->any())->method('getIdBySku')->willReturn($this->productId);
     //getIdBySku
     $this->productFactory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product));
     $this->stock = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockInterface', ['__wakeup'], '', false);
     $this->stockItem = $this->getMockBuilder('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface')->setMethods(['setProductId', 'getData', 'addData', 'getItemId'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->stockStatus = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockStatusInterface', ['__wakeup'], '', false);
     $this->stockRegistryProvider = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Model\\Spi\\StockRegistryProviderInterface', ['getStock', 'getStockItem', 'getStockStatus'], '', false);
     $this->stockRegistryProvider->expects($this->any())->method('getStock')->will($this->returnValue($this->stock));
     $this->stockRegistryProvider->expects($this->any())->method('getStockItem')->will($this->returnValue($this->stockItem));
     $this->stockRegistryProvider->expects($this->any())->method('getStockStatus')->will($this->returnValue($this->stockStatus));
     $this->stockItemRepository = $this->getMockForAbstractClass('\\Magento\\CatalogInventory\\Api\\StockItemRepositoryInterface', ['save'], '', false);
     $this->stockItemRepository->expects($this->any())->method('save')->will($this->returnValue($this->stockItem));
     $this->stockRegistry = $this->objectManagerHelper->getObject('\\Magento\\CatalogInventory\\Model\\StockRegistry', ['stockRegistryProvider' => $this->stockRegistryProvider, 'productFactory' => $this->productFactory, 'stockItemRepository' => $this->stockItemRepository]);
 }
コード例 #3
0
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->stock = $this->getMock('\\Magento\\CatalogInventory\\Api\\Data\\StockInterface', [], [], '', false);
     $this->stockItem = $this->getMock('\\Magento\\CatalogInventory\\Api\\Data\\StockItemInterface', [], [], '', false);
     $this->stockStatus = $this->getMock('\\Magento\\CatalogInventory\\Api\\Data\\StockStatusInterface', [], [], '', false);
     $this->objectResult = $this->getMock('\\Magento\\Framework\\Object', [], [], '', false);
     $this->stockStateProvider = $this->getMock('Magento\\CatalogInventory\\Model\\Spi\\StockStateProviderInterface', ['verifyStock', 'verifyNotification', 'checkQty', 'suggestQty', 'getStockQty', 'checkQtyIncrements', 'checkQuoteItemQty'], [], '', false);
     $this->stockStateProvider->expects($this->any())->method('verifyStock')->willReturn(true);
     $this->stockStateProvider->expects($this->any())->method('verifyNotification')->willReturn(true);
     $this->stockStateProvider->expects($this->any())->method('checkQty')->willReturn(true);
     $this->stockStateProvider->expects($this->any())->method('suggestQty')->willReturn($this->qty);
     $this->stockStateProvider->expects($this->any())->method('getStockQty')->willReturn($this->qty);
     $this->stockStateProvider->expects($this->any())->method('checkQtyIncrements')->willReturn($this->objectResult);
     $this->stockStateProvider->expects($this->any())->method('checkQuoteItemQty')->willReturn($this->objectResult);
     $this->stockRegistryProvider = $this->getMock('Magento\\CatalogInventory\\Model\\Spi\\StockRegistryProviderInterface', ['getStock', 'getStockItem', 'getStockStatus'], [], '', false);
     $this->stockRegistryProvider->expects($this->any())->method('getStock')->will($this->returnValue($this->stock));
     $this->stockRegistryProvider->expects($this->any())->method('getStockItem')->will($this->returnValue($this->stockItem));
     $this->stockRegistryProvider->expects($this->any())->method('getStockStatus')->will($this->returnValue($this->stockStatus));
     $this->stockState = $this->objectManagerHelper->getObject('\\Magento\\CatalogInventory\\Model\\StockState', ['stockStateProvider' => $this->stockStateProvider, 'stockRegistryProvider' => $this->stockRegistryProvider]);
 }