Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 5699338

Browse files
committed
Revert all the commits from the last couple of days
1 parent 861a0b9 commit 5699338

6 files changed

Lines changed: 245 additions & 16 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
],
1313
"require": {
14-
"guzzlehttp/guzzle": "~4.0|~5.0|~6.0"
14+
"guzzlehttp/guzzle": "~4.0|~5.0"
1515
},
1616
"require-dev": {
1717
"phpunit/phpunit" : "~4.0",

src/Client.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,7 @@ public function get($endpoint, $data = [])
237237
'query' => $data
238238
]);
239239

240-
if ($response) {
241-
return json_decode($response->getBody(), true);
242-
} else {
243-
return null;
244-
}
240+
return $response->json();
245241
}
246242

247243
/**
@@ -258,11 +254,7 @@ public function post($endpoint, $data = [])
258254
'body' => $data
259255
]);
260256

261-
if ($response) {
262-
return json_decode($response->getBody(), true);
263-
} else {
264-
return null;
265-
}
257+
return $response->json();
266258
}
267259

268260
/**
@@ -279,11 +271,7 @@ public function put($endpoint, $data = [])
279271
'body' => $data
280272
]);
281273

282-
if ($response) {
283-
return json_decode($response->getBody(), true);
284-
} else {
285-
return null;
286-
}
274+
return $response->json();
287275
}
288276

289277
}

tests/ClientTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,72 @@ public function testCompanyMethodReturnsIssueObject()
3838
);
3939
}
4040

41+
public function typeOfRequestProvider()
42+
{
43+
return [
44+
['priorityLevels', 'get'],
45+
['projects', 'get'],
46+
['companies', 'get'],
47+
['issues', 'get'],
48+
['activeIssues', 'get'],
49+
['closedAndFixedIssues', 'get'],
50+
['issuesWaitingOnYou', 'get'],
51+
['issuesWaitingOnThem', 'get'],
52+
['globalFilters', 'get'],
53+
['issueCreationTypes', 'get'],
54+
['issueSortTypes', 'get'],
55+
];
56+
}
57+
58+
/**
59+
* @dataProvider typeOfRequestProvider
60+
*/
61+
public function testMethodsMakeCorrectTypeOfRequest($function, $requestType)
62+
{
63+
$responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response')
64+
->disableOriginalConstructor()->getMock();
65+
$responseMock->expects($this->once())->method('json')
66+
->willReturn($this->returnValue(true));
67+
68+
$guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client')
69+
->disableOriginalConstructor()->getMock();
70+
$guzzleClientMock->expects($this->once())->method($requestType)
71+
->willReturn($responseMock);
72+
73+
$this->client->setClient($guzzleClientMock);
74+
75+
$this->client->$function();
76+
}
77+
78+
public function typeOfRequestWithArgumentProvider()
79+
{
80+
return [
81+
['issuesByFilter', 'get', 'argument'],
82+
['createCompany', 'post', new Company()],
83+
];
84+
}
85+
86+
/**
87+
* @dataProvider typeOfRequestWithArgumentProvider
88+
*/
89+
public function testMethodsWithArgumentMakeCorrectTypeOfRequest(
90+
$function,
91+
$requestType,
92+
$argument
93+
) {
94+
$responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response')
95+
->disableOriginalConstructor()->getMock();
96+
$responseMock->expects($this->once())->method('json')
97+
->willReturn($this->returnValue(true));
98+
99+
$guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client')
100+
->disableOriginalConstructor()->getMock();
101+
$guzzleClientMock->expects($this->once())->method($requestType)
102+
->willReturn($responseMock);
103+
104+
$this->client->setClient($guzzleClientMock);
105+
106+
$this->client->$function($argument);
107+
}
108+
41109
}

tests/CompanyTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,24 @@ public function testTitleGetsSet()
2222
$this->assertEquals('my name', $company->toArray()['company_name']);
2323
}
2424

25+
public function testUpdateNameMakesPutRequest()
26+
{
27+
$responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response')
28+
->disableOriginalConstructor()->getMock();
29+
$responseMock->expects($this->once())->method('json')
30+
->willReturn($this->returnValue(true));
31+
32+
$guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client')
33+
->disableOriginalConstructor()->getMock();
34+
$guzzleClientMock->expects($this->once())->method('put')
35+
->willReturn($responseMock);
36+
37+
$client = new Client('team', 'username', 'password');
38+
$client->setClient($guzzleClientMock);
39+
40+
$company = $client->company(3);
41+
42+
$company->updateName('name');
43+
}
44+
2545
}

tests/IssueTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,88 @@ public function testTitleIsSetCorrectly()
128128
$this->assertEquals('setting title!', $issue->toArray()['title']);
129129
}
130130

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+
131215
}

tests/ProjectTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,73 @@ public function testIssueMethodReturnsIssueObject()
1717
$this->assertInstanceOf('Manavo\\DoneDone\\Issue', $project->issue(1));
1818
}
1919

20+
public function typeOfRequestProvider()
21+
{
22+
return [
23+
['people', 'get'],
24+
['issues', 'get'],
25+
['activeIssues', 'get'],
26+
['closedAndFixedIssues', 'get'],
27+
['issuesWaitingOnYou', 'get'],
28+
['issuesWaitingOnThem', 'get'],
29+
['releaseBuilds', 'get'],
30+
//['releaseBuildInfo', 'get'], // TODO response is object of class ReleaseBuildInfo
31+
['filters', 'get'],
32+
];
33+
}
34+
35+
/**
36+
* @dataProvider typeOfRequestProvider
37+
*/
38+
public function testMethodsMakeCorrectTypeOfRequest($function, $requestType)
39+
{
40+
$responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response')
41+
->disableOriginalConstructor()->getMock();
42+
$responseMock->expects($this->once())->method('json')
43+
->willReturn($this->returnValue(true));
44+
45+
$guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client')
46+
->disableOriginalConstructor()->getMock();
47+
$guzzleClientMock->expects($this->once())->method($requestType)
48+
->willReturn($responseMock);
49+
50+
$client = new Client('team', 'username', 'password');
51+
$client->setClient($guzzleClientMock);
52+
53+
$client->project(123)->$function();
54+
}
55+
56+
public function typeOfRequestWithArgumentProvider()
57+
{
58+
return [
59+
['issuesByFilter', 'get', 'argument'],
60+
['addIssue', 'post', new Issue()],
61+
['createReleaseBuild', 'post', new ReleaseBuild()],
62+
];
63+
}
64+
65+
/**
66+
* @dataProvider typeOfRequestWithArgumentProvider
67+
*/
68+
public function testMethodsWithArgumentMakeCorrectTypeOfRequest(
69+
$function,
70+
$requestType,
71+
$argument
72+
) {
73+
$responseMock = $this->getMockBuilder('\GuzzleHttp\Message\Response')
74+
->disableOriginalConstructor()->getMock();
75+
$responseMock->expects($this->once())->method('json')
76+
->willReturn($this->returnValue(true));
77+
78+
$guzzleClientMock = $this->getMockBuilder('\GuzzleHttp\Client')
79+
->disableOriginalConstructor()->getMock();
80+
$guzzleClientMock->expects($this->once())->method($requestType)
81+
->willReturn($responseMock);
82+
83+
$client = new Client('team', 'username', 'password');
84+
$client->setClient($guzzleClientMock);
85+
86+
$client->project(123)->$function($argument);
87+
}
88+
2089
}

0 commit comments

Comments
 (0)