コード例 #1
0
 /**
  * //Last method throws exception because class method 'submit()' already covered.
  *
  * @expectedException \Exception
  * @expectedExceptionMessage Quote prepared for guest customer.
  */
 public function testPlaceOrderIfCustomerIsQuest()
 {
     $cartId = 100;
     $email = '*****@*****.**';
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['getCheckoutMethod', 'setCustomerId', 'setCustomerEmail', 'getBillingAddress', 'setCustomerIsGuest', 'setCustomerGroupId'], [], '', false);
     $this->quoteRepositoryMock->expects($this->once())->method('getActive')->with($cartId)->willReturn($quoteMock);
     $quoteMock->expects($this->once())->method('getCheckoutMethod')->willReturn(\Magento\Checkout\Model\Type\Onepage::METHOD_GUEST);
     $quoteMock->expects($this->once())->method('setCustomerId')->with(null)->willReturnSelf();
     $quoteMock->expects($this->once())->method('setCustomerEmail')->with($email)->willReturnSelf();
     $addressMock = $this->getMock('\\Magento\\Quote\\Model\\Quote\\Address', ['getEmail'], [], '', false);
     $addressMock->expects($this->once())->method('getEmail')->willReturn($email);
     $quoteMock->expects($this->once())->method('getBillingAddress')->with()->willReturn($addressMock);
     $quoteMock->expects($this->once())->method('setCustomerIsGuest')->with(true)->willReturnSelf();
     $quoteMock->expects($this->once())->method('setCustomerGroupId')->with(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID)->willThrowException(new \Exception('Quote prepared for guest customer.'));
     $this->model->placeOrder($cartId);
 }