public function testAddChild()
 {
     $productLink = $this->getMock('Magento\\Bundle\\Service\\V1\\Data\\Product\\Link', array(), array(), '', false);
     $productLink->expects($this->any())->method('getSku')->will($this->returnValue('linked_product_sku'));
     $productLink->expects($this->any())->method('getOptionId')->will($this->returnValue(1));
     $productMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', array(), array(), '', false);
     $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE));
     $productMock->expects($this->any())->method('getId')->will($this->returnValue('product_id'));
     $linkedProductMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', array(), array(), '', false);
     $linkedProductMock->expects($this->any())->method('getId')->will($this->returnValue(13));
     $linkedProductMock->expects($this->once())->method('isComposite')->will($this->returnValue(false));
     $this->productRepositoryMock->expects($this->at(0))->method('get')->with('product_sku')->will($this->returnValue($productMock));
     $this->productRepositoryMock->expects($this->at(1))->method('get')->with('linked_product_sku')->will($this->returnValue($linkedProductMock));
     $store = $this->getMock('\\Magento\\Store\\Model\\Store', array(), array(), '', false);
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $store->expects($this->any())->method('getId')->will($this->returnValue(0));
     $option = $this->getMockBuilder('\\Magento\\Bundle\\Model\\Option')->disableOriginalConstructor()->setMethods(['getOptionId', '__wakeup'])->getMock();
     $option->expects($this->once())->method('getOptionId')->will($this->returnValue(1));
     $optionsCollectionMock = $this->getMock('\\Magento\\Bundle\\Model\\Resource\\Option\\Collection', array(), array(), '', false);
     $optionsCollectionMock->expects($this->once())->method('setProductIdFilter')->with($this->equalTo('product_id'))->will($this->returnSelf());
     $optionsCollectionMock->expects($this->once())->method('joinValues')->with($this->equalTo(0))->will($this->returnSelf());
     $optionsCollectionMock->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$option])));
     $this->optionCollectionFactoryMock->expects($this->any())->method('create')->will($this->returnValue($optionsCollectionMock));
     $selections = [['option_id' => 1, 'product_id' => 11], ['option_id' => 1, 'product_id' => 12]];
     $bundle = $this->getMock('\\Magento\\Bundle\\Model\\Resource\\Bundle', array(), array(), '', false);
     $bundle->expects($this->once())->method('getSelectionsData')->with('product_id')->will($this->returnValue($selections));
     $this->bundleFactoryMock->expects($this->once())->method('create')->will($this->returnValue($bundle));
     $selection = $this->getMock('\\Magento\\Framework\\Object', array('save', 'getId'), array(), '', false);
     $selection->expects($this->once())->method('save');
     $selection->expects($this->once())->method('getId')->will($this->returnValue(42));
     $this->bundleSelectionMock->expects($this->once())->method('create')->will($this->returnValue($selection));
     $result = $this->service->addChild('product_sku', 1, $productLink);
     $this->assertEquals(42, $result);
 }