-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(parser): Test the Codebird response parser
- Loading branch information
Showing
3 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
tests/unit/API/REST/Gateway/CodebirdResponseParserTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
|
||
namespace Twitter\Test\API\REST\Gateway; | ||
|
||
use Codebird\Codebird; | ||
use Faker\Factory; | ||
use Faker\Generator; | ||
use Mockery\Mock; | ||
use Twitter\API\Exception\TwitterException; | ||
use Twitter\API\REST\DTO\DirectMessageParameters; | ||
use Twitter\API\REST\DTO\FollowParameters; | ||
use Twitter\API\REST\DTO\TweetParameters; | ||
use Twitter\API\REST\DTO\UserIdentifier; | ||
use Twitter\API\REST\Factory\CodebirdFactory; | ||
use Twitter\API\REST\Gateway\CodebirdResponseParser; | ||
use Twitter\API\REST\Gateway\CodebirdTwitterApiGateway; | ||
use Twitter\API\REST\OAuth\AuthenticationToken; | ||
use Twitter\API\REST\Query\DirectMessage\DirectMessageQuery; | ||
use Twitter\API\REST\Query\Stream\UserStreamQuery; | ||
use Twitter\API\REST\Query\Tweet\MentionsTimelineQuery; | ||
use Twitter\API\REST\Query\User\UserInformationQuery; | ||
use Twitter\API\REST\Response\ApiResponse; | ||
use Twitter\API\REST\Response\HttpStatus; | ||
use Twitter\API\REST\Response\LimitedApiRate; | ||
use Twitter\API\REST\Response\UnlimitedApiRate; | ||
use Twitter\API\REST\TwitterApiGateway; | ||
|
||
class CodebirdResponseParserTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var CodebirdResponseParser */ | ||
private $sut; | ||
|
||
public function setUp() | ||
{ | ||
$this->sut = new CodebirdResponseParser(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
\Mockery::close(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itShouldParseAnObjectResponseWithNoRateLimit() | ||
{ | ||
$object = new \stdClass(); | ||
$object->httpstatus = 200; | ||
$object->value = 'value'; | ||
|
||
$response = $this->sut->parseObject($object); | ||
|
||
$this->assertInstanceOf(ApiResponse::class, $response); | ||
$this->assertEquals(new UnlimitedApiRate(), $response->getRate()); | ||
$this->assertEquals(new HttpStatus(200), $response->getHttpStatus()); | ||
$this->assertEquals('value', $response->getContent()->value); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itShouldParseAnObjectResponseWithRateLimit() | ||
{ | ||
$time = time(); | ||
|
||
$object = new \stdClass(); | ||
$object->httpstatus = 200; | ||
$object->value = 'value'; | ||
$object->rate = [ | ||
'limit' => 10, | ||
'remaining' => 5, | ||
'reset' => $time | ||
]; | ||
|
||
$response = $this->sut->parseObject($object); | ||
|
||
$this->assertInstanceOf(ApiResponse::class, $response); | ||
$this->assertEquals(new LimitedApiRate(10, 5, $time), $response->getRate()); | ||
$this->assertEquals(new HttpStatus(200), $response->getHttpStatus()); | ||
$this->assertEquals('value', $response->getContent()->value); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itShouldParseANullObjectResponseWithNoRateLimit() | ||
{ | ||
$object = new \stdClass(); | ||
$object->httpstatus = 200; | ||
|
||
$response = $this->sut->parseObject($object); | ||
|
||
$this->assertInstanceOf(ApiResponse::class, $response); | ||
$this->assertEquals(new UnlimitedApiRate(), $response->getRate()); | ||
$this->assertEquals(new HttpStatus(200), $response->getHttpStatus()); | ||
$this->assertNull($response->getContent()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itShouldParseAListResponseWithNoRateLimit() | ||
{ | ||
$object = new \stdClass(); | ||
$object->{'0'} = 'zero'; | ||
$object->{'1'} = 'one'; | ||
$object->httpstatus = 200; | ||
|
||
$response = $this->sut->parseList($object); | ||
|
||
$this->assertInstanceOf(ApiResponse::class, $response); | ||
$this->assertEquals(new UnlimitedApiRate(), $response->getRate()); | ||
$this->assertEquals(new HttpStatus(200), $response->getHttpStatus()); | ||
$this->assertEquals( | ||
['zero', 'one'], | ||
$response->getContent() | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itShouldSendAnErrorIfTheResponseIsAnError() | ||
{ | ||
$this->setExpectedException(TwitterException::class); | ||
|
||
$error = new \stdClass(); | ||
$error->message = 'my error message'; | ||
$error->code = 33; | ||
|
||
$object = new \stdClass(); | ||
$object->errors = [ $error ]; | ||
|
||
$this->sut->parseObject($object); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itShouldSendAnErrorIfTheHttpStatusIsInError() | ||
{ | ||
$this->setExpectedException(TwitterException::class); | ||
|
||
$object = new \stdClass(); | ||
$object->httpstatus = 500; | ||
$object->message = 'error'; | ||
|
||
$this->sut->parseObject($object); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters