Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StatusResolverTest.php
Go to the documentation of this file.
1 <?php
7 
13 use PHPUnit_Framework_MockObject_MockObject as MockObject;
14 
15 class StatusResolverTest extends \PHPUnit\Framework\TestCase
16 {
23  public function testGetOrderStatusByState($order, $expectedReturn)
24  {
25  $actualReturn = (new StatusResolver())->getOrderStatusByState($order, 'new');
26 
27  self::assertEquals($expectedReturn, $actualReturn);
28  }
29 
33  public function statesDataProvider()
34  {
35  return [
36  [
37  $this->getOrder('pending', ['pending' => 'pending']),
38  'pending'
39  ],
40  [
41  $this->getOrder('processing', ['pending' => 'pending']),
42  'processing'
43  ],
44  ];
45  }
46 
52  private function getOrder($newOrderStatus, $stateStatuses)
53  {
54  $order = $this->getMockBuilder(OrderInterface::class)
55  ->setMethods(['getConfig'])
56  ->getMockForAbstractClass();
57  $order->method('getPayment')
58  ->willReturn($this->getPayment($newOrderStatus));
59  $order->method('getConfig')
60  ->willReturn($this->getConfig($stateStatuses));
61 
62  return $order;
63  }
64 
69  private function getPayment($newOrderStatus)
70  {
71  $payment = $this->getMockBuilder(OrderPaymentInterface::class)
72  ->setMethods(['getMethodInstance'])
73  ->getMockForAbstractClass();
74  $payment->method('getMethodInstance')
75  ->willReturn($this->getMethodInstance($newOrderStatus));
76 
77  return $payment;
78  }
79 
84  private function getMethodInstance($newOrderStatus)
85  {
86  $methodInstance = $this->getMockBuilder(MethodInterface::class)
87  ->getMockForAbstractClass();
88  $methodInstance->method('getConfigData')
89  ->with('order_status')
90  ->willReturn($newOrderStatus);
91 
92  return $methodInstance;
93  }
94 
99  private function getConfig($stateStatuses)
100  {
101  $config = $this->getMockBuilder(Config::class)
102  ->disableOriginalConstructor()
103  ->getMock();
104  $config->method('getStateStatuses')
105  ->willReturn($stateStatuses);
106  $config->method('getStateDefaultStatus')
107  ->willReturn('processing');
108 
109  return $config;
110  }
111 }
$config
Definition: fraud_order.php:17
$order
Definition: order.php:55
$payment
Definition: order.php:17