/**
  * @param ShippingInterface $shipping
  * @param CartInterface $quote
  * @return void
  */
 public function save(ShippingInterface $shipping, CartInterface $quote)
 {
     $this->shippingAddressManagement->assign($quote->getId(), $shipping->getAddress());
     if (!empty($shipping->getMethod()) && $quote->getItemsCount() > 0) {
         $nameComponents = explode('_', $shipping->getMethod());
         $carrierCode = array_shift($nameComponents);
         // carrier method code can contains more one name component
         $methodCode = implode('_', $nameComponents);
         $this->shippingMethodManagement->apply($quote->getId(), $carrierCode, $methodCode);
     }
 }
 /**
  * @param string $method
  * @param string $carrierCode
  * @param string $methodCode
  * @dataProvider saveDataProvider
  */
 public function testSave($method, $carrierCode, $methodCode)
 {
     $shipping = $this->getMockForAbstractClass(ShippingInterface::class);
     $quote = $this->getMockForAbstractClass(CartInterface::class);
     $quoteId = 1;
     $address = $this->getMockForAbstractClass(AddressInterface::class);
     $quote->expects(static::exactly(2))->method('getId')->willReturn($quoteId);
     $shipping->expects(static::once())->method('getAddress')->willReturn($address);
     $this->shippingAddressManagement->expects(static::once())->method('assign')->with($quoteId, $address);
     $shipping->expects(static::exactly(2))->method('getMethod')->willReturn($method);
     $quote->expects(static::once())->method('getItemsCount')->willReturn(1);
     $this->shippingMethodManagement->expects(static::once())->method('apply')->with($quoteId, $carrierCode, $methodCode);
     $this->shippingProcessor->save($shipping, $quote);
 }
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Cart contains virtual product(s) only. Shipping address is not applicable
  */
 public function testGetAddressOfQuoteWithVirtualProducts()
 {
     $quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with('cartId')->will($this->returnValue($quoteMock));
     $quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue(true));
     $quoteMock->expects($this->never())->method('getShippingAddress');
     $this->service->get('cartId');
 }