/** * @dataProvider saveDataProvider * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product * @param array $data * @param array $modelData */ public function testSave($product, array $data, array $modelData) { $link = $this->createSampleModel($product, $modelData, true); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn('id'); $this->sampleFactory->expects($this->once())->method('create')->willReturn($link); $this->target->save($product, $data); }
/** * @return Sample */ private function getComponent() { if (!$this->component) { $this->component = $this->componentFactory->create(); } return $this->component; }
/** * {@inheritdoc} */ public function delete($id) { /** @var $sample \Magento\Downloadable\Model\Sample */ $sample = $this->sampleFactory->create()->load($id); if (!$sample->getId()) { throw new NoSuchEntityException(__('There is no downloadable sample with provided ID.')); } try { $sample->delete(); } catch (\Exception $exception) { throw new StateException(__('Cannot delete sample with id %1', $sample->getId()), $exception); } return true; }
/** * @return \Magento\Downloadable\Model\Sample */ protected function _createSample() { return $this->_sampleFactory->create(); }
/** * @return ComponentInterface */ protected function createItem() { return $this->sampleFactory->create(); }
/** * @dataProvider saveDataProvider * @param \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product * @param array $data * @param array $modelData */ public function testSave($product, array $data, array $modelData) { $link = $this->createSampleModel($product, $modelData, true); $this->sampleFactory->expects($this->once())->method('create')->will($this->returnValue($link)); $this->target->save($product, $data); }