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\TrackingWrapper; |
15
|
|
|
|
16
|
|
|
class TrackingTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var |
20
|
|
|
*/ |
21
|
|
|
private $trackingMock; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->trackingMock = $this->getMock('Ups\Tracking'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* when: trackIsCalled |
30
|
|
|
* should: callUpsTrackingTrackMethod. |
31
|
|
|
*/ |
32
|
|
View Code Duplication |
public function testTrackingGetTrackMethodIsCalled() |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$trackingNumber = 'tracking Number'; |
35
|
|
|
$requestOption = 'request Option'; |
36
|
|
|
$this->trackingMock |
37
|
|
|
->expects($this->once()) |
38
|
|
|
->method('track') |
39
|
|
|
->with( |
40
|
|
|
$trackingNumber, |
41
|
|
|
$requestOption |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$sut = new TrackingWrapper($this->trackingMock); |
45
|
|
|
|
46
|
|
|
$sut->track( |
47
|
|
|
$trackingNumber, |
48
|
|
|
$requestOption |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* when: trackByReferenceIsCalled |
54
|
|
|
* should: callUpsTrackingTrackByReferenceMethod. |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function testTrackingGetTrackByReferenceMethodIsCalled() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$referenceNumber = 'reference Number'; |
59
|
|
|
$requestOption = 'request Option'; |
60
|
|
|
$this->trackingMock |
61
|
|
|
->expects($this->once()) |
62
|
|
|
->method('track') |
63
|
|
|
->with( |
64
|
|
|
$referenceNumber, |
65
|
|
|
$requestOption |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$sut = new TrackingWrapper($this->trackingMock); |
69
|
|
|
|
70
|
|
|
$sut->track( |
71
|
|
|
$referenceNumber, |
72
|
|
|
$requestOption |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* when: getRequestIsCalled |
78
|
|
|
* should: callUpsTrackingGetRequestMethod. |
79
|
|
|
*/ |
80
|
|
|
public function testTrackingGetGetRequestMethodIsCalled() |
81
|
|
|
{ |
82
|
|
|
$requestMock = $this->getMock('Ups\Request'); |
83
|
|
|
$this |
84
|
|
|
->trackingMock |
85
|
|
|
->method('getRequest') |
86
|
|
|
->willReturn($requestMock); |
87
|
|
|
|
88
|
|
|
$sut = new TrackingWrapper($this->trackingMock); |
89
|
|
|
$sut->setRequest($requestMock); |
90
|
|
|
$request = $sut->getRequest(); |
91
|
|
|
$this->assertInstanceOf('Ups\Request', $request); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* when: getResponseIsCalled |
96
|
|
|
* should: callUpsTrackingGetResponseMethod. |
97
|
|
|
*/ |
98
|
|
View Code Duplication |
public function testTrackingGetResponseMethodIsCalled() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$responseMock = $this->getMock('Ups\Response'); |
101
|
|
|
$this |
102
|
|
|
->trackingMock |
103
|
|
|
->method('getResponse') |
104
|
|
|
->willReturn($responseMock); |
105
|
|
|
|
106
|
|
|
$sut = new TrackingWrapper($this->trackingMock); |
107
|
|
|
$sut->setResponse($responseMock); |
108
|
|
|
$response = $sut->getResponse(); |
109
|
|
|
$this->assertInstanceOf('Ups\Response', $response); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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.