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