@@ -92,10 +92,11 @@ protected function setUp(): void
92
92
$ this ->priceInfo = $ this ->createMock (Base::class);
93
93
$ this ->priceInfo ->expects ($ this ->any ())->method ('getPrice ' )->willReturn ($ basePrice );
94
94
$ this ->product = $ this ->getMockBuilder (Product::class)
95
- ->setMethods (['getPriceInfo ' , 'getOptionById ' , 'getResource ' ])
95
+ ->setMethods (['getPriceInfo ' , 'getOptionById ' , 'getResource ' , ' getId ' ])
96
96
->disableOriginalConstructor ()
97
97
->getMock ();
98
98
$ this ->product ->expects ($ this ->once ())->method ('getPriceInfo ' )->willReturn ($ this ->priceInfo );
99
+ $ this ->product ->expects ($ this ->any ())->method ('getId ' )->willReturn (123 );
99
100
100
101
$ this ->item = $ this ->getMockBuilder (ItemInterface::class)
101
102
->getMock ();
@@ -124,7 +125,16 @@ protected function setUp(): void
124
125
->getMock ();
125
126
$ this ->discountCalculator ->expects ($ this ->any ())->method ('calculateDiscount ' )
126
127
->willReturn (-5.0 );
127
- $ this ->model = new ConfiguredPrice ($ this ->product , 1 , $ this ->calculator , $ this ->priceCurrencyMock , $ this ->discountCalculator ,null , $ this ->jsonSerializerMock , $ this ->configuredPriceSelectionMock );
128
+ $ this ->model = new ConfiguredPrice (
129
+ $ this ->product ,
130
+ 1 ,
131
+ $ this ->calculator ,
132
+ $ this ->priceCurrencyMock ,
133
+ $ this ->discountCalculator ,
134
+ null ,
135
+ $ this ->jsonSerializerMock ,
136
+ $ this ->configuredPriceSelectionMock
137
+ );
128
138
$ this ->model ->setItem ($ this ->item );
129
139
}
130
140
@@ -141,6 +151,7 @@ private function prepareAndReturnSelectionPriceDataStub()
141
151
$ second
142
152
];
143
153
}
154
+
144
155
/**
145
156
* Test of value getter
146
157
*/
@@ -149,4 +160,23 @@ public function testGetValueMethod()
149
160
$ valueFromMock = $ this ->model ->getValue ();
150
161
$ this ->assertEquals (95. , $ valueFromMock );
151
162
}
163
+
164
+ /**
165
+ * Test of value getter if no product item
166
+ */
167
+ public function testGetValueMethodNoItem ()
168
+ {
169
+ unset($ this ->item );
170
+ $ this ->product = $ this ->getMockBuilder (Product::class)
171
+ //->setMethods(['getPriceInfo', 'getOptionById', 'getResource', 'getId'])
172
+ ->disableOriginalConstructor ()
173
+ ->getMock ();
174
+ $ this ->item = $ this ->getMockBuilder (ItemInterface::class)
175
+ ->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 );
179
+ $ valueFromMock = $ this ->model ->getValue ();
180
+ $ this ->assertEquals (100. , $ valueFromMock );
181
+ }
152
182
}
0 commit comments