6
6
namespace Magento \Ups \Test \Unit \Model ;
7
7
8
8
use Magento \Quote \Model \Quote \Address \RateRequest ;
9
+ use Magento \Ups \Model \Carrier ;
10
+ use Magento \Directory \Model \Country ;
11
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
9
12
13
+ /**
14
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15
+ */
10
16
class CarrierTest extends \PHPUnit_Framework_TestCase
11
17
{
12
18
const FREE_METHOD_NAME = 'free_method ' ;
@@ -19,10 +25,12 @@ class CarrierTest extends \PHPUnit_Framework_TestCase
19
25
* @var \Magento\Quote\Model\Quote\Address\RateResult\Error|\PHPUnit_Framework_MockObject_MockObject
20
26
*/
21
27
protected $ error ;
28
+
22
29
/**
23
30
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
24
31
*/
25
32
protected $ helper ;
33
+
26
34
/**
27
35
* Model under test
28
36
*
@@ -51,7 +59,7 @@ class CarrierTest extends \PHPUnit_Framework_TestCase
51
59
protected $ countryFactory ;
52
60
53
61
/**
54
- * @var \Magento\Directory\Model\ Country
62
+ * @var Country|MockObject
55
63
*/
56
64
protected $ country ;
57
65
@@ -70,7 +78,7 @@ protected function setUp()
70
78
$ this ->helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
71
79
72
80
$ this ->scope = $ this ->getMockBuilder (
73
- ' \Magento\Framework\App\Config\ScopeConfigInterface '
81
+ \Magento \Framework \App \Config \ScopeConfigInterface::class
74
82
)->disableOriginalConstructor ()->getMock ();
75
83
76
84
$ this ->scope ->expects (
@@ -81,43 +89,43 @@ protected function setUp()
81
89
$ this ->returnCallback ([$ this , 'scopeConfiggetValue ' ])
82
90
);
83
91
84
- $ this ->error = $ this ->getMockBuilder (' \Magento\Quote\Model\Quote\Address\RateResult\Error ' )
92
+ $ this ->error = $ this ->getMockBuilder (\Magento \Quote \Model \Quote \Address \RateResult \Error::class )
85
93
->setMethods (['setCarrier ' , 'setCarrierTitle ' , 'setErrorMessage ' ])
86
94
->getMock ();
87
95
88
- $ this ->errorFactory = $ this ->getMockBuilder (' Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory ' )
96
+ $ this ->errorFactory = $ this ->getMockBuilder (\ Magento \Quote \Model \Quote \Address \RateResult \ErrorFactory::class )
89
97
->disableOriginalConstructor ()
90
98
->setMethods (['create ' ])
91
99
->getMock ();
92
100
93
101
$ this ->errorFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ this ->error );
94
102
95
- $ this ->rate = $ this ->getMock (' Magento\Shipping\Model\Rate\Result ' , ['getError ' ], [], '' , false );
96
- $ rateFactory = $ this ->getMock (' Magento\Shipping\Model\Rate\ResultFactory ' , ['create ' ], [], '' , false );
103
+ $ this ->rate = $ this ->getMock (\ Magento \Shipping \Model \Rate \Result::class , ['getError ' ], [], '' , false );
104
+ $ rateFactory = $ this ->getMock (\ Magento \Shipping \Model \Rate \ResultFactory::class , ['create ' ], [], '' , false );
97
105
98
106
$ rateFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ this ->rate );
99
107
100
- $ this ->country = $ this ->getMockBuilder (' \Magento\Directory\Model\Country ' )
108
+ $ this ->country = $ this ->getMockBuilder (\Magento \Directory \Model \Country::class )
101
109
->disableOriginalConstructor ()
102
110
->setMethods (['load ' ])
103
111
->getMock ();
104
112
105
- $ this ->abstractModel = $ this ->getMockBuilder (' Magento\Framework\Model\AbstractModel ' )
113
+ $ this ->abstractModel = $ this ->getMockBuilder (\ Magento \Framework \Model \AbstractModel::class )
106
114
->disableOriginalConstructor ()
107
115
->setMethods (['getData ' ])
108
116
->getMock ();
109
117
110
118
$ this ->country ->expects ($ this ->any ())->method ('load ' )->willReturn ($ this ->abstractModel );
111
119
112
- $ this ->countryFactory = $ this ->getMockBuilder (' \Magento\Directory\Model\CountryFactory ' )
120
+ $ this ->countryFactory = $ this ->getMockBuilder (\Magento \Directory \Model \CountryFactory::class )
113
121
->disableOriginalConstructor ()
114
122
->setMethods (['create ' ])
115
123
->getMock ();
116
124
117
125
$ this ->countryFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ this ->country );
118
126
119
127
$ this ->model = $ this ->helper ->getObject (
120
- ' Magento\Ups\Model\Carrier ' ,
128
+ \ Magento \Ups \Model \Carrier::class ,
121
129
[
122
130
'scopeConfig ' => $ this ->scope ,
123
131
'rateErrorFactory ' => $ this ->errorFactory ,
@@ -233,4 +241,47 @@ public function testCollectRatesFail()
233
241
234
242
$ this ->assertSame ($ this ->rate , $ this ->model ->collectRates ($ request ));
235
243
}
244
+
245
+ /**
246
+ * @covers \Magento\Ups\Model\Carrier::setRequest
247
+ * @param string $countryCode
248
+ * @param string $foundCountryCode
249
+ * @dataProvider countryDataProvider
250
+ */
251
+ public function testSetRequest ($ countryCode , $ foundCountryCode )
252
+ {
253
+ /** @var RateRequest $request */
254
+ $ request = $ this ->helper ->getObject (RateRequest::class);
255
+ $ request ->setData ([
256
+ 'orig_country ' => 'USA ' ,
257
+ 'orig_region_code ' => 'CA ' ,
258
+ 'orig_post_code ' => 90230 ,
259
+ 'orig_city ' => 'Culver City ' ,
260
+ 'dest_country_id ' => $ countryCode ,
261
+ ]);
262
+
263
+ $ this ->country ->expects (static ::at (1 ))
264
+ ->method ('load ' )
265
+ ->with ($ countryCode )
266
+ ->willReturnSelf ();
267
+
268
+ $ this ->country ->expects (static ::any ())
269
+ ->method ('getData ' )
270
+ ->with ('iso2_code ' )
271
+ ->willReturn ($ foundCountryCode );
272
+
273
+ $ this ->model ->setRequest ($ request );
274
+ }
275
+
276
+ /**
277
+ * Get list of country variations
278
+ * @return array
279
+ */
280
+ public function countryDataProvider ()
281
+ {
282
+ return [
283
+ ['countryCode ' => 'PR ' , 'foundCountryCode ' => null ],
284
+ ['countryCode ' => 'US ' , 'foundCountryCode ' => 'US ' ],
285
+ ];
286
+ }
236
287
}
0 commit comments