Пример #1
0
 /**
  * @param \Magento\Framework\DataObject $item
  * @param array $storesData
  * @dataProvider getItemsDataProvider
  * @throws \Exception
  */
 public function testAfterLoad($item, $storesData)
 {
     $linkField = 'row_id';
     $expectedResult = [];
     foreach ($storesData as $storeData) {
         $expectedResult[$storeData[$linkField]][] = $storeData['store_id'];
     }
     $entityMetadataMock = $this->getMockBuilder('Magento\\Framework\\EntityManager\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $entityMetadataMock->expects($this->any())->method('getLinkField')->willReturn($linkField);
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($entityMetadataMock);
     $this->select->expects($this->any())->method('from')->willReturnSelf();
     $this->connection->expects($this->any())->method('fetchAll')->willReturn($storesData);
     $storeDataMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->getMockForAbstractClass();
     $storeDataMock->expects($this->any())->method('getId')->willReturn(current($expectedResult[$item->getId()]));
     $storeDataMock->expects($this->any())->method('getCode')->willReturn('some_code');
     $this->storeManagerMock->expects($this->any())->method('getStores')->willReturn([$storeDataMock]);
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeDataMock);
     $this->collection->addItem($item);
     $this->assertEmpty($item->getStoreId());
     $this->collection->load();
     $this->assertEquals($expectedResult[$item->getId()], $item->getStoreId());
 }