@@ -24,7 +24,9 @@ class StateTest extends \PHPUnit\Framework\TestCase
24
24
25
25
protected function setUp ()
26
26
{
27
- $ this ->orderMock = $ this ->createPartialMock (\Magento \Sales \Model \Order::class, [
27
+ $ this ->orderMock = $ this ->createPartialMock (
28
+ \Magento \Sales \Model \Order::class,
29
+ [
28
30
'__wakeup ' ,
29
31
'getId ' ,
30
32
'hasCustomerNoteNotify ' ,
@@ -35,13 +37,12 @@ protected function setUp()
35
37
'canShip ' ,
36
38
'getBaseGrandTotal ' ,
37
39
'canCreditmemo ' ,
38
- 'getState ' ,
39
- 'setState ' ,
40
40
'getTotalRefunded ' ,
41
41
'hasForcedCanCreditmemo ' ,
42
42
'getIsInProcess ' ,
43
43
'getConfig ' ,
44
- ]);
44
+ ]
45
+ );
45
46
$ this ->orderMock ->expects ($ this ->any ())
46
47
->method ('getConfig ' )
47
48
->willReturnSelf ();
@@ -53,127 +54,88 @@ protected function setUp()
53
54
}
54
55
55
56
/**
56
- * test check order - order without id
57
- */
58
- public function testCheckOrderEmpty ()
59
- {
60
- $ this ->orderMock ->expects ($ this ->once ())
61
- ->method ('getBaseGrandTotal ' )
62
- ->willReturn (100 );
63
- $ this ->orderMock ->expects ($ this ->never ())
64
- ->method ('setState ' );
65
-
66
- $ this ->state ->check ($ this ->orderMock );
67
- }
68
-
69
- /**
70
- * test check order - set state complete
57
+ * @param bool $isCanceled
58
+ * @param bool $canUnhold
59
+ * @param bool $canInvoice
60
+ * @param bool $canShip
61
+ * @param int $callCanSkipNum
62
+ * @param bool $canCreditmemo
63
+ * @param int $callCanCreditmemoNum
64
+ * @param string $currentState
65
+ * @param string $expectedState
66
+ * @param int $callSetStateNum
67
+ * @dataProvider stateCheckDataProvider
68
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
71
69
*/
72
- public function testCheckSetStateComplete ()
73
- {
70
+ public function testCheck (
71
+ bool $ canCreditmemo ,
72
+ int $ callCanCreditmemoNum ,
73
+ bool $ canShip ,
74
+ int $ callCanSkipNum ,
75
+ string $ currentState ,
76
+ string $ expectedState = '' ,
77
+ bool $ isInProcess = false ,
78
+ int $ callGetIsInProcessNum = 0 ,
79
+ bool $ isCanceled = false ,
80
+ bool $ canUnhold = false ,
81
+ bool $ canInvoice = false
82
+ ) {
83
+ $ this ->orderMock ->setState ($ currentState );
74
84
$ this ->orderMock ->expects ($ this ->any ())
75
- ->method ('getId ' )
76
- ->will ($ this ->returnValue (1 ));
77
- $ this ->orderMock ->expects ($ this ->once ())
78
85
->method ('isCanceled ' )
79
- ->will ($ this ->returnValue (false ));
80
- $ this ->orderMock ->expects ($ this ->once ())
81
- ->method ('canUnhold ' )
82
- ->will ($ this ->returnValue (false ));
83
- $ this ->orderMock ->expects ($ this ->once ())
84
- ->method ('canInvoice ' )
85
- ->will ($ this ->returnValue (false ));
86
- $ this ->orderMock ->expects ($ this ->once ())
87
- ->method ('canShip ' )
88
- ->will ($ this ->returnValue (false ));
89
- $ this ->orderMock ->expects ($ this ->once ())
90
- ->method ('getBaseGrandTotal ' )
91
- ->will ($ this ->returnValue (100 ));
92
- $ this ->orderMock ->expects ($ this ->once ())
93
- ->method ('canCreditmemo ' )
94
- ->will ($ this ->returnValue (true ));
95
- $ this ->orderMock ->expects ($ this ->exactly (2 ))
96
- ->method ('getState ' )
97
- ->will ($ this ->returnValue (Order::STATE_PROCESSING ));
98
- $ this ->orderMock ->expects ($ this ->once ())
99
- ->method ('setState ' )
100
- ->with (Order::STATE_COMPLETE )
101
- ->will ($ this ->returnSelf ());
102
- $ this ->assertEquals ($ this ->state , $ this ->state ->check ($ this ->orderMock ));
103
- }
104
-
105
- /**
106
- * test check order - set state closed
107
- */
108
- public function testCheckSetStateClosed ()
109
- {
86
+ ->willReturn ($ isCanceled );
110
87
$ this ->orderMock ->expects ($ this ->any ())
111
- ->method ('getId ' )
112
- ->will ($ this ->returnValue (1 ));
113
- $ this ->orderMock ->expects ($ this ->once ())
114
- ->method ('isCanceled ' )
115
- ->will ($ this ->returnValue (false ));
116
- $ this ->orderMock ->expects ($ this ->once ())
117
88
->method ('canUnhold ' )
118
- ->will ( $ this -> returnValue ( false ) );
119
- $ this ->orderMock ->expects ($ this ->once ())
89
+ ->willReturn ( $ canUnhold );
90
+ $ this ->orderMock ->expects ($ this ->any ())
120
91
->method ('canInvoice ' )
121
- ->will ( $ this -> returnValue ( false ) );
122
- $ this ->orderMock ->expects ($ this ->once ( ))
92
+ ->willReturn ( $ canInvoice );
93
+ $ this ->orderMock ->expects ($ this ->exactly ( $ callCanSkipNum ))
123
94
->method ('canShip ' )
124
- ->will ($ this ->returnValue (false ));
125
- $ this ->orderMock ->expects ($ this ->once ())
126
- ->method ('getBaseGrandTotal ' )
127
- ->will ($ this ->returnValue (100 ));
128
- $ this ->orderMock ->expects ($ this ->once ())
95
+ ->willReturn ($ canShip );
96
+ $ this ->orderMock ->expects ($ this ->exactly ($ callCanCreditmemoNum ))
129
97
->method ('canCreditmemo ' )
130
- ->will ($ this ->returnValue (false ));
131
- $ this ->orderMock ->expects ($ this ->exactly (2 ))
132
- ->method ('getTotalRefunded ' )
133
- ->will ($ this ->returnValue (null ));
134
- $ this ->orderMock ->expects ($ this ->once ())
135
- ->method ('hasForcedCanCreditmemo ' )
136
- ->will ($ this ->returnValue (true ));
137
- $ this ->orderMock ->expects ($ this ->exactly (2 ))
138
- ->method ('getState ' )
139
- ->will ($ this ->returnValue (Order::STATE_PROCESSING ));
140
- $ this ->orderMock ->expects ($ this ->once ())
141
- ->method ('setState ' )
142
- ->with (Order::STATE_CLOSED )
143
- ->will ($ this ->returnSelf ());
144
- $ this ->assertEquals ($ this ->state , $ this ->state ->check ($ this ->orderMock ));
98
+ ->willReturn ($ canCreditmemo );
99
+ $ this ->orderMock ->expects ($ this ->exactly ($ callGetIsInProcessNum ))
100
+ ->method ('getIsInProcess ' )
101
+ ->willReturn ($ isInProcess );
102
+ $ this ->state ->check ($ this ->orderMock );
103
+ $ this ->assertEquals ($ expectedState , $ this ->orderMock ->getState ());
145
104
}
146
105
147
- /**
148
- * test check order - set state processing
149
- */
150
- public function testCheckSetStateProcessing ()
106
+ public function stateCheckDataProvider ()
151
107
{
152
- $ this ->orderMock ->expects ($ this ->any ())
153
- ->method ('getId ' )
154
- ->will ($ this ->returnValue (1 ));
155
- $ this ->orderMock ->expects ($ this ->once ())
156
- ->method ('isCanceled ' )
157
- ->will ($ this ->returnValue (false ));
158
- $ this ->orderMock ->expects ($ this ->once ())
159
- ->method ('canUnhold ' )
160
- ->will ($ this ->returnValue (false ));
161
- $ this ->orderMock ->expects ($ this ->once ())
162
- ->method ('canInvoice ' )
163
- ->will ($ this ->returnValue (false ));
164
- $ this ->orderMock ->expects ($ this ->once ())
165
- ->method ('canShip ' )
166
- ->will ($ this ->returnValue (true ));
167
- $ this ->orderMock ->expects ($ this ->once ())
168
- ->method ('getState ' )
169
- ->will ($ this ->returnValue (Order::STATE_NEW ));
170
- $ this ->orderMock ->expects ($ this ->once ())
171
- ->method ('getIsInProcess ' )
172
- ->will ($ this ->returnValue (true ));
173
- $ this ->orderMock ->expects ($ this ->once ())
174
- ->method ('setState ' )
175
- ->with (Order::STATE_PROCESSING )
176
- ->will ($ this ->returnSelf ());
177
- $ this ->assertEquals ($ this ->state , $ this ->state ->check ($ this ->orderMock ));
108
+ return [
109
+ 'processing - !canCreditmemo!canShip -> closed ' =>
110
+ [false , 1 , false , 0 , Order::STATE_PROCESSING , Order::STATE_CLOSED ],
111
+ 'complete - !canCreditmemo,!canShip -> closed ' =>
112
+ [false , 1 , false , 0 , Order::STATE_COMPLETE , Order::STATE_CLOSED ],
113
+ 'processing - !canCreditmemo,canShip -> closed ' =>
114
+ [false , 1 , true , 0 , Order::STATE_PROCESSING , Order::STATE_CLOSED ],
115
+ 'complete - !canCreditmemo,canShip -> closed ' =>
116
+ [false , 1 , true , 0 , Order::STATE_COMPLETE , Order::STATE_CLOSED ],
117
+ 'processing - canCreditmemo,!canShip -> complete ' =>
118
+ [true , 1 , false , 1 , Order::STATE_PROCESSING , Order::STATE_COMPLETE ],
119
+ 'complete - canCreditmemo,!canShip -> complete ' =>
120
+ [true , 1 , false , 0 , Order::STATE_COMPLETE , Order::STATE_COMPLETE ],
121
+ 'processing - canCreditmemo, canShip -> processing ' =>
122
+ [true , 1 , true , 1 , Order::STATE_PROCESSING , Order::STATE_PROCESSING ],
123
+ 'complete - canCreditmemo, canShip -> complete ' =>
124
+ [true , 1 , true , 0 , Order::STATE_COMPLETE , Order::STATE_COMPLETE ],
125
+ 'new - canCreditmemo, canShip, IsInProcess -> processing ' =>
126
+ [true , 1 , true , 1 , Order::STATE_NEW , Order::STATE_PROCESSING , true , 1 ],
127
+ 'new - canCreditmemo, !canShip, IsInProcess -> processing ' =>
128
+ [true , 1 , false , 1 , Order::STATE_NEW , Order::STATE_COMPLETE , true , 1 ],
129
+ 'new - canCreditmemo, canShip, !IsInProcess -> new ' =>
130
+ [true , 0 , true , 0 , Order::STATE_NEW , Order::STATE_NEW , false , 1 ],
131
+ 'hold - canUnhold -> hold ' =>
132
+ [true , 0 , true , 0 , Order::STATE_HOLDED , Order::STATE_HOLDED , false , 0 , false , true ],
133
+ 'payment_review - canUnhold -> payment_review ' =>
134
+ [true , 0 , true , 0 , Order::STATE_PAYMENT_REVIEW , Order::STATE_PAYMENT_REVIEW , false , 0 , false , true ],
135
+ 'pending_payment - canUnhold -> pending_payment ' =>
136
+ [true , 0 , true , 0 , Order::STATE_PENDING_PAYMENT , Order::STATE_PENDING_PAYMENT , false , 0 , false , true ],
137
+ 'cancelled - isCanceled -> cancelled ' =>
138
+ [true , 0 , true , 0 , Order::STATE_HOLDED , Order::STATE_HOLDED , false , 0 , true ],
139
+ ];
178
140
}
179
141
}
0 commit comments