1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Octante\UpsAPIBundle\Tests\Unit\Library; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the UpsAPIBundle package. |
7
|
|
|
* |
8
|
|
|
* (c) Issel Guberna <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
use Octante\UpsAPIBundle\Library\ShippingWrapper; |
15
|
|
|
|
16
|
|
|
class ShippingTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
private $shippingMock; |
19
|
|
|
|
20
|
|
|
public function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->shippingMock = $this->getMock('Ups\Shipping'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* when: confirmIsCalled |
27
|
|
|
* should: callUpsShippingConfirmMethod. |
28
|
|
|
*/ |
29
|
|
|
public function testShippingConfirmMethodIsCalled() |
30
|
|
|
{ |
31
|
|
|
$validationString = 'validationString'; |
32
|
|
|
$shipmentMock = $this->getMockBuilder('Ups\Entity\Shipment') |
33
|
|
|
->disableOriginalConstructor() |
34
|
|
|
->getMock(); |
35
|
|
|
$labelSpecMock = $this->getMockBuilder('Ups\Entity\ShipmentRequestLabelSpecification') |
36
|
|
|
->disableOriginalConstructor() |
37
|
|
|
->getMock(); |
38
|
|
|
$receiptSpecMock = $this->getMockBuilder('Ups\Entity\ShipmentRequestReceiptSpecification') |
39
|
|
|
->disableOriginalConstructor() |
40
|
|
|
->getMock(); |
41
|
|
|
|
42
|
|
|
$this->shippingMock |
43
|
|
|
->expects($this->once()) |
44
|
|
|
->method('confirm') |
45
|
|
|
->with( |
46
|
|
|
$validationString, |
47
|
|
|
$shipmentMock, |
48
|
|
|
$labelSpecMock, |
49
|
|
|
$receiptSpecMock |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$sut = new ShippingWrapper($this->shippingMock); |
53
|
|
|
|
54
|
|
|
$sut->confirm( |
55
|
|
|
'validationString', |
56
|
|
|
$shipmentMock, |
57
|
|
|
$labelSpecMock, |
58
|
|
|
$receiptSpecMock |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* when: acceptIsCalled |
64
|
|
|
* should: callUpsShippingAcceptMethod. |
65
|
|
|
*/ |
66
|
|
|
public function testShippingAcceptMethodIsCalled() |
67
|
|
|
{ |
68
|
|
|
$shipmentDigestString = 'shippmentDigestString'; |
69
|
|
|
$this->shippingMock |
70
|
|
|
->expects($this->once()) |
71
|
|
|
->method('accept') |
72
|
|
|
->with($shipmentDigestString); |
73
|
|
|
|
74
|
|
|
$sut = new ShippingWrapper($this->shippingMock); |
75
|
|
|
|
76
|
|
|
$sut->accept($shipmentDigestString); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* when: voidIsCalled |
81
|
|
|
* should: callUpsShippingVoidRequestMethod. |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function testShippingVoidMethodIsCalled() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$shipmentDataString = 'shippmentDataString'; |
86
|
|
|
$this->shippingMock |
87
|
|
|
->expects($this->once()) |
88
|
|
|
->method('void') |
89
|
|
|
->with($shipmentDataString); |
90
|
|
|
|
91
|
|
|
$sut = new ShippingWrapper($this->shippingMock); |
92
|
|
|
|
93
|
|
|
$sut->void($shipmentDataString); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* when: recoverLabelIsCalled |
98
|
|
|
* should: callUpsShippingRecoverLabelRequestMethod. |
99
|
|
|
*/ |
100
|
|
View Code Duplication |
public function testShippingRecoverLabelMethodIsCalled() |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
$shipmentDataString = 'shipmentDataString'; |
103
|
|
|
$this->shippingMock |
104
|
|
|
->expects($this->once()) |
105
|
|
|
->method('recoverLabel') |
106
|
|
|
->with($shipmentDataString); |
107
|
|
|
|
108
|
|
|
$sut = new ShippingWrapper($this->shippingMock); |
109
|
|
|
|
110
|
|
|
$sut->recoverLabel($shipmentDataString); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.