6
6
namespace Magento \Customer \Test \Unit \Model \ResourceModel ;
7
7
8
8
use Magento \Customer \Api \Data \AddressInterface as AddressData ;
9
- use Magento \Directory \Model \ResourceModel \Country \Collection as Countries ;
10
9
use Magento \Framework \Exception \InputException ;
10
+ use Magento \Store \Model \ScopeInterface ;
11
11
12
12
/**
13
13
* Unit test for Magento\Customer\Model\ResourceModel\AddressRepository
@@ -71,6 +71,16 @@ class AddressRepositoryTest extends \PHPUnit_Framework_TestCase
71
71
*/
72
72
protected $ repository ;
73
73
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
+
74
84
protected function setUp ()
75
85
{
76
86
$ this ->addressFactory = $ this ->getMock (
@@ -137,6 +147,26 @@ protected function setUp()
137
147
false
138
148
);
139
149
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
+
140
170
$ this ->repository = new \Magento \Customer \Model \ResourceModel \AddressRepository (
141
171
$ this ->addressFactory ,
142
172
$ this ->addressRegistry ,
@@ -145,7 +175,9 @@ protected function setUp()
145
175
$ this ->directoryData ,
146
176
$ this ->addressSearchResultsFactory ,
147
177
$ this ->addressCollectionFactory ,
148
- $ this ->extensionAttributesJoinProcessor
178
+ $ this ->extensionAttributesJoinProcessor ,
179
+ $ this ->allowedCountriesReaderMock ,
180
+ $ this ->shareConfigMock
149
181
);
150
182
}
151
183
@@ -315,15 +347,6 @@ public function testSaveWithInvalidRegion()
315
347
->method ('getRegion ' )
316
348
->willReturn ('' );
317
349
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
-
327
350
$ this ->repository ->save ($ customerAddress );
328
351
}
329
352
@@ -408,15 +431,6 @@ public function testSaveWithInvalidRegionId()
408
431
->method ('getRegion ' )
409
432
->willReturn ('' );
410
433
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
-
420
434
$ this ->repository ->save ($ customerAddress );
421
435
}
422
436
@@ -714,15 +728,6 @@ private function prepareAddressData($countryId, $regionId)
714
728
$ countryModel ->expects ($ this ->any ())->method ('getRegionCollection ' )->willReturn ($ regionCollection );
715
729
$ regionCollection ->expects ($ this ->any ())->method ('getAllIds ' )->willReturn (['3 ' , '4 ' ]);
716
730
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
-
726
731
return $ customerAddress ;
727
732
}
728
733
}
0 commit comments