1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Manavo\DoneDone\Test; |
4
|
|
|
|
5
|
|
|
use Manavo\DoneDone\Client; |
6
|
|
|
use Manavo\DoneDone\Comment; |
7
|
|
|
use Manavo\DoneDone\Issue; |
8
|
|
|
use PHPUnit_Framework_TestCase; |
9
|
|
|
|
10
|
|
|
class IssueTest extends PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
public function setUp() |
14
|
|
|
{ |
15
|
|
|
date_default_timezone_set('UTC'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testRequiredParametersIncludedWhenConvertingToArray() |
19
|
|
|
{ |
20
|
|
|
$issueArray = (new Issue())->toArray(); |
21
|
|
|
|
22
|
|
|
$this->assertArrayHasKey('title', $issueArray); |
23
|
|
|
$this->assertArrayHasKey('priority_level_id', $issueArray); |
24
|
|
|
$this->assertArrayHasKey('fixer_id', $issueArray); |
25
|
|
|
$this->assertArrayHasKey('tester_id', $issueArray); |
26
|
|
|
|
27
|
|
|
$this->assertEquals(4, count($issueArray)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testDescriptionIsAddedIfNotEmpty() |
31
|
|
|
{ |
32
|
|
|
$issue = new Issue(); |
33
|
|
|
$issue->setDescription('desc'); |
34
|
|
|
|
35
|
|
|
$this->assertArrayHasKey('description', $issue->toArray()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testUserIdsToCcIsAddedIfNotEmpty() |
39
|
|
|
{ |
40
|
|
|
$issue = new Issue(); |
41
|
|
|
$issue->setUserIdsToCc('1,2,3'); |
42
|
|
|
|
43
|
|
|
$this->assertArrayHasKey('user_ids_to_cc', $issue->toArray()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testDueDateIsAddedIfNotEmpty() |
47
|
|
|
{ |
48
|
|
|
$issue = new Issue(); |
49
|
|
|
$issue->setDueDate('2014-01-12 12:01:00'); |
50
|
|
|
|
51
|
|
|
$this->assertArrayHasKey('due_date', $issue->toArray()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testTagsIsAddedIfNotEmpty() |
55
|
|
|
{ |
56
|
|
|
$issue = new Issue(); |
57
|
|
|
$issue->setTags('tag1,tag2'); |
58
|
|
|
|
59
|
|
|
$this->assertArrayHasKey('tags', $issue->toArray()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testUserIdsToCcIsACommaSeparatedString() |
63
|
|
|
{ |
64
|
|
|
$issue = new Issue(); |
65
|
|
|
$issue->setUserIdsToCc([1, 2, 3]); |
66
|
|
|
|
67
|
|
|
$this->assertEquals('1,2,3', $issue->toArray()['user_ids_to_cc']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testTagsIsACommaSeparatedString() |
71
|
|
|
{ |
72
|
|
|
$issue = new Issue(); |
73
|
|
|
$issue->setTags(['tag1', 'tag2', 'tag3']); |
74
|
|
|
|
75
|
|
|
$this->assertEquals('tag1,tag2,tag3', $issue->toArray()['tags']); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testAttachmentsGetAddedWhenConvertingToArray() |
79
|
|
|
{ |
80
|
|
|
$issue = new Issue(); |
81
|
|
|
$issue->addAttachment(__FILE__); |
82
|
|
|
$issue->addAttachment(__FILE__); |
83
|
|
|
$issue->addAttachment(__FILE__); |
84
|
|
|
$issue->addAttachment(__FILE__); |
85
|
|
|
|
86
|
|
|
$this->assertEquals(8, count($issue->toArray())); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testUnixTimestampGetsConvertedForDueDate() |
90
|
|
|
{ |
91
|
|
|
$time = time(); |
92
|
|
|
|
93
|
|
|
$issue = new Issue(); |
94
|
|
|
$issue->setDueDate($time); |
95
|
|
|
|
96
|
|
|
$this->assertEquals(date('Y-m-d H:i:s', $time), $issue->toArray()['due_date']); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testFixerIsSetCorrectly() |
100
|
|
|
{ |
101
|
|
|
$issue = new Issue(); |
102
|
|
|
$issue->setFixer(123); |
103
|
|
|
|
104
|
|
|
$this->assertEquals(123, $issue->toArray()['fixer_id']); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testPriorityLevelIsSetCorrectly() |
108
|
|
|
{ |
109
|
|
|
$issue = new Issue(); |
110
|
|
|
$issue->setPriorityLevel(1123); |
111
|
|
|
|
112
|
|
|
$this->assertEquals(1123, $issue->toArray()['priority_level_id']); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testTesterIsSetCorrectly() |
116
|
|
|
{ |
117
|
|
|
$issue = new Issue(); |
118
|
|
|
$issue->setTester(31); |
119
|
|
|
|
120
|
|
|
$this->assertEquals(31, $issue->toArray()['tester_id']); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testTitleIsSetCorrectly() |
124
|
|
|
{ |
125
|
|
|
$issue = new Issue(); |
126
|
|
|
$issue->setTitle('setting title!'); |
127
|
|
|
|
128
|
|
|
$this->assertEquals('setting title!', $issue->toArray()['title']); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function typeOfRequestProvider() |
132
|
|
|
{ |
133
|
|
|
return [ |
134
|
|
|
['availableReassignees', 'get'], |
135
|
|
|
['availableStatuses', 'get'], |
136
|
|
|
]; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @dataProvider typeOfRequestProvider |
141
|
|
|
*/ |
142
|
|
|
public function testMethodsMakeCorrectTypeOfRequest($function, $requestType) |
143
|
|
|
{ |
144
|
|
|
$responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response') |
145
|
|
|
->disableOriginalConstructor()->getMock(); |
146
|
|
|
$responseMock->expects($this->once())->method('json') |
147
|
|
|
->willReturn($this->returnValue(true)); |
148
|
|
|
|
149
|
|
|
$guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client') |
150
|
|
|
->disableOriginalConstructor()->getMock(); |
151
|
|
|
$guzzleClientMock->expects($this->once())->method($requestType) |
152
|
|
|
->willReturn($responseMock); |
153
|
|
|
|
154
|
|
|
$client = new Client('team', 'username', 'password'); |
155
|
|
|
$client->setClient($guzzleClientMock); |
156
|
|
|
|
157
|
|
|
$client->project(123)->issue(111)->$function(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function typeOfRequestWithArgumentProvider() |
161
|
|
|
{ |
162
|
|
|
return [ |
163
|
|
|
['addComment', 'post', new Comment()], |
164
|
|
|
['updateStatus', 'put', 1], |
165
|
|
|
['updatePriorityLevel', 'put', 1], |
166
|
|
|
['updateTester', 'put', 1], |
167
|
|
|
['updateFixer', 'put', 1], |
168
|
|
|
]; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @dataProvider typeOfRequestWithArgumentProvider |
173
|
|
|
*/ |
174
|
|
|
public function testMethodsWithArgumentMakeCorrectTypeOfRequest( |
175
|
|
|
$function, |
176
|
|
|
$requestType, |
177
|
|
|
$argument |
178
|
|
|
) { |
179
|
|
|
$responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response') |
180
|
|
|
->disableOriginalConstructor()->getMock(); |
181
|
|
|
$responseMock->expects($this->once())->method('json') |
182
|
|
|
->willReturn($this->returnValue(true)); |
183
|
|
|
|
184
|
|
|
$guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client') |
185
|
|
|
->disableOriginalConstructor()->getMock(); |
186
|
|
|
$guzzleClientMock->expects($this->once())->method($requestType) |
187
|
|
|
->willReturn($responseMock); |
188
|
|
|
|
189
|
|
|
$client = new Client('team', 'username', 'password'); |
190
|
|
|
$client->setClient($guzzleClientMock); |
191
|
|
|
|
192
|
|
|
$client->project(123)->issue(182)->$function($argument); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function testUpdateMethodSendsCommentIfSet() |
196
|
|
|
{ |
197
|
|
|
$responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response') |
198
|
|
|
->disableOriginalConstructor()->getMock(); |
199
|
|
|
$responseMock->expects($this->once())->method('json') |
200
|
|
|
->willReturn($this->returnValue(true)); |
201
|
|
|
|
202
|
|
|
$guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client') |
203
|
|
|
->disableOriginalConstructor()->getMock(); |
204
|
|
|
$guzzleClientMock->expects($this->once())->method('put') |
205
|
|
|
->with($this->equalTo('https://team.mydonedone.com/issuetracker/api/v2/projects/111/issues/321/fixer.json'), $this->equalTo(['body' => ['new_fixer_id' => 1, 'comment' => 'Comment!']]))->willReturn($responseMock); |
206
|
|
|
|
207
|
|
|
$client = new Client('team', 'username', 'password'); |
208
|
|
|
$client->setClient($guzzleClientMock); |
209
|
|
|
|
210
|
|
|
$client->project(111)->issue(321)->updateFixer( |
211
|
|
|
1, 'Comment!' |
212
|
|
|
); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
} |
216
|
|
|
|