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\RateWrapper; |
15
|
|
|
|
16
|
|
|
class RateTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
private $rateMock; |
19
|
|
|
|
20
|
|
|
public function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->rateMock = $this->getMock('Ups\Rate'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* when: shopRatesIsCalled |
27
|
|
|
* should: callUpsRateShopRatesMethod. |
28
|
|
|
*/ |
29
|
|
|
public function testRateShopRatesMethodIsCalled() |
30
|
|
|
{ |
31
|
|
|
$rateRequest = $this->getMock('Ups\Entity\RateRequest'); |
32
|
|
|
$this->rateMock |
33
|
|
|
->expects($this->once()) |
34
|
|
|
->method('shopRates') |
35
|
|
|
->with($rateRequest); |
36
|
|
|
|
37
|
|
|
$sut = new RateWrapper($this->rateMock); |
38
|
|
|
|
39
|
|
|
$sut->shopRates($rateRequest); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* when: getRateIsCalled |
44
|
|
|
* should: callUpsRateGetRateMethod. |
45
|
|
|
*/ |
46
|
|
|
public function testRateGetRateMethodIsCalled() |
47
|
|
|
{ |
48
|
|
|
$shipmentMock = $this->getMock('Ups\Entity\Shipment'); |
49
|
|
|
$rateRequestMock = $this->getMock('Ups\Entity\RateRequest'); |
50
|
|
|
$this->rateMock |
51
|
|
|
->expects($this->once()) |
52
|
|
|
->method('getRate') |
53
|
|
|
->willReturn($rateRequestMock); |
54
|
|
|
|
55
|
|
|
$sut = new RateWrapper($this->rateMock); |
56
|
|
|
|
57
|
|
|
$rateRequest = $sut->getRate($shipmentMock); |
58
|
|
|
$this->assertEquals($rateRequestMock, $rateRequest); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* when: getRequestIsCalled |
63
|
|
|
* should: callUpsRateGetRequestMethod. |
64
|
|
|
*/ |
65
|
|
|
public function testRateGetRequestMethodIsCalled() |
66
|
|
|
{ |
67
|
|
|
$requestMock = $this->getMock('Ups\Request'); |
68
|
|
|
$this |
69
|
|
|
->rateMock |
70
|
|
|
->method('getRequest') |
71
|
|
|
->willReturn($requestMock); |
72
|
|
|
|
73
|
|
|
$sut = new RateWrapper($this->rateMock); |
74
|
|
|
$sut->setRequest($requestMock); |
75
|
|
|
$request = $sut->getRequest(); |
76
|
|
|
$this->assertInstanceOf('Ups\Request', $request); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* when: getResponseIsCalled |
81
|
|
|
* should: callUpsRateGetResponseMethod. |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function testRateGetResponseMethodIsCalled() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$responseMock = $this->getMock('Ups\Response'); |
86
|
|
|
$this |
87
|
|
|
->rateMock |
88
|
|
|
->method('getResponse') |
89
|
|
|
->willReturn($responseMock); |
90
|
|
|
|
91
|
|
|
$sut = new RateWrapper($this->rateMock); |
92
|
|
|
$sut->setResponse($responseMock); |
93
|
|
|
$response = $sut->getResponse(); |
94
|
|
|
$this->assertInstanceOf('Ups\Response', $response); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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.