|
14 | 14 | * Class CarrierTest
|
15 | 15 | * @package Magento\Fedex\Model
|
16 | 16 | * TODO refactor me
|
| 17 | + * |
| 18 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
17 | 19 | */
|
18 | 20 | class CarrierTest extends \PHPUnit_Framework_TestCase
|
19 | 21 | {
|
@@ -50,89 +52,126 @@ class CarrierTest extends \PHPUnit_Framework_TestCase
|
50 | 52 | protected function setUp()
|
51 | 53 | {
|
52 | 54 | $this->scope = $this->getMockBuilder(
|
53 |
| - '\Magento\Framework\App\Config\ScopeConfigInterface' |
| 55 | + \Magento\Framework\App\Config\ScopeConfigInterface::class |
54 | 56 | )->disableOriginalConstructor()->getMock();
|
55 | 57 |
|
56 |
| - $this->scope->expects( |
57 |
| - $this->any() |
58 |
| - )->method( |
59 |
| - 'getValue' |
60 |
| - )->will( |
61 |
| - $this->returnCallback([$this, 'scopeConfiggetValue']) |
62 |
| - ); |
63 |
| - |
| 58 | + $this->scope->expects($this->any())->method('getValue')->willReturnCallback([$this, 'scopeConfiggetValue']); |
64 | 59 | $country = $this->getMock(
|
65 |
| - 'Magento\Directory\Model\Country', |
| 60 | + \Magento\Directory\Model\Country::class, |
66 | 61 | ['load', 'getData', '__wakeup'],
|
67 | 62 | [],
|
68 | 63 | '',
|
69 | 64 | false
|
70 | 65 | );
|
71 | 66 | $country->expects($this->any())->method('load')->will($this->returnSelf());
|
72 |
| - $countryFactory = $this->getMock('Magento\Directory\Model\CountryFactory', ['create'], [], '', false); |
| 67 | + $countryFactory = $this->getMock(\Magento\Directory\Model\CountryFactory::class, ['create'], [], '', false); |
73 | 68 | $countryFactory->expects($this->any())->method('create')->will($this->returnValue($country));
|
74 | 69 |
|
75 |
| - $rate = $this->getMock('Magento\Shipping\Model\Rate\Result', ['getError'], [], '', false); |
76 |
| - $rateFactory = $this->getMock('Magento\Shipping\Model\Rate\ResultFactory', ['create'], [], '', false); |
| 70 | + $rate = $this->getMock(\Magento\Shipping\Model\Rate\Result::class, ['getError'], [], '', false); |
| 71 | + $rateFactory = $this->getMock(\Magento\Shipping\Model\Rate\ResultFactory::class, ['create'], [], '', false); |
77 | 72 | $rateFactory->expects($this->any())->method('create')->will($this->returnValue($rate));
|
78 |
| - |
79 |
| - $this->error = $this->getMockBuilder('\Magento\Quote\Model\Quote\Address\RateResult\Error') |
80 |
| - ->setMethods(['setCarrier', 'setCarrierTitle', 'setErrorMessage']) |
81 |
| - ->getMock(); |
82 |
| - $this->errorFactory = $this->getMockBuilder('Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory') |
83 |
| - ->disableOriginalConstructor() |
84 |
| - ->setMethods(['create']) |
85 |
| - ->getMock(); |
| 73 | + $this->error = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address\RateResult\Error::class) |
| 74 | + ->setMethods(['setCarrier', 'setCarrierTitle', 'setErrorMessage'])->getMock(); |
| 75 | + $this->errorFactory = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory::class) |
| 76 | + ->disableOriginalConstructor()->setMethods(['create'])->getMock(); |
86 | 77 | $this->errorFactory->expects($this->any())->method('create')->willReturn($this->error);
|
87 | 78 |
|
88 |
| - $store = $this->getMock('Magento\Store\Model\Store', ['getBaseCurrencyCode', '__wakeup'], [], '', false); |
89 |
| - $storeManager = $this->getMockForAbstractClass('Magento\Store\Model\StoreManagerInterface'); |
| 79 | + $store = $this->getMock(\Magento\Store\Model\Store::class, ['getBaseCurrencyCode', '__wakeup'], [], '', false); |
| 80 | + $storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class); |
90 | 81 | $storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
|
91 |
| - $priceCurrency = $this->getMockBuilder('Magento\Framework\Pricing\PriceCurrencyInterface')->getMock(); |
| 82 | + $priceCurrency = $this->getMockBuilder(\Magento\Framework\Pricing\PriceCurrencyInterface::class)->getMock(); |
92 | 83 |
|
93 | 84 | $rateMethod = $this->getMock(
|
94 |
| - 'Magento\Quote\Model\Quote\Address\RateResult\Method', |
| 85 | + \Magento\Quote\Model\Quote\Address\RateResult\Method::class, |
95 | 86 | null,
|
96 | 87 | ['priceCurrency' => $priceCurrency]
|
97 | 88 | );
|
98 | 89 | $rateMethodFactory = $this->getMock(
|
99 |
| - 'Magento\Quote\Model\Quote\Address\RateResult\MethodFactory', |
| 90 | + \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory::class, |
100 | 91 | ['create'],
|
101 | 92 | [],
|
102 | 93 | '',
|
103 | 94 | false
|
104 | 95 | );
|
105 | 96 | $rateMethodFactory->expects($this->any())->method('create')->will($this->returnValue($rateMethod));
|
106 | 97 | $this->_model = $this->getMock(
|
107 |
| - 'Magento\Fedex\Model\Carrier', |
| 98 | + \Magento\Fedex\Model\Carrier::class, |
108 | 99 | ['_getCachedQuotes', '_debug'],
|
109 | 100 | [
|
110 | 101 | 'scopeConfig' => $this->scope,
|
111 | 102 | 'rateErrorFactory' => $this->errorFactory,
|
112 |
| - 'logger' => $this->getMock('Psr\Log\LoggerInterface'), |
| 103 | + 'logger' => $this->getMock(\Psr\Log\LoggerInterface::class), |
113 | 104 | 'xmlSecurity' => new Security(),
|
114 |
| - 'xmlElFactory' => $this->getMock('Magento\Shipping\Model\Simplexml\ElementFactory', [], [], '', false), |
| 105 | + 'xmlElFactory' => $this->getMock( |
| 106 | + \Magento\Shipping\Model\Simplexml\ElementFactory::class, |
| 107 | + [], |
| 108 | + [], |
| 109 | + '', |
| 110 | + false |
| 111 | + ), |
115 | 112 | 'rateFactory' => $rateFactory,
|
116 | 113 | 'rateMethodFactory' => $rateMethodFactory,
|
117 |
| - 'trackFactory' => $this->getMock('Magento\Shipping\Model\Tracking\ResultFactory', [], [], '', false), |
| 114 | + 'trackFactory' => $this->getMock( |
| 115 | + \Magento\Shipping\Model\Tracking\ResultFactory::class, |
| 116 | + [], |
| 117 | + [], |
| 118 | + '', |
| 119 | + false |
| 120 | + ), |
118 | 121 | 'trackErrorFactory' =>
|
119 |
| - $this->getMock('Magento\Shipping\Model\Tracking\Result\ErrorFactory', [], [], '', false), |
| 122 | + $this->getMock(\Magento\Shipping\Model\Tracking\Result\ErrorFactory::class, [], [], '', false), |
120 | 123 | 'trackStatusFactory' =>
|
121 |
| - $this->getMock('Magento\Shipping\Model\Tracking\Result\StatusFactory', [], [], '', false), |
122 |
| - 'regionFactory' => $this->getMock('Magento\Directory\Model\RegionFactory', [], [], '', false), |
| 124 | + $this->getMock(\Magento\Shipping\Model\Tracking\Result\StatusFactory::class, [], [], '', false), |
| 125 | + 'regionFactory' => $this->getMock(\Magento\Directory\Model\RegionFactory::class, [], [], '', false), |
123 | 126 | 'countryFactory' => $countryFactory,
|
124 |
| - 'currencyFactory' => $this->getMock('Magento\Directory\Model\CurrencyFactory', [], [], '', false), |
125 |
| - 'directoryData' => $this->getMock('Magento\Directory\Helper\Data', [], [], '', false), |
126 |
| - 'stockRegistry' => $this->getMock('Magento\CatalogInventory\Model\StockRegistry', [], [], '', false), |
| 127 | + 'currencyFactory' => $this->getMock(\Magento\Directory\Model\CurrencyFactory::class, [], [], '', false), |
| 128 | + 'directoryData' => $this->getMock(\Magento\Directory\Helper\Data::class, [], [], '', false), |
| 129 | + 'stockRegistry' => $this->getMock( |
| 130 | + \Magento\CatalogInventory\Model\StockRegistry::class, |
| 131 | + [], |
| 132 | + [], |
| 133 | + '', |
| 134 | + false |
| 135 | + ), |
127 | 136 | 'storeManager' => $storeManager,
|
128 |
| - 'configReader' => $this->getMock('Magento\Framework\Module\Dir\Reader', [], [], '', false), |
| 137 | + 'configReader' => $this->getMock(\Magento\Framework\Module\Dir\Reader::class, [], [], '', false), |
129 | 138 | 'productCollectionFactory' =>
|
130 |
| - $this->getMock('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory', [], [], '', false), |
| 139 | + $this->getMock( |
| 140 | + \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class, |
| 141 | + [], |
| 142 | + [], |
| 143 | + '', |
| 144 | + false |
| 145 | + ), |
131 | 146 | 'data' => []
|
132 | 147 | ]
|
133 | 148 | );
|
134 | 149 | }
|
135 | 150 |
|
| 151 | + public function testSetRequestWithoutCity() |
| 152 | + { |
| 153 | + $requestMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address\RateRequest::class) |
| 154 | + ->disableOriginalConstructor() |
| 155 | + ->setMethods(['getDestCity']) |
| 156 | + ->getMock(); |
| 157 | + $requestMock->expects($this->once()) |
| 158 | + ->method('getDestCity') |
| 159 | + ->willReturn(null); |
| 160 | + $this->_model->setRequest($requestMock); |
| 161 | + } |
| 162 | + |
| 163 | + public function testSetRequestWithCity() |
| 164 | + { |
| 165 | + $requestMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Address\RateRequest::class) |
| 166 | + ->disableOriginalConstructor() |
| 167 | + ->setMethods(['getDestCity']) |
| 168 | + ->getMock(); |
| 169 | + $requestMock->expects($this->exactly(2)) |
| 170 | + ->method('getDestCity') |
| 171 | + ->willReturn('Small Town'); |
| 172 | + $this->_model->setRequest($requestMock); |
| 173 | + } |
| 174 | + |
136 | 175 | /**
|
137 | 176 | * Callback function, emulates getValue function
|
138 | 177 | * @param $path
|
@@ -179,7 +218,16 @@ public function testCollectRatesRateAmountOriginBased($amount, $rateType, $expec
|
179 | 218 | $this->_model->expects($this->any())->method('_getCachedQuotes')->will(
|
180 | 219 | $this->returnValue(serialize($response))
|
181 | 220 | );
|
182 |
| - $request = $this->getMock('Magento\Quote\Model\Quote\Address\RateRequest', [], [], '', false); |
| 221 | + $request = $this->getMock( |
| 222 | + \Magento\Quote\Model\Quote\Address\RateRequest::class, |
| 223 | + ['getDestCity'], |
| 224 | + [], |
| 225 | + '', |
| 226 | + false |
| 227 | + ); |
| 228 | + $request->expects($this->exactly(2)) |
| 229 | + ->method('getDestCity') |
| 230 | + ->willReturn('Wonderful City'); |
183 | 231 | foreach ($this->_model->collectRates($request)->getAllRates() as $allRates) {
|
184 | 232 | $this->assertEquals($expected, $allRates->getData('cost'));
|
185 | 233 | }
|
|
0 commit comments