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

Commit e31aba9

Browse files
committed
Merge pull request #9 from phergie/dev
Merge PR from sitedyno
2 parents dd52738 + f9e4684 commit e31aba9

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/Plugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ protected function getApiRequest($url, Event $event, Queue $queue)
162162
* Handles a successful request for video data.
163163
*
164164
* @param string $url URL of the request
165-
* @param string $data Response body
165+
* @param \GuzzleHttp\Message\Response $data Response body
166166
* @param \Phergie\Irc\EventInterface $event
167167
* @param \Phergie\Irc\Bot\React\EventQueueInterface $queue
168168
*/
169-
public function resolve($url, $data, Event $event, Queue $queue)
169+
public function resolve($url, \GuzzleHttp\Message\Response $data, Event $event, Queue $queue)
170170
{
171171
$logger = $this->getLogger();
172-
$json = json_decode($data);
172+
$json = json_decode($data->getBody());
173173
$logger->info('resolve', array('url' => $url, 'json' => $json));
174174

175175
if (isset($json->error)) {

tests/PluginTest.php

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

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

13+
use GuzzleHttp\Message\Response as Response;
1314
use Phake;
1415
use Phergie\Irc\Bot\React\EventQueueInterface as Queue;
1516
use Phergie\Irc\Plugin\React\Command\CommandEvent as Event;
@@ -67,6 +68,7 @@ protected function setUp()
6768
$this->queue = Phake::mock('\Phergie\Irc\Bot\React\EventQueueInterface');
6869
$this->emitter = Phake::mock('\Evenement\EventEmitterInterface');
6970
$this->logger = Phake::mock('\Psr\Log\LoggerInterface');
71+
$this->response = Phake::mock('\GuzzleHttp\Message\Response');
7072
$this->plugin = $this->getPlugin();
7173

7274
date_default_timezone_set('America/Chicago');
@@ -215,8 +217,8 @@ public function testResolveWithApiError()
215217
Phake::verifyNoFurtherInteraction($this->queue);
216218
$requestConfig = $this->testHandleUrlWithVideoUrl('http://youtu.be/HFuTvTVAO-M');
217219
$resolve = $requestConfig['resolveCallback'];
218-
$data = '{"error":"foo"}';
219-
$resolve($data, $this->event, $this->queue);
220+
Phake::when($this->response)->getBody()->thenReturn('{"error":"foo"}');
221+
$resolve($this->response, $this->event, $this->queue);
220222
Phake::verify($this->logger)->warning(
221223
'Query response contained an error',
222224
array(
@@ -234,8 +236,8 @@ public function testResolveWithNoResults()
234236
Phake::verifyNoFurtherInteraction($this->queue);
235237
$requestConfig = $this->testHandleUrlWithVideoUrl('http://youtu.be/HFuTvTVAO-M');
236238
$resolve = $requestConfig['resolveCallback'];
237-
$data = file_get_contents(__DIR__ . '/_files/empty.json');
238-
$resolve($data, $this->event, $this->queue);
239+
Phake::when($this->response)->getBody()->thenReturn(file_get_contents(__DIR__ . '/_files/empty.json'));
240+
$resolve($this->response, $this->event, $this->queue);
239241
Phake::verify($this->logger)->warning(
240242
'Query returned no results',
241243
array(
@@ -302,8 +304,8 @@ public function testResolveWithResults(array $config, $message)
302304
Phake::when($this->event)->getSource()->thenReturn('#channel');
303305
$requestConfig = $this->testHandleUrlWithVideoUrl('http://youtu.be/HFuTvTVAO-M');
304306
$resolve = $requestConfig['resolveCallback'];
305-
$data = file_get_contents(__DIR__ . '/_files/success.json');
306-
$resolve($data, $this->event, $this->queue);
307+
Phake::when($this->response)->getBody()->thenReturn(file_get_contents(__DIR__ . '/_files/success.json'));
308+
$resolve($this->response, $this->event, $this->queue);
307309
Phake::verify($this->queue)->ircPrivmsg('#channel', $message);
308310
}
309311

0 commit comments

Comments
 (0)