@@ -149,6 +149,16 @@ class AddressTest extends TestCase
149149 */
150150 private $ countryWithWebsites ;
151151
152+ /**
153+ * @var \stdClass|MockObject
154+ */
155+ private $ dataSourceModel ;
156+
157+ /**
158+ * @var \stdClass|MockObject
159+ */
160+ private $ connection ;
161+
152162 /**
153163 * Init entity adapter model
154164 */
@@ -193,10 +203,14 @@ protected function tearDown(): void
193203 */
194204 protected function _getModelDependencies ()
195205 {
196- $ dataSourceModel = $ this ->getMockBuilder (\stdClass::class)->addMethods (['getNextBunch ' ])
206+ $ this ->dataSourceModel = $ this ->getMockBuilder (\stdClass::class)
207+ ->addMethods (['getNextBunch ' , 'getNextUniqueBunch ' , 'getIterator ' , 'rewind ' ])
208+ ->disableOriginalConstructor ()
209+ ->getMock ();
210+ $ this ->connection = $ this ->getMockBuilder (\stdClass::class)
211+ ->addMethods (['insertMultiple ' ])
197212 ->disableOriginalConstructor ()
198213 ->getMock ();
199- $ connection = $ this ->createMock (\stdClass::class);
200214 $ attributeCollection = $ this ->_createAttrCollectionMock ();
201215 $ customerStorage = $ this ->_createCustomerStorageMock ();
202216 $ customerEntity = $ this ->_createCustomerEntityMock ();
@@ -215,8 +229,8 @@ protected function _getModelDependencies()
215229 }
216230
217231 $ data = [
218- 'data_source_model ' => $ dataSourceModel ,
219- 'connection ' => $ connection ,
232+ 'data_source_model ' => $ this -> dataSourceModel ,
233+ 'connection ' => $ this -> connection ,
220234 'page_size ' => 1 ,
221235 'max_data_size ' => 1 ,
222236 'bunch_size ' => 1 ,
@@ -571,4 +585,83 @@ public function validateDeleteAddressEntities(array $deleteRowIds)
571585 $ this ->assertContains ($ this ->_customBehaviour ['delete_id ' ], $ deleteRowIds );
572586 return $ this ->_model ;
573587 }
588+
589+ /**
590+ * @dataProvider importDataProvider
591+ * @param $data
592+ * @return void
593+ * @throws \ReflectionException
594+ */
595+ public function testImportData ($ data ): void
596+ {
597+ $ this ->dataSourceModel ->expects ($ this ->atLeastOnce ())
598+ ->method ('getNextUniqueBunch ' )
599+ ->willReturnOnConsecutiveCalls ($ data );
600+
601+ $ this ->dataSourceModel ->method ('getIterator ' )->willReturnSelf ();
602+ $ this ->setProtectedProperty ($ this ->_model , '_websiteCodeToId ' , [
603+ 'base ' => 1 ,
604+ ]);
605+ $ method = $ this ->setMethodAccessible ('_importData ' );
606+ $ this ->connection ->method ('insertMultiple ' )->willReturnSelf ();
607+ $ method ->invokeArgs ($ this ->_model , []);
608+ }
609+
610+ /**
611+ * @return array
612+ */
613+ public function importDataProvider (): array
614+ {
615+ return [
616+ [
617+ [
618+ '_email ' => 'jondoe@example.com ' ,
619+ '_website ' => 'base ' ,
620+ '_store ' => 'admin ' ,
621+ '_entity_id ' => 'abc '
622+ ]
623+ ],
624+ [
625+ [
626+ '_email ' => 'jondoe@example.com ' ,
627+ '_store ' => 'admin ' ,
628+ '_entity_id ' => 'abc '
629+ ]
630+ ]
631+ ];
632+ }
633+
634+ /**
635+ * Invoke any method of class AdvancedPricing.
636+ *
637+ * @param string $method
638+ *
639+ * @return mixed
640+ * @throws \ReflectionException
641+ */
642+ private function setMethodAccessible ($ method )
643+ {
644+ $ class = new \ReflectionClass (Address::class);
645+ $ method = $ class ->getMethod ($ method );
646+ $ method ->setAccessible (true );
647+ return $ method ;
648+ }
649+
650+ /**
651+ * Sets a protected property on a given object via reflection
652+ *
653+ * @param $object - instance in which protected value is being modified
654+ * @param $property - property on instance being modified
655+ * @param $value - new value of the property being modified
656+ *
657+ * @return void
658+ * @throws \ReflectionException
659+ */
660+ private function setProtectedProperty ($ object , $ property , $ value )
661+ {
662+ $ reflection = new \ReflectionClass ($ object );
663+ $ reflection_property = $ reflection ->getProperty ($ property );
664+ $ reflection_property ->setAccessible (true );
665+ $ reflection_property ->setValue ($ object , $ value );
666+ }
574667}
0 commit comments