17
17
use PHPUnit \Framework \MockObject \MockObject ;
18
18
use PHPUnit \Framework \TestCase ;
19
19
20
+ /**
21
+ * Contains tests for Price class
22
+ */
20
23
class PriceTest extends TestCase
21
24
{
22
25
/**
@@ -34,6 +37,9 @@ class PriceTest extends TestCase
34
37
*/
35
38
private $ storeManagerMock ;
36
39
40
+ /**
41
+ * @inheritDoc
42
+ */
37
43
protected function setUp (): void
38
44
{
39
45
$ objectManager = new ObjectManager ($ this );
@@ -57,12 +63,20 @@ protected function setUp(): void
57
63
}
58
64
59
65
/**
60
- * @param $hasCurrency
61
- * @param $dataSource
62
- * @param $currencyCode
66
+ * Test for prepareDataSource method
67
+ *
68
+ * @param bool $hasCurrency
69
+ * @param array $dataSource
70
+ * @param string $currencyCode
71
+ * @param int|null $expectedStoreId
63
72
* @dataProvider testPrepareDataSourceDataProvider
64
73
*/
65
- public function testPrepareDataSource ($ hasCurrency , $ dataSource , $ currencyCode )
74
+ public function testPrepareDataSource (
75
+ bool $ hasCurrency ,
76
+ array $ dataSource ,
77
+ string $ currencyCode ,
78
+ ?int $ expectedStoreId = null
79
+ ): void
66
80
{
67
81
$ itemName = 'itemName ' ;
68
82
$ oldItemValue = 'oldItemValue ' ;
@@ -79,6 +93,7 @@ public function testPrepareDataSource($hasCurrency, $dataSource, $currencyCode)
79
93
->willReturn ($ currencyCode );
80
94
$ this ->storeManagerMock ->expects ($ hasCurrency ? $ this ->never () : $ this ->once ())
81
95
->method ('getStore ' )
96
+ ->with ($ expectedStoreId )
82
97
->willReturn ($ store );
83
98
$ store ->expects ($ hasCurrency ? $ this ->never () : $ this ->once ())
84
99
->method ('getBaseCurrency ' )
@@ -98,7 +113,12 @@ public function testPrepareDataSource($hasCurrency, $dataSource, $currencyCode)
98
113
$ this ->assertEquals ($ newItemValue , $ dataSource ['data ' ]['items ' ][0 ][$ itemName ]);
99
114
}
100
115
101
- public function testPrepareDataSourceDataProvider ()
116
+ /**
117
+ * Provider for testPrepareDataSource
118
+ *
119
+ * @return array
120
+ */
121
+ public function testPrepareDataSourceDataProvider (): array
102
122
{
103
123
$ dataSource1 = [
104
124
'data ' => [
@@ -119,9 +139,31 @@ public function testPrepareDataSourceDataProvider()
119
139
]
120
140
]
121
141
];
142
+ $ dataSource3 = [
143
+ 'data ' => [
144
+ 'items ' => [
145
+ [
146
+ 'itemName ' => 'oldItemValue ' ,
147
+ 'store_id ' => '2 '
148
+ ]
149
+ ]
150
+ ]
151
+ ];
152
+ $ dataSource4 = [
153
+ 'data ' => [
154
+ 'items ' => [
155
+ [
156
+ 'itemName ' => 'oldItemValue ' ,
157
+ 'store_id ' => 'abc '
158
+ ]
159
+ ]
160
+ ]
161
+ ];
122
162
return [
123
163
[true , $ dataSource1 , 'US ' ],
124
164
[false , $ dataSource2 , 'SAR ' ],
165
+ [false , $ dataSource3 , 'SAR ' , 2 ],
166
+ [false , $ dataSource4 , 'SAR ' ],
125
167
];
126
168
}
127
169
}
0 commit comments