66namespace Magento \Customer \Test \Unit \Model \ResourceModel ;
77
88use Magento \Customer \Api \Data \AddressInterface as AddressData ;
9- use Magento \Directory \Model \ResourceModel \Country \Collection as Countries ;
109use Magento \Framework \Exception \InputException ;
10+ use Magento \Store \Model \ScopeInterface ;
1111
1212/**
1313 * Unit test for Magento\Customer\Model\ResourceModel\AddressRepository
@@ -71,6 +71,16 @@ class AddressRepositoryTest extends \PHPUnit_Framework_TestCase
7171 */
7272 protected $ repository ;
7373
74+ /**
75+ * @var \Magento\Directory\Model\AllowedCountries|\PHPUnit_Framework_MockObject_MockObject
76+ */
77+ private $ allowedCountriesReaderMock ;
78+
79+ /**
80+ * @var \Magento\Customer\Model\Config\Share|\PHPUnit_Framework_MockObject_MockObject
81+ */
82+ private $ shareConfigMock ;
83+
7484 protected function setUp ()
7585 {
7686 $ this ->addressFactory = $ this ->getMock (
@@ -137,6 +147,26 @@ protected function setUp()
137147 false
138148 );
139149
150+ $ this ->allowedCountriesReaderMock = $ this ->getMock (
151+ \Magento \Directory \Model \AllowedCountries::class,
152+ ['getAllowedCountries ' ],
153+ [],
154+ '' ,
155+ false
156+ );
157+ $ this ->shareConfigMock = $ this ->getMock (
158+ \Magento \Customer \Model \Config \Share::class,
159+ ['isGlobalScope ' ],
160+ [],
161+ '' ,
162+ false
163+ );
164+ $ this ->shareConfigMock ->method ('isGlobalScope ' )->willReturn (false );
165+ $ this ->allowedCountriesReaderMock
166+ ->method ('getAllowedCountries ' )
167+ ->with (ScopeInterface::SCOPE_WEBSITE , null )
168+ ->willReturn (['1 ' , '2 ' ]);
169+
140170 $ this ->repository = new \Magento \Customer \Model \ResourceModel \AddressRepository (
141171 $ this ->addressFactory ,
142172 $ this ->addressRegistry ,
@@ -145,7 +175,9 @@ protected function setUp()
145175 $ this ->directoryData ,
146176 $ this ->addressSearchResultsFactory ,
147177 $ this ->addressCollectionFactory ,
148- $ this ->extensionAttributesJoinProcessor
178+ $ this ->extensionAttributesJoinProcessor ,
179+ $ this ->allowedCountriesReaderMock ,
180+ $ this ->shareConfigMock
149181 );
150182 }
151183
@@ -315,15 +347,6 @@ public function testSaveWithInvalidRegion()
315347 ->method ('getRegion ' )
316348 ->willReturn ('' );
317349
318- /** @var \PHPUnit_Framework_MockObject_MockObject $countryCollection */
319- $ countryCollection = $ this ->getMockBuilder (Countries::class)
320- ->disableOriginalConstructor ()
321- ->getMock ();
322- $ countryCollection ->expects ($ this ->once ())->method ('getAllIds ' )->willReturn (['1 ' , '2 ' ]);
323- $ this ->directoryData ->expects ($ this ->once ())
324- ->method ('getCountryCollection ' )
325- ->willReturn ($ countryCollection );
326-
327350 $ this ->repository ->save ($ customerAddress );
328351 }
329352
@@ -408,15 +431,6 @@ public function testSaveWithInvalidRegionId()
408431 ->method ('getRegion ' )
409432 ->willReturn ('' );
410433
411- /** @var \PHPUnit_Framework_MockObject_MockObject $countryCollection */
412- $ countryCollection = $ this ->getMockBuilder (Countries::class)
413- ->disableOriginalConstructor ()
414- ->getMock ();
415- $ countryCollection ->expects ($ this ->once ())->method ('getAllIds ' )->willReturn (['1 ' , '2 ' ]);
416- $ this ->directoryData ->expects ($ this ->once ())
417- ->method ('getCountryCollection ' )
418- ->willReturn ($ countryCollection );
419-
420434 $ this ->repository ->save ($ customerAddress );
421435 }
422436
@@ -714,15 +728,6 @@ private function prepareAddressData($countryId, $regionId)
714728 $ countryModel ->expects ($ this ->any ())->method ('getRegionCollection ' )->willReturn ($ regionCollection );
715729 $ regionCollection ->expects ($ this ->any ())->method ('getAllIds ' )->willReturn (['3 ' , '4 ' ]);
716730
717- /** @var \PHPUnit_Framework_MockObject_MockObject $countryCollection */
718- $ countryCollection = $ this ->getMockBuilder (Countries::class)
719- ->disableOriginalConstructor ()
720- ->getMock ();
721- $ countryCollection ->expects ($ this ->once ())->method ('getAllIds ' )->willReturn (['1 ' , '2 ' ]);
722- $ this ->directoryData ->expects ($ this ->once ())
723- ->method ('getCountryCollection ' )
724- ->willReturn ($ countryCollection );
725-
726731 return $ customerAddress ;
727732 }
728733}
0 commit comments