16
16
use Magento \Framework \Currency \Exception \CurrencyException ;
17
17
use Magento \Framework \DataObject ;
18
18
use Magento \Framework \Exception \LocalizedException ;
19
- use Magento \Framework \Exception \NoSuchEntityException ;
20
19
use Magento \Framework \Locale \CurrencyInterface ;
21
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
22
20
use Magento \Reports \Block \Adminhtml \Grid \Column \Renderer \Currency ;
23
21
use Magento \Store \Api \Data \StoreInterface ;
24
- use Magento \Store \Api \Data \WebsiteInterface ;
25
22
use Magento \Store \Model \StoreManagerInterface ;
23
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
24
+ use PHPUnit \Framework \MockObject \Exception ;
26
25
use PHPUnit \Framework \MockObject \MockObject ;
27
26
use PHPUnit \Framework \TestCase ;
28
27
29
28
/**
30
29
* Test for class Currency.
31
30
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
32
31
*/
32
+ #[\AllowDynamicProperties] //@phpstan-ignore-line
33
33
class CurrencyTest extends TestCase
34
34
{
35
35
/**
@@ -57,21 +57,11 @@ class CurrencyTest extends TestCase
57
57
*/
58
58
private $ gridColumnMock ;
59
59
60
- /**
61
- * @var ScopeConfigInterface|MockObject
62
- */
63
- private $ scopeConfigMock ;
64
-
65
60
/**
66
61
* @var StoreInterface|MockObject
67
62
*/
68
63
private $ storeMock ;
69
64
70
- /**
71
- * @var WebsiteInterface|MockObject
72
- */
73
- private $ websiteMock ;
74
-
75
65
/**
76
66
* @var DataObject
77
67
*/
@@ -110,26 +100,6 @@ protected function setUp(): void
110
100
['getStore ' , 'getWebsite ' ]
111
101
);
112
102
113
- $ this ->storeMock = $ this ->getMockForAbstractClass (
114
- StoreInterface::class,
115
- [],
116
- '' ,
117
- true ,
118
- true ,
119
- true ,
120
- ['getWebsiteId ' , 'getCurrentCurrencyCode ' ]
121
- );
122
-
123
- $ this ->websiteMock = $ this ->getMockForAbstractClass (
124
- WebsiteInterface::class,
125
- [],
126
- '' ,
127
- true ,
128
- true ,
129
- true ,
130
- ['getBaseCurrencyCode ' ]
131
- );
132
-
133
103
$ this ->currencyLocatorMock = $ this ->getMockBuilder (DefaultLocator::class)
134
104
->disableOriginalConstructor ()
135
105
->getMock ();
@@ -175,32 +145,19 @@ protected function setUp(): void
175
145
*
176
146
* @param float $rate
177
147
* @param string $columnIndex
178
- * @param int $catalogPriceScope
179
- * @param int $adminWebsiteId
180
- * @param string $adminCurrencyCode
181
148
* @param string $storeCurrencyCode
182
- * @param string $displayCurrencyCode
183
149
* @param string $adminOrderAmount
184
150
* @param string $convertedAmount
185
- * @param bool $needToGetRateFromModel
186
151
* @throws LocalizedException
187
- * @throws NoSuchEntityException
188
- * @throws CurrencyException
152
+ * @throws CurrencyException|Exception
189
153
* @dataProvider getCurrencyDataProvider
190
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
191
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
192
154
*/
193
155
public function testRender (
194
156
float $ rate ,
195
157
string $ columnIndex ,
196
- int $ catalogPriceScope ,
197
- int $ adminWebsiteId ,
198
- string $ adminCurrencyCode ,
199
158
string $ storeCurrencyCode ,
200
- string $ displayCurrencyCode ,
201
159
string $ adminOrderAmount ,
202
160
string $ convertedAmount ,
203
- bool $ needToGetRateFromModel
204
161
): void {
205
162
$ this ->row = new DataObject (
206
163
[
@@ -220,35 +177,14 @@ public function testRender(
220
177
->expects ($ this ->any ())
221
178
->method ('getRate ' )
222
179
->willReturn ($ rate );
223
- $ this ->scopeConfigMock
224
- ->expects ($ this ->any ())
225
- ->method ('getValue ' )
226
- ->willReturn ($ catalogPriceScope );
227
180
$ this ->storeManagerMock
228
181
->expects ($ this ->any ())
229
182
->method ('getStore ' )
230
183
->willReturn ($ this ->storeMock );
231
- $ this ->storeMock
232
- ->expects ($ this ->any ())
233
- ->method ('getWebsiteId ' )
234
- ->willReturn ($ adminWebsiteId );
235
- $ this ->storeManagerMock
236
- ->expects ($ this ->any ())
237
- ->method ('getWebsite ' )
238
- ->with ($ adminWebsiteId )
239
- ->willReturn ($ this ->websiteMock );
240
- $ this ->websiteMock
241
- ->expects ($ this ->any ())
242
- ->method ('getBaseCurrencyCode ' )
243
- ->willReturn ($ adminCurrencyCode );
244
184
$ this ->currencyLocatorMock
245
185
->expects ($ this ->any ())
246
186
->method ('getDefaultCurrency ' )
247
187
->willReturn ($ storeCurrencyCode );
248
- $ this ->currencyLocatorMock
249
- ->expects ($ this ->any ())
250
- ->method ('getDisplayCurrency ' )
251
- ->willReturn ($ displayCurrencyCode );
252
188
$ currLocaleMock = $ this ->createMock (CurrencyData::class);
253
189
$ currLocaleMock
254
190
->expects ($ this ->any ())
@@ -257,18 +193,11 @@ public function testRender(
257
193
$ this ->localeCurrencyMock
258
194
->expects ($ this ->any ())
259
195
->method ('getCurrency ' )
260
- ->with ($ displayCurrencyCode )
196
+ ->with ($ storeCurrencyCode )
261
197
->willReturn ($ currLocaleMock );
262
- $ this ->gridColumnMock ->method ('getCurrency ' )->willReturn ($ displayCurrencyCode );
198
+ $ this ->gridColumnMock ->method ('getCurrency ' )->willReturn ($ storeCurrencyCode );
263
199
$ this ->gridColumnMock ->method ('getRateField ' )->willReturn ('test_rate_field ' );
264
200
265
- if ($ needToGetRateFromModel ) {
266
- $ this ->currencyMock ->expects ($ this ->once ())
267
- ->method ('getAnyRate ' )
268
- ->with ($ storeCurrencyCode )
269
- ->willReturn ($ rate );
270
- }
271
-
272
201
$ actualAmount = $ this ->model ->render ($ this ->row );
273
202
$ this ->assertEquals ($ convertedAmount , $ actualAmount );
274
203
}
@@ -281,64 +210,21 @@ public function testRender(
281
210
public static function getCurrencyDataProvider (): array
282
211
{
283
212
return [
284
- 'rate conversion with same admin and storefront rate ' => [
285
- 'rate ' => 1.00 ,
286
- 'columnIndex ' => 'total_income_amount ' ,
287
- 'catalogPriceScope ' => 1 ,
288
- 'adminWebsiteId ' => 1 ,
289
- 'adminCurrencyCode ' => 'EUR ' ,
290
- 'storeCurrencyCode ' => 'EUR ' ,
291
- 'displayCurrencyCode ' => 'EUR ' ,
292
- 'adminOrderAmount ' => '105.00 ' ,
293
- 'convertedAmount ' => '€105.00 ' ,
294
- 'needToGetRateFromModel ' => false
295
- ],
296
- 'rate conversion with different admin and storefront rate ' => [
297
- 'rate ' => 1.4150 ,
213
+ 'rate conversion with storefront ' => [
214
+ 'rate ' => 1.367 ,
298
215
'columnIndex ' => 'total_income_amount ' ,
299
- 'catalogPriceScope ' => 1 ,
300
- 'adminWebsiteId ' => 1 ,
301
- 'adminCurrencyCode ' => 'USD ' ,
302
216
'storeCurrencyCode ' => 'EUR ' ,
303
- 'displayCurrencyCode ' => 'EUR ' ,
304
- 'adminOrderAmount ' => '105.00 ' ,
305
- 'convertedAmount ' => '148.575 ' ,
306
- 'needToGetRateFromModel ' => true
307
- ],
308
- 'rate conversation with same rate for different currencies ' => [
309
- 'rate ' => 1.00 ,
310
- 'columnIndex ' => 'total_income_amount ' ,
311
- 'catalogPriceScope ' => 1 ,
312
- 'adminWebsiteId ' => 1 ,
313
- 'adminCurrencyCode ' => 'USD ' ,
314
- 'storeCurrencyCode ' => 'THB ' ,
315
- 'displayCurrencyCode ' => 'THB ' ,
316
217
'adminOrderAmount ' => '100.00 ' ,
317
- 'convertedAmount ' => '100.00 ' ,
318
- 'needToGetRateFromModel ' => true
319
- ],
320
- 'rate conversation with different rate for different display currencies ' => [
321
- 'rate ' => 1.6150 ,
322
- 'columnIndex ' => 'total_income_amount ' ,
323
- 'catalogPriceScope ' => 1 ,
324
- 'adminWebsiteId ' => 1 ,
325
- 'adminCurrencyCode ' => 'USD ' ,
326
- 'storeCurrencyCode ' => 'USD ' ,
327
- 'displayCurrencyCode ' => 'EUR ' ,
328
- 'adminOrderAmount ' => '$100.00 ' ,
329
- 'convertedAmount ' => '€161.50 ' ,
330
- 'needToGetRateFromModel ' => false
218
+ 'convertedAmount ' => '€136.70 ' ,
331
219
],
332
220
];
333
221
}
334
222
335
223
protected function tearDown (): void
336
224
{
337
- unset($ this ->scopeConfigMock );
338
225
unset($ this ->storeManagerMock );
339
226
unset($ this ->currencyLocatorMock );
340
227
unset($ this ->localeCurrencyMock );
341
- unset($ this ->websiteMock );
342
228
unset($ this ->storeMock );
343
229
unset($ this ->currencyMock );
344
230
unset($ this ->backendCurrencyMock );
0 commit comments