From d9b5ec43ddefe303e8a6d8bf208ae93301b228db Mon Sep 17 00:00:00 2001 From: Joe Ferguson Date: Tue, 9 Feb 2016 16:56:29 -0600 Subject: [PATCH 1/3] fix parsing data from Guzzle object, NEED TO FIX BROKEN TESTS :/ --- src/Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin.php b/src/Plugin.php index db41105..813043a 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -169,7 +169,7 @@ protected function getApiRequest($url, Event $event, Queue $queue) public function resolve($url, $data, Event $event, Queue $queue) { $logger = $this->getLogger(); - $json = json_decode($data); + $json = json_decode($data->getBody()); $logger->info('resolve', array('url' => $url, 'json' => $json)); if (isset($json->error)) { From 1f61f483959d9ee09ef1d9d893a6293b96bb410c Mon Sep 17 00:00:00 2001 From: Heath Nail Date: Tue, 9 Feb 2016 18:26:43 -0500 Subject: [PATCH 2/3] Add typehint to Plugin::resolve() --- src/Plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 813043a..1437dd8 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -162,11 +162,11 @@ protected function getApiRequest($url, Event $event, Queue $queue) * Handles a successful request for video data. * * @param string $url URL of the request - * @param string $data Response body + * @param \GuzzleHttp\Message\Response $data Response body * @param \Phergie\Irc\EventInterface $event * @param \Phergie\Irc\Bot\React\EventQueueInterface $queue */ - public function resolve($url, $data, Event $event, Queue $queue) + public function resolve($url, \GuzzleHttp\Message\Response $data, Event $event, Queue $queue) { $logger = $this->getLogger(); $json = json_decode($data->getBody()); From fc83f5795b75f58bea677c1c571c3c77e517d447 Mon Sep 17 00:00:00 2001 From: Heath Nail Date: Tue, 9 Feb 2016 18:27:32 -0500 Subject: [PATCH 3/3] Use mock of GuzzleHttp\Message\Response --- tests/PluginTest.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/PluginTest.php b/tests/PluginTest.php index 6843a0a..d1f44c8 100644 --- a/tests/PluginTest.php +++ b/tests/PluginTest.php @@ -10,6 +10,7 @@ namespace Phergie\Irc\Tests\Plugin\React\YouTube; +use GuzzleHttp\Message\Response as Response; use Phake; use Phergie\Irc\Bot\React\EventQueueInterface as Queue; use Phergie\Irc\Plugin\React\Command\CommandEvent as Event; @@ -67,6 +68,7 @@ protected function setUp() $this->queue = Phake::mock('\Phergie\Irc\Bot\React\EventQueueInterface'); $this->emitter = Phake::mock('\Evenement\EventEmitterInterface'); $this->logger = Phake::mock('\Psr\Log\LoggerInterface'); + $this->response = Phake::mock('\GuzzleHttp\Message\Response'); $this->plugin = $this->getPlugin(); date_default_timezone_set('America/Chicago'); @@ -215,8 +217,8 @@ public function testResolveWithApiError() Phake::verifyNoFurtherInteraction($this->queue); $requestConfig = $this->testHandleUrlWithVideoUrl('http://youtu.be/HFuTvTVAO-M'); $resolve = $requestConfig['resolveCallback']; - $data = '{"error":"foo"}'; - $resolve($data, $this->event, $this->queue); + Phake::when($this->response)->getBody()->thenReturn('{"error":"foo"}'); + $resolve($this->response, $this->event, $this->queue); Phake::verify($this->logger)->warning( 'Query response contained an error', array( @@ -234,8 +236,8 @@ public function testResolveWithNoResults() Phake::verifyNoFurtherInteraction($this->queue); $requestConfig = $this->testHandleUrlWithVideoUrl('http://youtu.be/HFuTvTVAO-M'); $resolve = $requestConfig['resolveCallback']; - $data = file_get_contents(__DIR__ . '/_files/empty.json'); - $resolve($data, $this->event, $this->queue); + Phake::when($this->response)->getBody()->thenReturn(file_get_contents(__DIR__ . '/_files/empty.json')); + $resolve($this->response, $this->event, $this->queue); Phake::verify($this->logger)->warning( 'Query returned no results', array( @@ -302,8 +304,8 @@ public function testResolveWithResults(array $config, $message) Phake::when($this->event)->getSource()->thenReturn('#channel'); $requestConfig = $this->testHandleUrlWithVideoUrl('http://youtu.be/HFuTvTVAO-M'); $resolve = $requestConfig['resolveCallback']; - $data = file_get_contents(__DIR__ . '/_files/success.json'); - $resolve($data, $this->event, $this->queue); + Phake::when($this->response)->getBody()->thenReturn(file_get_contents(__DIR__ . '/_files/success.json')); + $resolve($this->response, $this->event, $this->queue); Phake::verify($this->queue)->ircPrivmsg('#channel', $message); }