7
7
8
8
use Magento \Directory \Helper \Data ;
9
9
use Magento \Directory \Model \AllowedCountries ;
10
+ use Magento \Directory \Model \CurrencyFactory ;
11
+ use Magento \Directory \Model \ResourceModel \Country \Collection as CountryCollection ;
12
+ use Magento \Directory \Model \ResourceModel \Region \Collection as RegionCollection ;
13
+ use Magento \Directory \Model \ResourceModel \Region \CollectionFactory ;
14
+ use Magento \Framework \App \Cache \Type \Config ;
10
15
use Magento \Framework \App \Config \ScopeConfigInterface ;
16
+ use Magento \Framework \App \Helper \Context ;
11
17
use Magento \Framework \App \RequestInterface ;
18
+ use Magento \Framework \DataObject ;
19
+ use Magento \Framework \Json \Helper \Data as JsonDataHelper ;
20
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12
21
use Magento \Store \Model \ScopeInterface ;
22
+ use Magento \Store \Model \Store ;
23
+ use Magento \Store \Model \StoreManagerInterface ;
24
+ use PHPUnit \Framework \Constraint \IsIdentical ;
25
+ use PHPUnit \Framework \MockObject \MockObject ;
26
+ use PHPUnit \Framework \TestCase ;
13
27
14
28
/**
15
29
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16
30
*/
17
- class DataTest extends \ PHPUnit \ Framework \ TestCase
31
+ class DataTest extends TestCase
18
32
{
19
33
/**
20
- * @var \Magento\Directory\Model\ResourceModel\Country\Collection|\PHPUnit_Framework_MockObject_MockObject
34
+ * @var CountryCollection|MockObject
21
35
*/
22
36
protected $ _countryCollection ;
23
37
24
38
/**
25
- * @var \Magento\Directory\Model\ResourceModel\Region\ CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
39
+ * @var CollectionFactory|MockObject
26
40
*/
27
41
protected $ _regionCollection ;
28
42
29
43
/**
30
- * @var \Magento\Framework\Json\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
44
+ * @var JsonDataHelper|MockObject
31
45
*/
32
46
protected $ jsonHelperMock ;
33
47
34
48
/**
35
- * @var \Magento\ Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
49
+ * @var Store|MockObject
36
50
*/
37
51
protected $ _store ;
38
52
39
53
/**
40
- * @var \Magento\Framework\App\Config\ ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
54
+ * @var ScopeConfigInterface|MockObject
41
55
*/
42
56
protected $ scopeConfigMock ;
43
57
44
58
/**
45
- * @var \Magento\Directory\Helper\ Data
59
+ * @var Data
46
60
*/
47
61
protected $ _object ;
48
62
49
63
protected function setUp ()
50
64
{
51
- $ objectManager = new \ Magento \ Framework \ TestFramework \ Unit \ Helper \ ObjectManager ($ this );
52
- $ this ->scopeConfigMock = $ this ->createMock (\ Magento \ Framework \ App \ Config \ ScopeConfigInterface::class);
65
+ $ objectManager = new ObjectManager ($ this );
66
+ $ this ->scopeConfigMock = $ this ->createMock (ScopeConfigInterface::class);
53
67
$ this ->scopeConfigMock ->expects ($ this ->any ())->method ('isSetFlag ' )->willReturn (false );
54
68
$ requestMock = $ this ->createMock (RequestInterface::class);
55
- $ context = $ this ->createMock (\ Magento \ Framework \ App \ Helper \ Context::class);
69
+ $ context = $ this ->createMock (Context::class);
56
70
$ context ->method ('getRequest ' )
57
71
->willReturn ($ requestMock );
58
72
$ context ->expects ($ this ->any ())
59
73
->method ('getScopeConfig ' )
60
74
->willReturn ($ this ->scopeConfigMock );
61
- $ configCacheType = $ this ->createMock (\ Magento \ Framework \ App \ Cache \ Type \ Config::class);
75
+ $ configCacheType = $ this ->createMock (Config::class);
62
76
63
- $ this ->_countryCollection = $ this ->createMock (\ Magento \ Directory \ Model \ ResourceModel \ Country \Collection ::class);
77
+ $ this ->_countryCollection = $ this ->createMock (CountryCollection ::class);
64
78
65
- $ this ->_regionCollection = $ this ->createMock (\ Magento \ Directory \ Model \ ResourceModel \ Region \Collection ::class);
79
+ $ this ->_regionCollection = $ this ->createMock (RegionCollection ::class);
66
80
$ regCollectionFactory = $ this ->createPartialMock (
67
- \ Magento \ Directory \ Model \ ResourceModel \ Region \ CollectionFactory::class,
81
+ CollectionFactory::class,
68
82
['create ' ]
69
83
);
70
84
$ regCollectionFactory ->expects (
@@ -75,13 +89,13 @@ protected function setUp()
75
89
$ this ->returnValue ($ this ->_regionCollection )
76
90
);
77
91
78
- $ this ->jsonHelperMock = $ this ->createMock (\ Magento \ Framework \ Json \ Helper \Data ::class);
92
+ $ this ->jsonHelperMock = $ this ->createMock (JsonDataHelper ::class);
79
93
80
- $ this ->_store = $ this ->createMock (\ Magento \ Store \ Model \ Store::class);
81
- $ storeManager = $ this ->createMock (\ Magento \ Store \ Model \ StoreManagerInterface::class);
94
+ $ this ->_store = $ this ->createMock (Store::class);
95
+ $ storeManager = $ this ->createMock (StoreManagerInterface::class);
82
96
$ storeManager ->expects ($ this ->any ())->method ('getStore ' )->will ($ this ->returnValue ($ this ->_store ));
83
97
84
- $ currencyFactory = $ this ->createMock (\ Magento \ Directory \ Model \ CurrencyFactory::class);
98
+ $ currencyFactory = $ this ->createMock (CurrencyFactory::class);
85
99
86
100
$ arguments = [
87
101
'context ' => $ context ,
@@ -92,7 +106,7 @@ protected function setUp()
92
106
'storeManager ' => $ storeManager ,
93
107
'currencyFactory ' => $ currencyFactory ,
94
108
];
95
- $ this ->_object = $ objectManager ->getObject (\ Magento \ Directory \ Helper \ Data::class, $ arguments );
109
+ $ this ->_object = $ objectManager ->getObject (Data::class, $ arguments );
96
110
}
97
111
98
112
public function testGetRegionJson ()
@@ -110,13 +124,13 @@ public function testGetRegionJson()
110
124
]
111
125
);
112
126
$ regions = [
113
- new \ Magento \ Framework \ DataObject (
127
+ new DataObject (
114
128
['country_id ' => 'Country1 ' , 'region_id ' => 'r1 ' , 'code ' => 'r1-code ' , 'name ' => 'r1-name ' ]
115
129
),
116
- new \ Magento \ Framework \ DataObject (
130
+ new DataObject (
117
131
['country_id ' => 'Country1 ' , 'region_id ' => 'r2 ' , 'code ' => 'r2-code ' , 'name ' => 'r2-name ' ]
118
132
),
119
- new \ Magento \ Framework \ DataObject (
133
+ new DataObject (
120
134
['country_id ' => 'Country2 ' , 'region_id ' => 'r3 ' , 'code ' => 'r3-code ' , 'name ' => 'r3-name ' ]
121
135
)
122
136
];
@@ -153,7 +167,7 @@ public function testGetRegionJson()
153
167
)->method (
154
168
'jsonEncode '
155
169
)->with (
156
- new \ PHPUnit \ Framework \ Constraint \ IsIdentical ($ expectedDataToEncode )
170
+ new IsIdentical ($ expectedDataToEncode )
157
171
)->will (
158
172
$ this ->returnValue ('encoded_json ' )
159
173
);
@@ -225,7 +239,7 @@ public function testGetDefaultCountry()
225
239
->method ('getValue ' )
226
240
->with (
227
241
Data::XML_PATH_DEFAULT_COUNTRY ,
228
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE ,
242
+ ScopeInterface::SCOPE_STORE ,
229
243
$ storeId
230
244
)->will ($ this ->returnValue ($ country ));
231
245
@@ -242,7 +256,7 @@ public function testGetCountryCollection()
242
256
$ this ->returnValue (0 )
243
257
);
244
258
245
- $ store = $ this ->createMock (\ Magento \ Store \ Model \ Store::class);
259
+ $ store = $ this ->createMock (Store::class);
246
260
$ this ->_countryCollection ->expects (
247
261
$ this ->once ()
248
262
)->method (
@@ -262,7 +276,7 @@ public function testGetCountryCollection()
262
276
public function testGetTopCountryCodesReturnsParsedConfigurationValue ($ topCountriesValue , $ expectedResult )
263
277
{
264
278
$ this ->scopeConfigMock ->expects ($ this ->once ())
265
- ->method ('getValue ' )->with (\ Magento \ Directory \ Helper \ Data::XML_PATH_TOP_COUNTRIES )
279
+ ->method ('getValue ' )->with (Data::XML_PATH_TOP_COUNTRIES )
266
280
->willReturn ($ topCountriesValue );
267
281
268
282
$ this ->assertEquals ($ expectedResult , $ this ->_object ->getTopCountryCodes ());
0 commit comments