Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ShippingProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
15 use PHPUnit_Framework_MockObject_MockObject as MockObject;
16 
20 class ShippingProcessorTest extends \PHPUnit\Framework\TestCase
21 {
25  private $shippingAddressManagement;
26 
30  private $shippingMethodManagement;
31 
35  private $shippingProcessor;
36 
37  protected function setUp()
38  {
39  $this->shippingAddressManagement = $this->getMockBuilder(ShippingAddressManagement::class)
40  ->disableOriginalConstructor()
41  ->setMethods(['assign'])
42  ->getMock();
43 
44  $this->shippingMethodManagement = $this->getMockBuilder(ShippingMethodManagement::class)
45  ->disableOriginalConstructor()
46  ->setMethods(['apply'])
47  ->getMock();
48 
49  $objectManager = new ObjectManager($this);
50 
51  $this->shippingProcessor = $objectManager->getObject(ShippingProcessor::class, [
52  'shippingAddressManagement' => $this->shippingAddressManagement,
53  'shippingMethodManagement' => $this->shippingMethodManagement
54  ]);
55  }
56 
63  public function testSave($method, $carrierCode, $methodCode)
64  {
65  $shipping = $this->getMockForAbstractClass(ShippingInterface::class);
66  $quote = $this->getMockForAbstractClass(CartInterface::class);
67  $quoteId = 1;
68 
69  $address = $this->getMockForAbstractClass(AddressInterface::class);
70 
71  $quote->expects(static::exactly(2))
72  ->method('getId')
73  ->willReturn($quoteId);
74 
75  $shipping->expects(static::once())
76  ->method('getAddress')
77  ->willReturn($address);
78 
79  $this->shippingAddressManagement->expects(static::once())
80  ->method('assign')
81  ->with($quoteId, $address);
82 
83  $shipping->expects(static::exactly(2))
84  ->method('getMethod')
85  ->willReturn($method);
86 
87  $quote->expects(static::once())
88  ->method('getItemsCount')
89  ->willReturn(1);
90 
91  $this->shippingMethodManagement->expects(static::once())
92  ->method('apply')
93  ->with($quoteId, $carrierCode, $methodCode);
94 
95  $this->shippingProcessor->save($shipping, $quote);
96  }
97 
102  public function saveDataProvider()
103  {
104  return [
105  ['carrier_Global_World_Economy', 'carrier', 'Global_World_Economy'],
106  ['carrier_International_Economy', 'carrier', 'International_Economy'],
107  ['carrier_Express', 'carrier', 'Express'],
108  ['flat_rate', 'flat', 'rate'],
109  ];
110  }
111 }
$objectManager
Definition: bootstrap.php:17
$quote
$address
Definition: customer.php:38
$method
Definition: info.phtml:13