Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit 0ab42be

Browse files
committed
Merge pull request #9 from phergie/use-response-object
Fixed missing conversion to Reponse object
2 parents 38f5a2d + 1bba4af commit 0ab42be

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/Plugin.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Phergie\Irc\Plugin\React\Url;
1212

13+
use GuzzleHttp\Message\Response;
1314
use React\EventLoop\LoopInterface;
1415
use Phergie\Irc\Bot\React\AbstractPlugin;
1516
use Phergie\Irc\Bot\React\EventQueue;
@@ -176,8 +177,13 @@ public function createRequest($requestId, $url, UserEvent $event, EventQueue $qu
176177
$this->logDebug('[' . $requestId . ']Reponse (after ' . ($end - $start) . 's): ' . $code);
177178
},
178179
'resolveCallback' =>
179-
function ($result) use ($requestId, $url, $event, $queue, $start) {
180-
list ($data, $headers, $code) = $result;
180+
function (Response $response) use ($requestId, $url, $event, $queue, $start) {
181+
$data = $response->getBody()->getContents();
182+
$headers = $response->getHeaders();
183+
array_walk($headers, function (&$value, $key) use ($response) {
184+
$value = $response->getHeader($key);
185+
});
186+
$code = $response->getStatusCode();
181187
$end = microtime(true);
182188
$message = '[';
183189
$message .= $requestId;

tests/PluginTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Phergie\Tests\Irc\Plugin\React\Url;
1212

13+
use GuzzleHttp\Message\Response;
1314
use Phake;
1415
use Phergie\Irc\Plugin\React\Url\Plugin;
1516
use React\Promise\FulfilledPromise;
@@ -249,13 +250,20 @@ public function testCreateRequest() {
249250

250251
Phake::when($plugin)->emitShorteningEvents($this->isType('string'), $this->isType('string'))->thenReturn(new FulfilledPromise($url));
251252

252-
$request->callResolve(['', array(
253-
'foo' => 'bar',
254-
), 200]);
253+
$body = Phake::mock('GuzzleHttp\Stream\StreamInterface');
254+
Phake::when($body)->getContents()->thenReturn('');
255255

256-
$request->callResolve(['', array(
257-
'foo' => 'bar',
258-
), 200]);
256+
$request->callResolve(
257+
new Response(200, [
258+
'foo' => 'bar',
259+
], $body)
260+
);
261+
262+
$request->callResolve(
263+
new Response(200, [
264+
'foo' => 'bar',
265+
], $body)
266+
);
259267

260268
Phake::inOrder(
261269
Phake::verify($plugin, Phake::times(2))->logDebug($this->isType('string')),

0 commit comments

Comments
 (0)