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

Commit

Permalink
Use mock of GuzzleHttp\Message\Response
Browse files Browse the repository at this point in the history
  • Loading branch information
sitedyno committed Feb 9, 2016
1 parent 1f61f48 commit fc83f57
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit fc83f57

Please sign in to comment.