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\QuantumViewWrapper; |
15
|
|
|
|
16
|
|
|
class QuantumViewTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var |
20
|
|
|
*/ |
21
|
|
|
private $quantumViewMock; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->quantumViewMock = $this->getMock('Ups\QuantumView'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* when: getSubscriptionIsCalled |
30
|
|
|
* should: callUpsQuantumViewGetSubscriptionMethod. |
31
|
|
|
*/ |
32
|
|
|
public function testQuantumViewGetSubscriptionMethodIsCalled() |
33
|
|
|
{ |
34
|
|
|
$name = 'name'; |
35
|
|
|
$beginDateTime = 'begin date time'; |
36
|
|
|
$endDateTime = 'end date time'; |
37
|
|
|
$fileName = 'filename'; |
38
|
|
|
$bookmark = 'bookmark'; |
39
|
|
|
|
40
|
|
|
$this |
41
|
|
|
->quantumViewMock |
42
|
|
|
->expects($this->once()) |
43
|
|
|
->method('getSubscription') |
44
|
|
|
->with( |
45
|
|
|
$name, |
46
|
|
|
$beginDateTime, |
47
|
|
|
$endDateTime, |
48
|
|
|
$fileName, |
49
|
|
|
$bookmark |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$sut = new QuantumViewWrapper($this->quantumViewMock); |
53
|
|
|
|
54
|
|
|
$sut->getSubscription( |
55
|
|
|
$name, |
56
|
|
|
$beginDateTime, |
57
|
|
|
$endDateTime, |
58
|
|
|
$fileName, |
59
|
|
|
$bookmark |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* when: getBookmarkIsCalled |
65
|
|
|
* should: callUpsQuantumViewGetBookmarkMethod. |
66
|
|
|
*/ |
67
|
|
|
public function testQuantumViewGetBookmarkMethodIsCalled() |
68
|
|
|
{ |
69
|
|
|
$sut = new QuantumViewWrapper($this->quantumViewMock); |
70
|
|
|
|
71
|
|
|
$this |
72
|
|
|
->quantumViewMock |
73
|
|
|
->expects($this->once()) |
74
|
|
|
->method('getBookmark'); |
75
|
|
|
|
76
|
|
|
$sut->getBookmark(); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* when: hasBookmarkIsCalled |
81
|
|
|
* should: callUpsQuantumViewHasBookmarkMethod. |
82
|
|
|
*/ |
83
|
|
|
public function testQuantumViewHasBookmarkMethodIsCalled() |
84
|
|
|
{ |
85
|
|
|
$sut = new QuantumViewWrapper($this->quantumViewMock); |
86
|
|
|
|
87
|
|
|
$this |
88
|
|
|
->quantumViewMock |
89
|
|
|
->expects($this->once()) |
90
|
|
|
->method('hasBookmark'); |
91
|
|
|
|
92
|
|
|
$sut->hasBookmark(); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* when: setBookmarkIsCalled |
97
|
|
|
* should: callUpsQuantumViewSetBookmarkMethod. |
98
|
|
|
*/ |
99
|
|
|
public function testQuantumViewSetBookmarkMethodIsCalled() |
100
|
|
|
{ |
101
|
|
|
$sut = new QuantumViewWrapper($this->quantumViewMock); |
102
|
|
|
$bookmarkMock = 'bookmark name'; |
103
|
|
|
|
104
|
|
|
$this |
105
|
|
|
->quantumViewMock |
106
|
|
|
->expects($this->once()) |
107
|
|
|
->method('setBookmark') |
108
|
|
|
->with($bookmarkMock); |
109
|
|
|
|
110
|
|
|
$sut->setBookmark($bookmarkMock); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* when: getRequestIsCalled |
115
|
|
|
* should: callUpsQuantumViewGetRequestMethod. |
116
|
|
|
*/ |
117
|
|
|
public function testQuantumViewGetRequestMethodIsCalled() |
118
|
|
|
{ |
119
|
|
|
$requestMock = $this->getMock('Ups\Request'); |
120
|
|
|
$this |
121
|
|
|
->quantumViewMock |
122
|
|
|
->method('getRequest') |
123
|
|
|
->willReturn($requestMock); |
124
|
|
|
|
125
|
|
|
$sut = new QuantumViewWrapper($this->quantumViewMock); |
126
|
|
|
$sut->setRequest($requestMock); |
127
|
|
|
$request = $sut->getRequest(); |
128
|
|
|
$this->assertInstanceOf('Ups\Request', $request); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* when: getResponseIsCalled |
133
|
|
|
* should: callUpsGetResponseMethod. |
134
|
|
|
*/ |
135
|
|
View Code Duplication |
public function testQuantumViewGetResponseMethodIsCalled() |
|
|
|
|
136
|
|
|
{ |
137
|
|
|
$responseMock = $this->getMock('Ups\Response'); |
138
|
|
|
$this |
139
|
|
|
->quantumViewMock |
140
|
|
|
->method('getResponse') |
141
|
|
|
->willReturn($responseMock); |
142
|
|
|
|
143
|
|
|
$sut = new QuantumViewWrapper($this->quantumViewMock); |
144
|
|
|
$sut->setResponse($responseMock); |
145
|
|
|
$response = $sut->getResponse(); |
146
|
|
|
$this->assertInstanceOf('Ups\Response', $response); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: