protected function setUp() { $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', ['create'], [], '', false); $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface'); $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategy\\Query', ['fetchAll'], [], '', false); $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\Manager', [], [], '', false); $this->optionsFactoryMock = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option\\Value\\CollectionFactory', ['create'], [], '', false); $this->storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false); $this->resourceMock = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option', ['getConnection', '__wakeup', 'getMainTable', 'getTable'], [], '', false); $this->selectMock = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'reset'], [], '', false); $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select'], [], '', false); $this->connection->expects($this->once())->method('select')->will($this->returnValue($this->selectMock)); $this->resourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->connection)); $this->resourceMock->expects($this->once())->method('getMainTable')->will($this->returnValue('test_main_table')); $this->resourceMock->expects($this->once())->method('getTable')->with('test_main_table')->will($this->returnValue('test_main_table')); $this->collection = new Collection($this->entityFactoryMock, $this->loggerMock, $this->fetchStrategyMock, $this->eventManagerMock, $this->optionsFactoryMock, $this->storeManagerMock, null, $this->resourceMock); }
protected function setUp() { $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', ['create'], [], '', false); $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface'); $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategy\\Query', ['fetchAll'], [], '', false); $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\Manager', [], [], '', false); $this->optionsFactoryMock = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option\\Value\\CollectionFactory', ['create'], [], '', false); $this->storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false); $this->joinProcessor = $this->getMockBuilder('Magento\\Framework\\Api\\ExtensionAttribute\\JoinProcessorInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->resourceMock = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option', ['getConnection', '__wakeup', 'getMainTable', 'getTable'], [], '', false); $this->selectMock = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'reset', 'join'], [], '', false); $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select'], [], '', false); $this->connection->expects($this->once())->method('select')->will($this->returnValue($this->selectMock)); $this->resourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->connection)); $this->resourceMock->expects($this->once())->method('getMainTable')->will($this->returnValue('test_main_table')); $this->resourceMock->expects($this->exactly(3))->method('getTable')->withConsecutive(['test_main_table'], ['catalog_product_entity'], ['catalog_product_entity'])->willReturnOnConsecutiveCalls($this->returnValue('test_main_table'), 'catalog_product_entity', 'catalog_product_entity'); $this->metadataPoolMock = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false); $metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false); $metadata->expects($this->any())->method('getLinkField')->willReturn('id'); $this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($metadata); $this->selectMock->expects($this->exactly(2))->method('join'); $this->collection = new Collection($this->entityFactoryMock, $this->loggerMock, $this->fetchStrategyMock, $this->eventManagerMock, $this->optionsFactoryMock, $this->storeManagerMock, $this->metadataPoolMock, $this->joinProcessor, null, $this->resourceMock); }
/** * {@inheritdoc} */ public function duplicate(\Magento\Catalog\Api\Data\ProductInterface $product, \Magento\Catalog\Api\Data\ProductInterface $duplicate) { $hydrator = $this->getHydratorPool()->getHydrator(ProductInterface::class); $metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class); return $this->optionResource->duplicate($this->getOptionFactory()->create([]), $hydrator->extract($product)[$metadata->getLinkField()], $hydrator->extract($duplicate)[$metadata->getLinkField()]); }
/** * {@inheritdoc} */ public function duplicate(\Magento\Catalog\Api\Data\ProductInterface $product, \Magento\Catalog\Api\Data\ProductInterface $duplicate) { return $this->optionResource->duplicate($this->getOptionFactory()->create([]), $product->getId(), $duplicate->getId()); }
/** * {@inheritdoc} */ public function delete(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $entity) { $this->optionResource->delete($entity); return true; }