|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Copyright © Magento, Inc. All rights reserved. |
4 | | - * See COPYING.txt for license details. |
| 3 | + * Copyright 2015 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */ |
6 | 6 | declare(strict_types=1); |
7 | 7 |
|
@@ -123,29 +123,19 @@ public function testAddTrackingNumbersToShipment(array $info): void |
123 | 123 | ->getMock(); |
124 | 124 | $shipmentMock->expects(static::once())->method('getOrder')->willReturn($order); |
125 | 125 |
|
126 | | - $this->carrierFactory->expects(static::once()) |
127 | | - ->method('create') |
128 | | - ->with(self::CARRIER_CODE) |
| 126 | + $this->carrierFactory->expects(static::once())->method('create')->with(self::CARRIER_CODE) |
129 | 127 | ->willReturn($this->getCarrierMock()); |
130 | 128 |
|
131 | | - $labelsMock = $this->getMockBuilder(Labels::class) |
132 | | - ->disableOriginalConstructor() |
133 | | - ->getMock(); |
134 | | - $labelsMock->expects(static::once()) |
135 | | - ->method('requestToShipment') |
136 | | - ->with($shipmentMock) |
| 129 | + $labelsMock = $this->getMockBuilder(Labels::class)->disableOriginalConstructor()->getMock(); |
| 130 | + $labelsMock->expects(static::once())->method('requestToShipment')->with($shipmentMock) |
137 | 131 | ->willReturn($this->getResponseMock($info)); |
138 | 132 |
|
139 | | - $this->labelsFactory->expects(static::once()) |
140 | | - ->method('create') |
141 | | - ->willReturn($labelsMock); |
| 133 | + $this->labelsFactory->expects(static::once())->method('create')->willReturn($labelsMock); |
142 | 134 |
|
143 | | - $this->filesystem->expects(static::once()) |
144 | | - ->method('getDirectoryWrite') |
| 135 | + $this->filesystem->expects(static::once())->method('getDirectoryWrite') |
145 | 136 | ->willReturn($this->getMockForAbstractClass(WriteInterface::class)); |
146 | 137 |
|
147 | | - $this->scopeConfig->expects(static::once()) |
148 | | - ->method('getValue') |
| 138 | + $this->scopeConfig->expects(static::once())->method('getValue') |
149 | 139 | ->with( |
150 | 140 | 'carriers/' . self::CARRIER_CODE . '/title', |
151 | 141 | ScopeInterface::SCOPE_STORE, |
@@ -204,9 +194,7 @@ public function testAddTrackingNumbersToShipment(array $info): void |
204 | 194 | } |
205 | 195 | }); |
206 | 196 |
|
207 | | - $this->trackFactory->expects(static::any()) |
208 | | - ->method('create') |
209 | | - ->willReturn($trackMock); |
| 197 | + $this->trackFactory->expects(static::any())->method('create')->willReturn($trackMock); |
210 | 198 |
|
211 | 199 | /** |
212 | 200 | * @var $requestMock \Magento\Framework\App\RequestInterface|MockObject |
@@ -284,4 +272,61 @@ public static function labelInfoDataProvider(): array |
284 | 272 | [['tracking_number' => '111111', 'label_content' => 'some']] |
285 | 273 | ]; |
286 | 274 | } |
| 275 | + |
| 276 | + public function testCreateResponseHasErrors() |
| 277 | + { |
| 278 | + $order = $this->getMockBuilder(Order::class) |
| 279 | + ->disableOriginalConstructor() |
| 280 | + ->getMock(); |
| 281 | + $order->expects(static::once()) |
| 282 | + ->method('getShippingMethod') |
| 283 | + ->with(true) |
| 284 | + ->willReturn($this->getShippingMethodMock()); |
| 285 | + |
| 286 | + /** |
| 287 | + * @var $shipmentMock \Magento\Sales\Model\Order\Shipment|MockObject |
| 288 | + */ |
| 289 | + $shipmentMock = $this->getMockBuilder(Shipment::class) |
| 290 | + ->disableOriginalConstructor() |
| 291 | + ->getMock(); |
| 292 | + $shipmentMock->expects(static::once())->method('getOrder')->willReturn($order); |
| 293 | + |
| 294 | + $carrierMock = $this->getMockBuilder(AbstractCarrier::class) |
| 295 | + ->disableOriginalConstructor() |
| 296 | + ->onlyMethods(['isShippingLabelsAvailable', 'getCarrierCode']) |
| 297 | + ->getMockForAbstractClass(); |
| 298 | + $carrierMock->expects(static::once()) |
| 299 | + ->method('isShippingLabelsAvailable') |
| 300 | + ->willReturn(true); |
| 301 | + $this->carrierFactory->expects(static::once()) |
| 302 | + ->method('create') |
| 303 | + ->with(self::CARRIER_CODE) |
| 304 | + ->willReturn($carrierMock); |
| 305 | + |
| 306 | + $responseMock = $this->getMockBuilder(DataObject::class) |
| 307 | + ->addMethods(['hasErrors', 'getErrors'])->disableOriginalConstructor()->getMock(); |
| 308 | + $responseMock->expects(static::once()) |
| 309 | + ->method('hasErrors') |
| 310 | + ->willReturn(true); |
| 311 | + $responseMock->expects(static::once())->method('getErrors')->willReturn(['Error message']); |
| 312 | + |
| 313 | + $labelsMock = $this->getMockBuilder(Labels::class) |
| 314 | + ->disableOriginalConstructor() |
| 315 | + ->getMock(); |
| 316 | + $labelsMock->expects(static::once()) |
| 317 | + ->method('requestToShipment') |
| 318 | + ->with($shipmentMock) |
| 319 | + ->willReturn($responseMock); |
| 320 | + |
| 321 | + $this->labelsFactory->expects(static::once()) |
| 322 | + ->method('create') |
| 323 | + ->willReturn($labelsMock); |
| 324 | + |
| 325 | + $this->expectException(\Magento\Framework\Exception\LocalizedException::class); |
| 326 | + /** |
| 327 | + * @var $requestMock \Magento\Framework\App\RequestInterface|MockObject |
| 328 | + */ |
| 329 | + $requestMock = $this->getMockForAbstractClass(RequestInterface::class); |
| 330 | + $this->labelGenerator->create($shipmentMock, $requestMock); |
| 331 | + } |
287 | 332 | } |
0 commit comments