1717use PHPUnit \Framework \MockObject \MockObject ;
1818use PHPUnit \Framework \TestCase ;
1919
20+ /**
21+ * Contains tests for Price class
22+ */
2023class PriceTest extends TestCase
2124{
2225 /**
@@ -34,6 +37,9 @@ class PriceTest extends TestCase
3437 */
3538 private $ storeManagerMock ;
3639
40+ /**
41+ * @inheritDoc
42+ */
3743 protected function setUp (): void
3844 {
3945 $ objectManager = new ObjectManager ($ this );
@@ -57,12 +63,20 @@ protected function setUp(): void
5763 }
5864
5965 /**
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
6372 * @dataProvider testPrepareDataSourceDataProvider
6473 */
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
6680 {
6781 $ itemName = 'itemName ' ;
6882 $ oldItemValue = 'oldItemValue ' ;
@@ -79,6 +93,7 @@ public function testPrepareDataSource($hasCurrency, $dataSource, $currencyCode)
7993 ->willReturn ($ currencyCode );
8094 $ this ->storeManagerMock ->expects ($ hasCurrency ? $ this ->never () : $ this ->once ())
8195 ->method ('getStore ' )
96+ ->with ($ expectedStoreId )
8297 ->willReturn ($ store );
8398 $ store ->expects ($ hasCurrency ? $ this ->never () : $ this ->once ())
8499 ->method ('getBaseCurrency ' )
@@ -98,7 +113,12 @@ public function testPrepareDataSource($hasCurrency, $dataSource, $currencyCode)
98113 $ this ->assertEquals ($ newItemValue , $ dataSource ['data ' ]['items ' ][0 ][$ itemName ]);
99114 }
100115
101- public function testPrepareDataSourceDataProvider ()
116+ /**
117+ * Provider for testPrepareDataSource
118+ *
119+ * @return array
120+ */
121+ public function testPrepareDataSourceDataProvider (): array
102122 {
103123 $ dataSource1 = [
104124 'data ' => [
@@ -119,9 +139,31 @@ public function testPrepareDataSourceDataProvider()
119139 ]
120140 ]
121141 ];
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+ ];
122162 return [
123163 [true , $ dataSource1 , 'US ' ],
124164 [false , $ dataSource2 , 'SAR ' ],
165+ [false , $ dataSource3 , 'SAR ' , 2 ],
166+ [false , $ dataSource4 , 'SAR ' ],
125167 ];
126168 }
127169}
0 commit comments