optionRepositoryMock = $this->getMockForAbstractClass(ProductOptionRepositoryInterface::class); $this->productRepositoryMock = $this->getMockForAbstractClass(ProductRepositoryInterface::class); $this->optionMock = $this->getMockForAbstractClass(OptionInterface::class); $this->productMock = $this->getMockForAbstractClass(ProductInterface::class); $this->model = new OptionManagement($this->optionRepositoryMock, $this->productRepositoryMock); } public function testSave() { $this->optionMock->expects($this->once())->method('getSku')->willReturn('bundle_product_sku'); $this->productRepositoryMock->expects($this->once()) ->method('get') ->with('bundle_product_sku') ->willReturn($this->productMock); $this->productMock->expects($this->once()) ->method('getTypeId') ->willReturn(Type::TYPE_BUNDLE); $this->optionRepositoryMock->expects($this->once()) ->method('save') ->with($this->productMock, $this->optionMock); $this->model->save($this->optionMock); } public function testSaveWithException() { $this->expectException(InputException::class); $this->expectExceptionMessage('This is implemented for bundle products only.'); $this->optionMock->expects($this->once())->method('getSku')->willReturn('bundle_product_sku'); $this->productRepositoryMock->expects($this->once()) ->method('get') ->with('bundle_product_sku') ->willReturn($this->productMock); $this->productMock->expects($this->once()) ->method('getTypeId') ->willReturn(Type::TYPE_SIMPLE); $this->optionRepositoryMock->expects($this->never())->method('save'); $this->model->save($this->optionMock); } }