10
10
use Magento \Bundle \Pricing \Price \DiscountCalculator ;
11
11
use Magento \Catalog \Model \Product ;
12
12
use Magento \Catalog \Model \Product \Configuration \Item \ItemInterface ;
13
- use Magento \Catalog \Model \Product \Configuration \Item \Option \OptionInterface ;
14
- use Magento \Catalog \Model \Product \Option ;
15
- use Magento \Catalog \Model \Product \Option \Type \DefaultType ;
16
13
use Magento \Bundle \Pricing \Price \ConfiguredPrice ;
17
14
use Magento \Bundle \Pricing \Adjustment \Calculator ;
18
15
use Magento \Catalog \Pricing \Price \ConfiguredPriceSelection ;
@@ -33,53 +30,57 @@ class ConfiguredPriceTest extends TestCase
33
30
/**
34
31
* @var float
35
32
*/
36
- protected $ basePriceValue = 100. ;
33
+ private $ basePriceValue = 100. ;
37
34
38
35
/**
39
- * @var MockObject
36
+ * @var ItemInterface| MockObject
40
37
*/
41
- protected $ item ;
38
+ private $ itemMock ;
42
39
43
40
/**
44
- * @var MockObject
41
+ * @var Product| MockObject
45
42
*/
46
- protected $ product ;
43
+ private $ productMock ;
47
44
48
45
/**
49
46
* @var MockObject
50
47
*/
51
- protected $ calculator ;
48
+ private $ calculator ;
52
49
53
50
/**
54
- * @var MockObject
51
+ * @var Base| MockObject
55
52
*/
56
- protected $ priceInfo ;
53
+ private $ priceInfoMock ;
57
54
58
55
/**
59
56
* @var ConfiguredPrice
60
57
*/
61
- protected $ model ;
58
+ private $ model ;
62
59
63
60
/**
64
61
* @var PriceCurrencyInterface|MockObject
65
62
*/
66
- protected $ priceCurrencyMock ;
63
+ private $ priceCurrencyMock ;
64
+
67
65
/**
68
66
* @var Json|MockObject
69
67
*/
70
68
private $ jsonSerializerMock ;
69
+
71
70
/**
72
71
* @var ConfiguredPriceSelection|MockObject
73
72
*/
74
73
private $ configuredPriceSelectionMock ;
74
+
75
75
/**
76
76
* @var AmountInterface|MockObject
77
77
*/
78
78
private $ amountInterfaceMock ;
79
+
79
80
/**
80
81
* @var DiscountCalculator|MockObject
81
82
*/
82
- private $ discountCalculator ;
83
+ private $ discountCalculatorMock ;
83
84
84
85
/**
85
86
* Initialize base dependencies
@@ -89,18 +90,18 @@ protected function setUp(): void
89
90
$ basePrice = $ this ->getMockForAbstractClass (PriceInterface::class);
90
91
$ basePrice ->expects ($ this ->any ())->method ('getValue ' )->willReturn ($ this ->basePriceValue );
91
92
92
- $ this ->priceInfo = $ this ->createMock (Base::class);
93
- $ this ->priceInfo ->expects ($ this ->any ())->method ('getPrice ' )->willReturn ($ basePrice );
94
- $ this ->product = $ this ->getMockBuilder (Product::class)
93
+ $ this ->priceInfoMock = $ this ->createMock (Base::class);
94
+ $ this ->priceInfoMock ->expects ($ this ->any ())->method ('getPrice ' )->willReturn ($ basePrice );
95
+ $ this ->productMock = $ this ->getMockBuilder (Product::class)
95
96
->setMethods (['getPriceInfo ' , 'getOptionById ' , 'getResource ' , 'getId ' ])
96
97
->disableOriginalConstructor ()
97
98
->getMock ();
98
- $ this ->product ->expects ($ this ->once ())->method ('getPriceInfo ' )->willReturn ($ this ->priceInfo );
99
- $ this ->product ->expects ($ this ->any ())->method ('getId ' )->willReturn (123 );
99
+ $ this ->productMock ->expects ($ this ->once ())->method ('getPriceInfo ' )->willReturn ($ this ->priceInfoMock );
100
+ $ this ->productMock ->expects ($ this ->any ())->method ('getId ' )->willReturn (123 );
100
101
101
- $ this ->item = $ this ->getMockBuilder (ItemInterface::class)
102
+ $ this ->itemMock = $ this ->getMockBuilder (ItemInterface::class)
102
103
->getMock ();
103
- $ this ->item ->expects ($ this ->any ())->method ('getProduct ' )->willReturn ($ this ->product );
104
+ $ this ->itemMock ->expects ($ this ->any ())->method ('getProduct ' )->willReturn ($ this ->productMock );
104
105
105
106
$ this ->priceCurrencyMock = $ this ->getMockForAbstractClass (PriceCurrencyInterface::class);
106
107
@@ -120,42 +121,28 @@ protected function setUp(): void
120
121
->getMock ();
121
122
$ this ->calculator ->expects ($ this ->any ())->method ('calculateBundleAmount ' )
122
123
->willReturn ($ this ->amountInterfaceMock );
123
- $ this ->discountCalculator = $ this ->getMockBuilder (DiscountCalculator::class)
124
+ $ this ->discountCalculatorMock = $ this ->getMockBuilder (DiscountCalculator::class)
124
125
->disableOriginalConstructor ()
125
126
->getMock ();
126
- $ this ->discountCalculator ->expects ($ this ->any ())->method ('calculateDiscount ' )
127
+ $ this ->discountCalculatorMock ->expects ($ this ->any ())->method ('calculateDiscount ' )
127
128
->willReturn (-5.0 );
128
129
$ this ->model = new ConfiguredPrice (
129
- $ this ->product ,
130
+ $ this ->productMock ,
130
131
1 ,
131
132
$ this ->calculator ,
132
133
$ this ->priceCurrencyMock ,
133
134
null ,
134
135
$ this ->jsonSerializerMock ,
135
136
$ this ->configuredPriceSelectionMock ,
136
- $ this ->discountCalculator ,
137
+ $ this ->discountCalculatorMock ,
137
138
);
138
- $ this ->model ->setItem ($ this ->item );
139
- }
140
-
141
- private function prepareAndReturnSelectionPriceDataStub ()
142
- {
143
- $ first = new DataObject ();
144
- $ first ->setValue (2 );
145
- $ first ->setQuantity (1 );
146
- $ second = new DataObject ();
147
- $ second ->setValue (3 );
148
- $ second ->setQuantity (1 );
149
- return [
150
- $ first ,
151
- $ second
152
- ];
139
+ $ this ->model ->setItem ($ this ->itemMock );
153
140
}
154
141
155
142
/**
156
143
* Test of value getter when item presented
157
144
*/
158
- public function testGetValueMethod ()
145
+ public function testGetValueMethod (): void
159
146
{
160
147
$ valueFromMock = $ this ->model ->getValue ();
161
148
$ this ->assertEquals (95. , $ valueFromMock );
@@ -164,19 +151,35 @@ public function testGetValueMethod()
164
151
/**
165
152
* Test of value getter if no product item
166
153
*/
167
- public function testGetValueMethodNoItem ()
154
+ public function testGetValueMethodNoItem (): void
168
155
{
169
- unset($ this ->item );
170
- $ this ->product = $ this ->getMockBuilder (Product::class)
171
- //->setMethods(['getPriceInfo', 'getOptionById', 'getResource', 'getId'])
156
+ $ this ->productMock = $ this ->getMockBuilder (Product::class)
172
157
->disableOriginalConstructor ()
173
158
->getMock ();
174
- $ this ->item = $ this ->getMockBuilder (ItemInterface::class)
159
+ $ this ->itemMock = $ this ->getMockBuilder (ItemInterface::class)
175
160
->getMock ();
176
- $ this ->item ->expects ($ this ->any ())->method ('getProduct ' )->willReturn ($ this ->product );
177
- $ this ->product ->expects ($ this ->any ())->method ('getId ' )->willReturn (false );
178
- $ this ->model ->setItem ($ this ->item );
161
+ $ this ->itemMock ->expects ($ this ->any ())->method ('getProduct ' )->willReturn ($ this ->productMock );
162
+ $ this ->productMock ->expects ($ this ->any ())->method ('getId ' )->willReturn (false );
163
+ $ this ->model ->setItem ($ this ->itemMock );
179
164
$ valueFromMock = $ this ->model ->getValue ();
180
165
$ this ->assertEquals (100. , $ valueFromMock );
181
166
}
167
+
168
+ /**
169
+ * Stub data for calculation amount of bundle
170
+ * @return \Magento\Framework\DataObject[]
171
+ */
172
+ private function prepareAndReturnSelectionPriceDataStub (): array
173
+ {
174
+ $ first = new DataObject ();
175
+ $ first ->setValue (2 );
176
+ $ first ->setQuantity (1 );
177
+ $ second = new DataObject ();
178
+ $ second ->setValue (3 );
179
+ $ second ->setQuantity (1 );
180
+ return [
181
+ $ first ,
182
+ $ second
183
+ ];
184
+ }
182
185
}
0 commit comments