6
6
7
7
namespace Magento \Customer \Test \Unit \Model \Address \Validator ;
8
8
9
+ use Magento \Store \Model \ScopeInterface ;
10
+
9
11
/**
10
12
* Magento\Customer\Model\Address\Validator\Country tests.
11
13
*/
@@ -20,14 +22,34 @@ class CountryTest extends \PHPUnit\Framework\TestCase
20
22
/** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
21
23
private $ objectManager ;
22
24
25
+ /**
26
+ * @var \Magento\Directory\Model\AllowedCountries|\PHPUnit_Framework_MockObject_MockObject
27
+ */
28
+ private $ allowedCountriesReaderMock ;
29
+
30
+ /**
31
+ * @var \Magento\Customer\Model\Config\Share|\PHPUnit_Framework_MockObject_MockObject
32
+ */
33
+ private $ shareConfigMock ;
34
+
23
35
protected function setUp ()
24
36
{
25
37
$ this ->directoryDataMock = $ this ->createMock (\Magento \Directory \Helper \Data::class);
26
38
$ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
39
+ $ this ->allowedCountriesReaderMock = $ this ->createPartialMock (
40
+ \Magento \Directory \Model \AllowedCountries::class,
41
+ ['getAllowedCountries ' ]
42
+ );
43
+ $ this ->shareConfigMock = $ this ->createPartialMock (
44
+ \Magento \Customer \Model \Config \Share::class,
45
+ ['isGlobalScope ' ]
46
+ );
27
47
$ this ->model = $ this ->objectManager ->getObject (
28
48
\Magento \Customer \Model \Address \Validator \Country::class,
29
49
[
30
50
'directoryData ' => $ this ->directoryDataMock ,
51
+ 'allowedCountriesReader ' => $ this ->allowedCountriesReaderMock ,
52
+ 'shareConfig ' => $ this ->shareConfigMock ,
31
53
]
32
54
);
33
55
}
@@ -59,16 +81,11 @@ public function testValidate(array $data, array $countryIds, array $allowedRegio
59
81
->method ('isRegionRequired ' )
60
82
->willReturn ($ data ['regionRequired ' ]);
61
83
62
- $ countryCollectionMock = $ this ->getMockBuilder (\Magento \Directory \Model \ResourceModel \Country \Collection::class)
63
- ->disableOriginalConstructor ()
64
- ->setMethods (['getAllIds ' ])
65
- ->getMock ();
66
-
67
- $ this ->directoryDataMock ->expects ($ this ->any ())
68
- ->method ('getCountryCollection ' )
69
- ->willReturn ($ countryCollectionMock );
70
-
71
- $ countryCollectionMock ->expects ($ this ->any ())->method ('getAllIds ' )->willReturn ($ countryIds );
84
+ $ this ->shareConfigMock ->method ('isGlobalScope ' )->willReturn (false );
85
+ $ this ->allowedCountriesReaderMock
86
+ ->method ('getAllowedCountries ' )
87
+ ->with (ScopeInterface::SCOPE_WEBSITE , null )
88
+ ->willReturn ($ countryIds );
72
89
73
90
$ addressMock ->method ('getCountryId ' )->willReturn ($ data ['country_id ' ]);
74
91
0 commit comments