public
Created

  • Download Gist
gistfile1.aw
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
<?php
 
namespace Knp\Bundle\LastTweetsBundle\Tests\Twitter\LastTweetsFetcher;
 
use Knp\Bundle\LastTweetsBundle\Twitter\LastTweetsFetcher\ApiFetcher;
use Knp\Bundle\LastTweetsBundle\Twitter\Tweet;
 
class ApiFetcherTest extends \PHPUnit_Framework_TestCase
{
const CLASSNAME = 'Knp\Bundle\LastTweetsBundle\Twitter\LastTweetsFetcher\ApiFetcher';
public function testRealFetchWithLimit()
{
$fixture = json_encode(array(
'one' => array('id' => 1, 'id_str' => 1, 'text' => 'asdasdasd', 'created_at' => 'Thu Apr 04 11:58:04 +0000 2012'),
'two' => array('id' => 2, 'id_str' => 2, 'text' => 'asdasdasd2', 'created_at' => 'Thu Apr 05 12:45:43 +0000 2012'),
'three' => array('id' => 3, 'id_str' => 3, 'text' => 'asdasdasd3', 'created_at' => 'Thu Apr 06 13:22:28 +0000 2012'),
'four' => array('id' => 4, 'id_str' => 4, 'text' => 'asdasdasd4', 'created_at' => 'Thu Apr 07 14:36:01 +0000 2012')
));
$mockedBrowser = $this->getMockedBrowser();
$mockedResponse = $this->getMockedResponse($fixture);
$mockedBrowser->expects($this->exactly(2))
->method('get')
->will($this->returnValue($mockedResponse));
$fetcher = new ApiFetcher($mockedBrowser);
$tweets = $fetcher->fetch(array('knplabs', 'knplabsru'), 4);
$this->assertCount(4, $tweets);
}
 
protected function getMockedBrowser()
{
$browser = $this->getMock('Buzz\Browser');
return $browser;
}
protected function getMockedResponse($fixture)
{
$response = $this->getMock('Buzz\Browser\Message\Response', array('getContent'));
$response->expects($this->atLeastOnce())
->method('getContent')
->will($this->returnValue($fixture));
return $response;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.