6
6
7
7
namespace Magento \SalesRule \Test \Unit \Model ;
8
8
9
+ use Magento \Framework \Event \Manager ;
10
+ use Magento \Quote \Model \Quote ;
11
+ use Magento \Quote \Model \Quote \Address ;
12
+ use Magento \Quote \Model \Quote \Item ;
13
+ use Magento \Quote \Model \Quote \Item \AbstractItem ;
14
+ use Magento \Rule \Model \Action \Collection ;
15
+ use Magento \SalesRule \Model \Quote \ChildrenValidationLocator ;
16
+ use Magento \SalesRule \Model \Rule ;
17
+ use Magento \SalesRule \Model \Rule \Action \Discount \CalculatorFactory ;
18
+ use Magento \SalesRule \Model \Rule \Action \Discount \Data ;
19
+ use Magento \SalesRule \Model \Rule \Action \Discount \DiscountInterface ;
20
+ use Magento \SalesRule \Model \RulesApplier ;
21
+ use Magento \SalesRule \Model \Utility ;
22
+ use PHPUnit \Framework \TestCase ;
23
+ use PHPUnit_Framework_MockObject_MockObject ;
24
+
9
25
/**
10
26
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
11
27
*/
12
- class RulesApplierTest extends \ PHPUnit \ Framework \ TestCase
28
+ class RulesApplierTest extends TestCase
13
29
{
14
30
/**
15
- * @var \Magento\SalesRule\Model\ RulesApplier
31
+ * @var RulesApplier
16
32
*/
17
33
protected $ rulesApplier ;
18
34
19
35
/**
20
- * @var \Magento\SalesRule\Model\Rule\Action\Discount\ CalculatorFactory|\ PHPUnit_Framework_MockObject_MockObject
36
+ * @var CalculatorFactory|PHPUnit_Framework_MockObject_MockObject
21
37
*/
22
38
protected $ calculatorFactory ;
23
39
24
40
/**
25
- * @var \Magento\Framework\Event\ Manager|\ PHPUnit_Framework_MockObject_MockObject
41
+ * @var Manager|PHPUnit_Framework_MockObject_MockObject
26
42
*/
27
43
protected $ eventManager ;
28
44
29
45
/**
30
- * @var \Magento\SalesRule\Model\ Utility|\ PHPUnit_Framework_MockObject_MockObject
46
+ * @var Utility|PHPUnit_Framework_MockObject_MockObject
31
47
*/
32
48
protected $ validatorUtility ;
33
49
34
50
/**
35
- * @var \Magento\SalesRule\Model\Quote\ ChildrenValidationLocator|\ PHPUnit_Framework_MockObject_MockObject
51
+ * @var ChildrenValidationLocator|PHPUnit_Framework_MockObject_MockObject
36
52
*/
37
53
protected $ childrenValidationLocator ;
38
54
39
55
protected function setUp ()
40
56
{
41
57
$ this ->calculatorFactory = $ this ->createMock (
42
- \ Magento \ SalesRule \ Model \ Rule \ Action \ Discount \ CalculatorFactory::class
58
+ CalculatorFactory::class
43
59
);
44
- $ this ->eventManager = $ this ->createPartialMock (\ Magento \ Framework \ Event \ Manager::class, ['dispatch ' ]);
60
+ $ this ->eventManager = $ this ->createPartialMock (Manager::class, ['dispatch ' ]);
45
61
$ this ->validatorUtility = $ this ->createPartialMock (
46
- \ Magento \ SalesRule \ Model \ Utility::class,
62
+ Utility::class,
47
63
['canProcessRule ' , 'minFix ' , 'deltaRoundingFix ' , 'getItemQty ' ]
48
64
);
49
65
$ this ->childrenValidationLocator = $ this ->createPartialMock (
50
- \ Magento \ SalesRule \ Model \ Quote \ ChildrenValidationLocator::class,
66
+ ChildrenValidationLocator::class,
51
67
['isChildrenValidationRequired ' ]
52
68
);
53
- $ this ->rulesApplier = new \ Magento \ SalesRule \ Model \ RulesApplier (
69
+ $ this ->rulesApplier = new RulesApplier (
54
70
$ this ->calculatorFactory ,
55
71
$ this ->eventManager ,
56
72
$ this ->validatorUtility ,
@@ -75,19 +91,21 @@ public function testApplyRulesWhenRuleWithStopRulesProcessingIsUsed($isChildren,
75
91
$ appliedRuleIds = [$ ruleId => $ ruleId ];
76
92
77
93
/**
78
- * @var \Magento\SalesRule\Model\ Rule|\ PHPUnit_Framework_MockObject_MockObject $ruleWithStopFurtherProcessing
94
+ * @var Rule|PHPUnit_Framework_MockObject_MockObject $ruleWithStopFurtherProcessing
79
95
*/
80
96
$ ruleWithStopFurtherProcessing = $ this ->createPartialMock (
81
- \ Magento \ SalesRule \ Model \ Rule::class,
97
+ Rule::class,
82
98
['getStoreLabel ' , 'getCouponType ' , 'getRuleId ' , '__wakeup ' , 'getActions ' ]
83
99
);
84
- /** @var \Magento\SalesRule\Model\Rule|\PHPUnit_Framework_MockObject_MockObject $ruleThatShouldNotBeRun */
100
+ /**
101
+ * @var Rule|PHPUnit_Framework_MockObject_MockObject $ruleThatShouldNotBeRun
102
+ */
85
103
$ ruleThatShouldNotBeRun = $ this ->createPartialMock (
86
- \ Magento \ SalesRule \ Model \ Rule::class,
104
+ Rule::class,
87
105
['getStopRulesProcessing ' , '__wakeup ' ]
88
106
);
89
107
90
- $ actionMock = $ this ->createPartialMock (\ Magento \ Rule \ Model \ Action \ Collection::class, ['validate ' ]);
108
+ $ actionMock = $ this ->createPartialMock (Collection::class, ['validate ' ]);
91
109
92
110
$ ruleWithStopFurtherProcessing ->setName ('ruleWithStopFurtherProcessing ' );
93
111
$ ruleThatShouldNotBeRun ->setName ('ruleThatShouldNotBeRun ' );
@@ -146,22 +164,27 @@ public function testAddCouponDescriptionWithRuleDescriptionIsUsed()
146
164
$ ruleDescription = 'Rule description ' ;
147
165
148
166
/**
149
- * @var \Magento\SalesRule\Model\ Rule|\ PHPUnit_Framework_MockObject_MockObject $rule
167
+ * @var Rule|PHPUnit_Framework_MockObject_MockObject $rule
150
168
*/
151
169
$ rule = $ this ->createPartialMock (
152
- \ Magento \ SalesRule \ Model \ Rule::class,
170
+ Rule::class,
153
171
['getStoreLabel ' , 'getCouponType ' , 'getRuleId ' , '__wakeup ' , 'getActions ' ]
154
- );
172
+ );
155
173
156
174
$ rule ->setDescription ($ ruleDescription );
157
175
158
- /** @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject $address */
159
- $ address = $ this ->createPartialMock (\Magento \Quote \Model \Quote \Address::class, [
176
+ /**
177
+ * @var Address|PHPUnit_Framework_MockObject_MockObject $address
178
+ */
179
+ $ address = $ this ->createPartialMock (
180
+ Address::class,
181
+ [
160
182
'getQuote ' ,
161
183
'setCouponCode ' ,
162
184
'setAppliedRuleIds ' ,
163
185
'__wakeup '
164
- ]);
186
+ ]
187
+ );
165
188
$ description = $ address ->getDiscountDescriptionArray ();
166
189
$ description [$ ruleId ] = $ rule ->getDescription ();
167
190
$ address ->setDiscountDescriptionArray ($ description [$ ruleId ]);
@@ -181,28 +204,38 @@ public function dataProviderChildren()
181
204
}
182
205
183
206
/**
184
- * @return \Magento\Quote\Model\Quote\Item\ AbstractItem|\ PHPUnit_Framework_MockObject_MockObject
207
+ * @return AbstractItem|PHPUnit_Framework_MockObject_MockObject
185
208
*/
186
209
protected function getPreparedItem ()
187
210
{
188
- /** @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject $address */
189
- $ address = $ this ->createPartialMock (\Magento \Quote \Model \Quote \Address::class, [
211
+ /**
212
+ * @var Address|PHPUnit_Framework_MockObject_MockObject $address
213
+ */
214
+ $ address = $ this ->createPartialMock (
215
+ Address::class,
216
+ [
190
217
'getQuote ' ,
191
218
'setCouponCode ' ,
192
219
'setAppliedRuleIds ' ,
193
220
'__wakeup '
194
- ]);
195
- /** @var \Magento\Quote\Model\Quote\Item\AbstractItem|\PHPUnit_Framework_MockObject_MockObject $item */
196
- $ item = $ this ->createPartialMock (\Magento \Quote \Model \Quote \Item::class, [
221
+ ]
222
+ );
223
+ /**
224
+ * @var AbstractItem|PHPUnit_Framework_MockObject_MockObject $item
225
+ */
226
+ $ item = $ this ->createPartialMock (
227
+ Item::class,
228
+ [
197
229
'setDiscountAmount ' ,
198
230
'setBaseDiscountAmount ' ,
199
231
'setDiscountPercent ' ,
200
232
'getAddress ' ,
201
233
'setAppliedRuleIds ' ,
202
234
'__wakeup ' ,
203
235
'getChildren '
204
- ]);
205
- $ quote = $ this ->createPartialMock (\Magento \Quote \Model \Quote::class, ['getStore ' , '__wakeUp ' ]);
236
+ ]
237
+ );
238
+ $ quote = $ this ->createPartialMock (Quote::class, ['getStore ' , '__wakeUp ' ]);
206
239
$ item ->expects ($ this ->any ())->method ('getAddress ' )->will ($ this ->returnValue ($ address ));
207
240
$ address ->expects ($ this ->any ())
208
241
->method ('getQuote ' )
@@ -219,10 +252,10 @@ protected function applyRule($item, $rule)
219
252
{
220
253
$ qty = 2 ;
221
254
$ discountCalc = $ this ->createPartialMock (
222
- \ Magento \ SalesRule \ Model \ Rule \ Action \ Discount \ DiscountInterface::class,
255
+ DiscountInterface::class,
223
256
['fixQuantity ' , 'calculate ' ]
224
257
);
225
- $ discountData = $ this ->getMockBuilder (\ Magento \ SalesRule \ Model \ Rule \ Action \ Discount \ Data::class)
258
+ $ discountData = $ this ->getMockBuilder (Data::class)
226
259
->setConstructorArgs (
227
260
[
228
261
'amount ' => 30 ,
0 commit comments