Skip to content

Commit

Permalink
test(client): Add tests on queries from the client
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-san committed Jul 13, 2017
1 parent 46628bd commit 85b3a79
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 28 deletions.
15 changes: 12 additions & 3 deletions src/API/REST/Client/TwitterApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function getMentionsTweets($from = null, $to = null)
if (!empty($tweets) && $from !== null) {
$moreTweets = $this->getMentionsTweets($from, min(array_keys($tweets))-1);
if (!empty($moreTweets)) {
$tweets = $tweets + $moreTweets;
$tweets += $moreTweets;
}
}
ksort($tweets);
Expand Down Expand Up @@ -164,7 +164,7 @@ public function getDirectMessages($from = null, $to = null)
if (!empty($dms) && $from !== null) {
$moreDms = $this->getDirectMessages($from, min(array_keys($dms))-1);
if (!empty($moreDms)) {
$dms = $dms + $moreDms;
$dms += $moreDms;
}
}
ksort($dms);
Expand Down Expand Up @@ -372,6 +372,15 @@ public function unfollow(TwitterUser $user)
$this->handleResponse(self::UNFOLLOW, $response);
}

/**
* @param string $category
* @param ApiRate $rate
*/
public function setRateLimit($category, ApiRate $rate)
{
$this->rateLimits[$category] = $rate;
}

/**
* @param string $category
*
Expand All @@ -395,6 +404,6 @@ private function checkRate($category)
*/
private function handleResponse($category, ApiResponse $response)
{
$this->rateLimits[$category] = $response->getRate();
$this->setRateLimit($category, $response->getRate());
}
}
3 changes: 2 additions & 1 deletion src/API/REST/Response/LimitedApiRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function getLimit()
*/
public function canMakeAnotherCall()
{
return $this->remaining > 0;
return $this->reset <= new \DateTimeImmutable('now', new \DateTimeZone('UTC'))
|| $this->remaining > 0;
}

/**
Expand Down

0 comments on commit 85b3a79

Please sign in to comment.