Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ShippingAddressAssignmentTest.php
Go to the documentation of this file.
1 <?php
8 
9 class ShippingAddressAssignmentTest extends \PHPUnit\Framework\TestCase
10 {
14  private $model;
15 
19  private $shippingAssignmentProcessorMock;
20 
24  private $cartExtensionFactoryMock;
25 
29  private $quoteMock;
30 
34  private $addressMock;
35 
39  private $extensionAttributeMock;
40 
44  private $shippingAssignmentMock;
45 
46  public function setUp()
47  {
48  $this->cartExtensionFactoryMock = $this->createPartialMock(
49  \Magento\Quote\Api\Data\CartExtensionFactory::class,
50  ['create']
51  );
52  $this->shippingAssignmentProcessorMock = $this->createMock(
53  \Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor::class
54  );
55  $this->quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
56  $this->addressMock = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
57  $this->extensionAttributeMock = $this->createPartialMock(
58  \Magento\Quote\Api\Data\CartExtension::class,
59  ['setShippingAssignments']
60  );
61 
62  $this->shippingAssignmentMock = $this->createMock(\Magento\Quote\Api\Data\ShippingAssignmentInterface::class);
63  //shipping assignment processing
64  $this->quoteMock->expects($this->once())->method('getExtensionAttributes')->willReturn(null);
65  $this->cartExtensionFactoryMock
66  ->expects($this->once())
67  ->method('create')
68  ->willReturn($this->extensionAttributeMock);
69  $this->shippingAssignmentProcessorMock
70  ->expects($this->once())
71  ->method('create')
72  ->willReturn($this->shippingAssignmentMock);
73  $this->extensionAttributeMock
74  ->expects($this->once())
75  ->method('setShippingAssignments')
76  ->with([$this->shippingAssignmentMock])
77  ->willReturnSelf();
78  $this->quoteMock->expects($this->once())->method('setExtensionAttributes')->with($this->extensionAttributeMock);
79  $this->model = new \Magento\Quote\Model\ShippingAddressAssignment(
80  $this->cartExtensionFactoryMock,
81  $this->shippingAssignmentProcessorMock
82  );
83  }
84 
86  {
87  $addressId = 1;
88  $addressMock = $this->createMock(\Magento\Quote\Api\Data\AddressInterface::class);
89  $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($addressMock);
90  $addressMock->expects($this->once())->method('getId')->willReturn($addressId);
91  $this->addressMock->expects($this->once())->method('setSameAsBilling')->with(1);
92  $this->quoteMock->expects($this->once())->method('removeAddress')->with($addressId);
93  $this->quoteMock->expects($this->once())->method('setShippingAddress')->with($this->addressMock);
94  $this->model->setAddress($this->quoteMock, $this->addressMock, true);
95  }
96 
98  {
99  $addressMock = $this->createMock(\Magento\Quote\Api\Data\AddressInterface::class);
100  $this->quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($addressMock);
101  $addressMock->expects($this->once())->method('setSameAsBilling')->with(0)->willReturnSelf();
102  $this->quoteMock->expects($this->once())->method('setShippingAddress')->with($addressMock);
103  $this->model->setAddress($this->quoteMock, $this->addressMock, false);
104  }
105 }