Skip to content

Commit 7e0d6fd

Browse files
authored
[4.0] Change access to body of Response object (#62)
* Change access to body of Response object * Fix unittests
1 parent 417aa8e commit 7e0d6fd

37 files changed

+157
-287
lines changed

Tests/Package/Activity/EventsTest.php

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @license GNU General Public License version 2 or later; see LICENSE
66
*/
77

8-
namespace Joomla\Github\Tests;
8+
namespace Joomla\Github\Tests\Package\Activity;
99

1010
use Joomla\Github\Package\Activity\Events;
1111
use Joomla\Github\Tests\Stub\GitHubTestCase;
@@ -62,8 +62,7 @@ public function testGetPublic()
6262
->with('/events')
6363
->willReturn($this->response);
6464

65-
$response = json_decode($this->response->getBody()->getContents());
66-
$this->response->getBody()->rewind();
65+
$response = json_decode((string) $this->response->getBody());
6766

6867
$this->assertEquals(
6968
$response,
@@ -85,8 +84,7 @@ public function testGetRepository()
8584
->with($path)
8685
->willReturn($this->response);
8786

88-
$response = json_decode($this->response->getBody()->getContents());
89-
$this->response->getBody()->rewind();
87+
$response = json_decode((string) $this->response->getBody());
9088

9189
$this->assertEquals(
9290
$response,
@@ -108,8 +106,7 @@ public function testGetIssue()
108106
->with($path)
109107
->willReturn($this->response);
110108

111-
$response = json_decode($this->response->getBody()->getContents());
112-
$this->response->getBody()->rewind();
109+
$response = json_decode((string) $this->response->getBody());
113110

114111
$this->assertEquals(
115112
$response,
@@ -131,8 +128,7 @@ public function testGetNetwork()
131128
->with($path)
132129
->willReturn($this->response);
133130

134-
$response = json_decode($this->response->getBody()->getContents());
135-
$this->response->getBody()->rewind();
131+
$response = json_decode((string) $this->response->getBody());
136132

137133
$this->assertEquals(
138134
$response,
@@ -154,8 +150,7 @@ public function testGetOrg()
154150
->with($path)
155151
->willReturn($this->response);
156152

157-
$response = json_decode($this->response->getBody()->getContents());
158-
$this->response->getBody()->rewind();
153+
$response = json_decode((string) $this->response->getBody());
159154

160155
$this->assertEquals(
161156
$response,
@@ -177,8 +172,7 @@ public function testGetUser()
177172
->with($path)
178173
->willReturn($this->response);
179174

180-
$response = json_decode($this->response->getBody()->getContents());
181-
$this->response->getBody()->rewind();
175+
$response = json_decode((string) $this->response->getBody());
182176

183177
$this->assertEquals(
184178
$response,
@@ -200,8 +194,7 @@ public function testGetUserPublic()
200194
->with($path)
201195
->willReturn($this->response);
202196

203-
$response = json_decode($this->response->getBody()->getContents());
204-
$this->response->getBody()->rewind();
197+
$response = json_decode((string) $this->response->getBody());
205198

206199
$this->assertEquals(
207200
$response,
@@ -223,8 +216,7 @@ public function testGetByUser()
223216
->with($path)
224217
->willReturn($this->response);
225218

226-
$response = json_decode($this->response->getBody()->getContents());
227-
$this->response->getBody()->rewind();
219+
$response = json_decode((string) $this->response->getBody());
228220

229221
$this->assertEquals(
230222
$response,
@@ -246,8 +238,7 @@ public function testGetByUserPublic()
246238
->with($path)
247239
->willReturn($this->response);
248240

249-
$response = json_decode($this->response->getBody()->getContents());
250-
$this->response->getBody()->rewind();
241+
$response = json_decode((string) $this->response->getBody());
251242

252243
$this->assertEquals(
253244
$response,
@@ -269,8 +260,7 @@ public function testGetUserOrg()
269260
->with($path)
270261
->willReturn($this->response);
271262

272-
$response = json_decode($this->response->getBody()->getContents());
273-
$this->response->getBody()->rewind();
263+
$response = json_decode((string) $this->response->getBody());
274264

275265
$this->assertEquals(
276266
$response,

Tests/Package/Activity/FeedsTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public function testGetFeeds()
5050
->with('/feeds')
5151
->willReturn($this->response);
5252

53-
$response = json_decode($this->response->getBody()->getContents());
54-
$this->response->getBody()->rewind();
53+
$response = json_decode((string) $this->response->getBody());
5554

5655
$this->assertEquals(
5756
$response,

Tests/Package/Activity/NotificationsTest.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @license GNU General Public License version 2 or later; see LICENSE
66
*/
77

8-
namespace Joomla\Github\Tests;
8+
namespace Joomla\Github\Tests\Package\Activity;
99

1010
use Joomla\Github\Package\Activity\Notifications;
1111
use Joomla\Github\Tests\Stub\GitHubTestCase;
@@ -54,8 +54,7 @@ public function testGetList()
5454
->with('/notifications?all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00', [], 0)
5555
->willReturn($this->response);
5656

57-
$response = json_decode($this->response->getBody()->getContents());
58-
$this->response->getBody()->rewind();
57+
$response = json_decode((string) $this->response->getBody());
5958

6059
$this->assertEquals(
6160
$response,
@@ -79,8 +78,7 @@ public function testGetListRepository()
7978
->with('/repos/{owner}/{repo}/notifications?' . $args, [], 0)
8079
->willReturn($this->response);
8180

82-
$response = json_decode($this->response->getBody()->getContents());
83-
$this->response->getBody()->rewind();
81+
$response = json_decode((string) $this->response->getBody());
8482

8583
$this->assertEquals(
8684
$response,
@@ -111,8 +109,7 @@ public function testMarkRead()
111109
->with('/notifications', '{"unread":true,"read":true}', [], 0)
112110
->willReturn($this->response);
113111

114-
$response = $this->response->getBody()->getContents();
115-
$this->response->getBody()->rewind();
112+
$response = (string) $this->response->getBody();
116113

117114
$this->assertEquals(
118115
$response,
@@ -139,8 +136,7 @@ public function testMarkReadLastRead()
139136
->with('/notifications', $data, [], 0)
140137
->willReturn($this->response);
141138

142-
$response = $this->response->getBody()->getContents();
143-
$this->response->getBody()->rewind();
139+
$response = (string) $this->response->getBody();
144140

145141
$this->assertEquals(
146142
$response,
@@ -166,8 +162,7 @@ public function testMarkReadRepository()
166162
->with('/repos/joomla/joomla-platform/notifications', $data, [], 0)
167163
->willReturn($this->response);
168164

169-
$response = $this->response->getBody()->getContents();
170-
$this->response->getBody()->rewind();
165+
$response = (string) $this->response->getBody();
171166

172167
$this->assertEquals(
173168
$response,
@@ -194,8 +189,7 @@ public function testMarkReadRepositoryLastRead()
194189
->with('/repos/joomla/joomla-platform/notifications', $data, [], 0)
195190
->willReturn($this->response);
196191

197-
$response = $this->response->getBody()->getContents();
198-
$this->response->getBody()->rewind();
192+
$response = (string) $this->response->getBody();
199193

200194
$this->assertEquals(
201195
$response,
@@ -217,8 +211,7 @@ public function testViewThread()
217211
->with('/notifications/threads/1', [], 0)
218212
->willReturn($this->response);
219213

220-
$response = json_decode($this->response->getBody()->getContents());
221-
$this->response->getBody()->rewind();
214+
$response = json_decode((string) $this->response->getBody());
222215

223216
$this->assertEquals(
224217
$response,
@@ -242,8 +235,7 @@ public function testMarkReadThread()
242235
->with('/notifications/threads/1', '{"unread":true,"read":true}', [], 0)
243236
->willReturn($this->response);
244237

245-
$response = json_decode($this->response->getBody()->getContents());
246-
$this->response->getBody()->rewind();
238+
$response = json_decode((string) $this->response->getBody());
247239

248240
$this->assertEquals(
249241
$response,
@@ -265,8 +257,7 @@ public function testGetThreadSubscription()
265257
->with('/notifications/threads/1/subscription', [], 0)
266258
->willReturn($this->response);
267259

268-
$response = json_decode($this->response->getBody()->getContents());
269-
$this->response->getBody()->rewind();
260+
$response = json_decode((string) $this->response->getBody());
270261

271262
$this->assertEquals(
272263
$response,
@@ -288,8 +279,7 @@ public function testSetThreadSubscription()
288279
->with('/notifications/threads/1/subscription', '{"subscribed":true,"ignored":false}', [], 0)
289280
->willReturn($this->response);
290281

291-
$response = json_decode($this->response->getBody()->getContents());
292-
$this->response->getBody()->rewind();
282+
$response = json_decode((string) $this->response->getBody());
293283

294284
$this->assertEquals(
295285
$response,
@@ -313,8 +303,7 @@ public function testDeleteThreadSubscription()
313303
->with('/notifications/threads/1/subscription', [], 0)
314304
->willReturn($this->response);
315305

316-
$response = json_decode($this->response->getBody()->getContents());
317-
$this->response->getBody()->rewind();
306+
$response = json_decode((string) $this->response->getBody());
318307

319308
$this->assertEquals(
320309
$response,

Tests/Package/Activity/StarringTest.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @license GNU General Public License version 2 or later; see LICENSE
66
*/
77

8-
namespace Joomla\Github\Tests;
8+
namespace Joomla\Github\Tests\Package\Activity;
99

1010
use Joomla\Github\Package\Activity\Starring;
1111
use Joomla\Github\Tests\Stub\GitHubTestCase;
@@ -54,8 +54,7 @@ public function testGetList()
5454
->with('/repos/joomla/joomla-platform/stargazers', [], 0)
5555
->willReturn($this->response);
5656

57-
$response = json_decode($this->response->getBody()->getContents());
58-
$this->response->getBody()->rewind();
57+
$response = json_decode((string) $this->response->getBody());
5958

6059
$this->assertEquals(
6160
$response,
@@ -77,8 +76,7 @@ public function testGetRepositories()
7776
->with('/user/starred?sort=created&direction=desc', [], 0)
7877
->willReturn($this->response);
7978

80-
$response = json_decode($this->response->getBody()->getContents());
81-
$this->response->getBody()->rewind();
79+
$response = json_decode((string) $this->response->getBody());
8280

8381
$this->assertEquals(
8482
$response,
@@ -100,8 +98,7 @@ public function testGetRepositoriesWithName()
10098
->with('/users/{user}/starred?sort=created&direction=desc', [], 0)
10199
->willReturn($this->response);
102100

103-
$response = json_decode($this->response->getBody()->getContents());
104-
$this->response->getBody()->rewind();
101+
$response = json_decode((string) $this->response->getBody());
105102

106103
$this->assertEquals(
107104
$response,
@@ -157,8 +154,7 @@ public function testCheck()
157154
->with('/user/starred/joomla/joomla-platform', [], 0)
158155
->willReturn($this->response);
159156

160-
$response = json_decode($this->response->getBody()->getContents());
161-
$this->response->getBody()->rewind();
157+
$response = json_decode((string) $this->response->getBody());
162158

163159
$this->assertEquals(
164160
$response,
@@ -182,8 +178,7 @@ public function testCheckFalse()
182178
->with('/user/starred/joomla/joomla-platform', [], 0)
183179
->willReturn($this->response);
184180

185-
$response = json_decode($this->response->getBody()->getContents());
186-
$this->response->getBody()->rewind();
181+
$response = json_decode((string) $this->response->getBody());
187182

188183
$this->assertEquals(
189184
$response,
@@ -209,8 +204,7 @@ public function testCheckUnexpected()
209204
->with('/user/starred/joomla/joomla-platform', [], 0)
210205
->willReturn($this->response);
211206

212-
$response = json_decode($this->response->getBody()->getContents());
213-
$this->response->getBody()->rewind();
207+
$response = json_decode((string) $this->response->getBody());
214208

215209
$this->assertEquals(
216210
$response,
@@ -234,8 +228,7 @@ public function testStar()
234228
->with('/user/starred/joomla/joomla-platform', '', [], 0)
235229
->willReturn($this->response);
236230

237-
$response = json_decode($this->response->getBody()->getContents());
238-
$this->response->getBody()->rewind();
231+
$response = json_decode((string) $this->response->getBody());
239232

240233
$this->assertEquals(
241234
$response,
@@ -259,8 +252,7 @@ public function testUnstar()
259252
->with('/user/starred/joomla/joomla-platform', [], 0)
260253
->willReturn($this->response);
261254

262-
$response = json_decode($this->response->getBody()->getContents());
263-
$this->response->getBody()->rewind();
255+
$response = json_decode((string) $this->response->getBody());
264256

265257
$this->assertEquals(
266258
$response,

0 commit comments

Comments
 (0)