Esempio n. 1
0
 public function testGetProductByAttributesReturnFirstItem()
 {
     $productMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'hasData', 'getData', 'getResource', 'getAttributeSetId'])->disableOriginalConstructor()->getMock();
     $firstItemMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->setMethods(['__wakeup', 'getId'])->disableOriginalConstructor()->getMock();
     $productCollection = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Resource\\Product\\Type\\Configurable\\Product\\Collection')->setMethods(['setFlag', 'setProductFilter', 'addStoreFilter', 'addAttributeToSelect', 'addAttributeToFilter', 'getFirstItem'])->disableOriginalConstructor()->getMock();
     $this->_productCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($productCollection));
     $productCollection->expects($this->any())->method('setProductFilter')->will($this->returnSelf());
     $productCollection->expects($this->any())->method('setFlag')->will($this->returnSelf());
     $productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
     $productCollection->expects($this->any())->method('addAttributeToFilter')->will($this->returnSelf());
     $productCollection->expects($this->once())->method('getFirstItem')->willReturn($firstItemMock);
     $firstItemMock->expects($this->once())->method('getId')->willReturn(3);
     $productMock->expects($this->at(0))->method('getData')->with('_cache_instance_store_filter')->willReturn('some_filter');
     $this->assertEquals($firstItemMock, $this->_model->getProductByAttributes($this->attributeData, $productMock));
 }