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\AddressValidationWrapper; |
15
|
|
|
|
16
|
|
|
class AddressValidationTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
private $addressValidationMock; |
19
|
|
|
|
20
|
|
|
public function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->addressValidationMock = $this->getMock('Ups\AddressValidation'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* when: validateIsCalled |
27
|
|
|
* should: callUpsAddressValidationValidateMethod. |
28
|
|
|
*/ |
29
|
|
|
public function testAddressValidationValidateMethodIsCalled() |
30
|
|
|
{ |
31
|
|
|
$addressMock = $this->getMock('Ups\Entity\Address'); |
32
|
|
|
|
33
|
|
|
$this->addressValidationMock |
34
|
|
|
->expects($this->once()) |
35
|
|
|
->method('validate') |
36
|
|
|
->with( |
37
|
|
|
$addressMock, |
38
|
|
|
\Ups\AddressValidation::REQUEST_OPTION_ADDRESS_VALIDATION, |
39
|
|
|
15 |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
$sut = new AddressValidationWrapper($this->addressValidationMock); |
43
|
|
|
|
44
|
|
|
$sut->validate( |
45
|
|
|
$addressMock, |
46
|
|
|
\Ups\AddressValidation::REQUEST_OPTION_ADDRESS_VALIDATION, |
47
|
|
|
15 |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* when: getRequestIsCalled |
53
|
|
|
* should: callUpsAddressValidationGetRequestMethod. |
54
|
|
|
*/ |
55
|
|
|
public function testAddressValidationGetRequestMethodIsCalled() |
56
|
|
|
{ |
57
|
|
|
$requestMock = $this->getMock('Ups\Request'); |
58
|
|
|
$this |
59
|
|
|
->addressValidationMock |
60
|
|
|
->method('getRequest') |
61
|
|
|
->willReturn($requestMock); |
62
|
|
|
|
63
|
|
|
$sut = new AddressValidationWrapper($this->addressValidationMock); |
64
|
|
|
$sut->setRequest($requestMock); |
65
|
|
|
$request = $sut->getRequest(); |
66
|
|
|
$this->assertInstanceOf('Ups\Request', $request); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* when: getResponseIsCalled |
71
|
|
|
* should: callUpsAddressValidationGetResponseMethod. |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public function testAddressValidationGetResponseMethodIsCalled() |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$responseMock = $this->getMock('Ups\Response'); |
76
|
|
|
$this |
77
|
|
|
->addressValidationMock |
78
|
|
|
->method('getResponse') |
79
|
|
|
->willReturn($responseMock); |
80
|
|
|
|
81
|
|
|
$sut = new AddressValidationWrapper($this->addressValidationMock); |
82
|
|
|
$sut->setResponse($responseMock); |
83
|
|
|
$response = $sut->getResponse(); |
84
|
|
|
$this->assertInstanceOf('Ups\Response', $response); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.