Skip to content

Commit bec6aa8

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-69185' into NORD-BUGFIXES-PR
2 parents 70e695c + fb47a1e commit bec6aa8

File tree

2 files changed

+85
-41
lines changed

2 files changed

+85
-41
lines changed

app/code/Magento/Shipping/Model/Shipping/Labels.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ public function requestToShipment(Shipment $orderShipment)
122122
|| !$storeInfo->getName()
123123
|| !$storeInfo->getPhone()
124124
|| !$originStreet1
125-
|| !$shipperRegionCode
126125
|| !$this->_scopeConfig->getValue(
127126
Shipment::XML_PATH_STORE_CITY,
128127
ScopeInterface::SCOPE_STORE,

app/code/Magento/Shipping/Test/Unit/Model/Shipping/LabelsTest.php

Lines changed: 85 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
*/
66
namespace Magento\Shipping\Test\Unit\Model\Shipping;
77

8-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9-
use Magento\Framework\DataObject;
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
109
use Magento\Sales\Model\Order\Shipment;
1110
use Magento\Store\Model\ScopeInterface;
1211

@@ -39,6 +38,16 @@ class LabelsTest extends \PHPUnit_Framework_TestCase
3938
*/
4039
protected $region;
4140

41+
/**
42+
* @var \PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
private $carrierFactory;
45+
46+
/**
47+
* @var \PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
private $user;
50+
4251
protected function setUp()
4352
{
4453
$this->request = $this->getMockBuilder(\Magento\Shipping\Model\Shipment\Request::class)
@@ -49,32 +58,32 @@ protected function setUp()
4958
->setMethods(['create'])
5059
->getMock();
5160
$requestFactory->expects(static::any())->method('create')->willReturn($this->request);
52-
53-
$carrier = $this->getMockBuilder(\Magento\Shipping\Model\Carrier\AbstractCarrier::class)
61+
$this->carrierFactory = $this->getMockBuilder(\Magento\Shipping\Model\CarrierFactory::class)
5462
->disableOriginalConstructor()
63+
->setMethods(['create'])
5564
->getMock();
56-
57-
$carrierFactory = $this->getMockBuilder(\Magento\Shipping\Model\CarrierFactory::class)
65+
$storeManager = $this->getStoreManager();
66+
$this->user = $this->getMockBuilder(\Magento\User\Model\User::class)
5867
->disableOriginalConstructor()
59-
->setMethods(['create'])
68+
->setMethods(['getFirstname', 'getLastname', 'getEmail', 'getName'])
6069
->getMock();
61-
$carrierFactory->expects(static::any())->method('create')->willReturn($carrier);
6270

63-
$storeManager = $this->getStoreManager();
64-
$authSession = $this->getAuthSession();
71+
$authSession = $this->getMockBuilder(\Magento\Backend\Model\Auth\Session::class)
72+
->disableOriginalConstructor()
73+
->setMethods(['getUser'])
74+
->getMock();
75+
$authSession->expects(static::any())->method('getUser')->willReturn($this->user);
6576
$regionFactory = $this->getRegionFactory();
66-
6777
$this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config::class)
6878
->disableOriginalConstructor()
6979
->setMethods(['getValue'])
7080
->getMock();
71-
72-
$objectManagerHelper = new ObjectManager($this);
81+
$objectManagerHelper = new ObjectManagerHelper($this);
7382
$this->labels = $objectManagerHelper->getObject(
7483
\Magento\Shipping\Model\Shipping\Labels::class,
7584
[
7685
'shipmentRequestFactory' => $requestFactory,
77-
'carrierFactory' => $carrierFactory,
86+
'carrierFactory' => $this->carrierFactory,
7887
'storeManager' => $storeManager,
7988
'scopeConfig' => $this->scopeConfig,
8089
'authSession' => $authSession,
@@ -84,14 +93,21 @@ protected function setUp()
8493
}
8594

8695
/**
87-
* @covers \Magento\Shipping\Model\Shipping\Labels
96+
* @dataProvider requestToShipmentDataProvider
8897
*/
89-
public function testRequestToShipment()
98+
public function testRequestToShipment($regionId)
9099
{
100+
$carrier = $this->getMockBuilder(\Magento\Shipping\Model\Carrier\AbstractCarrier::class)
101+
->disableOriginalConstructor()
102+
->getMock();
103+
$this->carrierFactory->expects(static::any())->method('create')->willReturn($carrier);
91104
$order = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
92105
->disableOriginalConstructor()
93106
->getMock();
94-
107+
$this->user->expects($this->atLeastOnce())->method('getFirstname')->willReturn('John');
108+
$this->user->expects($this->atLeastOnce())->method('getLastname')->willReturn('Doe');
109+
$this->user->expects($this->once())->method('getName')->willReturn('John Doe');
110+
$this->user->expects($this->once())->method('getEmail')->willReturn('admin@admin.test.com');
95111
$shippingMethod = $this->getMockBuilder(\Magento\Framework\DataObject::class)
96112
->disableOriginalConstructor()
97113
->setMethods(['getCarrierCode'])
@@ -125,7 +141,7 @@ public function testRequestToShipment()
125141
$this->scopeConfig->expects(static::any())
126142
->method('getValue')
127143
->willReturnMap([
128-
[Shipment::XML_PATH_STORE_REGION_ID, ScopeInterface::SCOPE_STORE, $storeId, 'CA'],
144+
[Shipment::XML_PATH_STORE_REGION_ID, ScopeInterface::SCOPE_STORE, $storeId, $regionId],
129145
[Shipment::XML_PATH_STORE_ADDRESS1, ScopeInterface::SCOPE_STORE, $storeId, 'Beverly Heals'],
130146
['general/store_information', ScopeInterface::SCOPE_STORE, $storeId, [
131147
'name' => 'General Store', 'phone' => '(244)1500301'
@@ -135,38 +151,35 @@ public function testRequestToShipment()
135151
[Shipment::XML_PATH_STORE_COUNTRY_ID, ScopeInterface::SCOPE_STORE, $storeId, 'US'],
136152
[Shipment::XML_PATH_STORE_ADDRESS2, ScopeInterface::SCOPE_STORE, $storeId, '1st Park Avenue'],
137153
]);
138-
139154
$this->labels->requestToShipment($shipment);
140155
}
141156

142157
/**
143-
* @return \PHPUnit_Framework_MockObject_MockObject
158+
* @expectedException \Magento\Framework\Exception\LocalizedException
159+
* @dataProvider testRequestToShipmentLocalizedExceptionDataProvider
144160
*/
145-
protected function getAuthSession()
161+
public function testRequestToShipmentLocalizedException($isShipmentCarrierNotNull)
146162
{
147-
$user = $this->getMockBuilder(\Magento\User\Model\User::class)
163+
$order = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
148164
->disableOriginalConstructor()
149-
->setMethods(['getFirstname', 'getLastname', 'getEmail', 'getName'])
150165
->getMock();
151-
$user->expects(static::exactly(2))
152-
->method('getFirstname')
153-
->willReturn('John');
154-
$user->expects(static::exactly(2))
155-
->method('getLastname')
156-
->willReturn('Doe');
157-
$user->expects(static::once())
158-
->method('getName')
159-
->willReturn('John Doe');
160-
$user->expects(static::once())
161-
->method('getEmail')
162-
->willReturn('admin@admin.test.com');
163-
164-
$authSession = $this->getMockBuilder(\Magento\Backend\Model\Auth\Session::class)
166+
$shipment = $this->getMockBuilder(\Magento\Sales\Model\Order\Shipment::class)
165167
->disableOriginalConstructor()
166-
->setMethods(['getUser'])
167168
->getMock();
168-
$authSession->expects(static::any())->method('getUser')->willReturn($user);
169-
return $authSession;
169+
$shippingMethod = $this->getMockBuilder(\Magento\Framework\DataObject::class)
170+
->disableOriginalConstructor()
171+
->setMethods(['getCarrierCode'])
172+
->getMock();
173+
$order->expects($this->atLeastOnce())
174+
->method('getShippingMethod')
175+
->with(true)
176+
->willReturn($shippingMethod);
177+
$this->carrierFactory
178+
->expects(static::any())
179+
->method('create')
180+
->willReturn($isShipmentCarrierNotNull ? $shippingMethod : null);
181+
$shipment->expects($this->once())->method('getOrder')->willReturn($order);
182+
$this->labels->requestToShipment($shipment);
170183
}
171184

172185
/**
@@ -246,4 +259,36 @@ protected function getRecipientAddress()
246259
->willReturn(1);
247260
return $address;
248261
}
262+
263+
/**
264+
* Data provider to testRequestToShipment
265+
* @return array
266+
*/
267+
public function requestToShipmentDataProvider()
268+
{
269+
return [
270+
[
271+
'CA'
272+
],
273+
[
274+
null
275+
]
276+
];
277+
}
278+
279+
/**
280+
* Data provider to testRequestToShipmentLocalizedException
281+
* @return array
282+
*/
283+
public function testRequestToShipmentLocalizedExceptionDataProvider()
284+
{
285+
return [
286+
[
287+
true
288+
],
289+
[
290+
false
291+
]
292+
];
293+
}
249294
}

0 commit comments

Comments
 (0)