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

Commit

Permalink
Merge pull request #250 from seregazhuk/develop
Browse files Browse the repository at this point in the history
fix: Pagination fails on last response
  • Loading branch information
seregazhuk authored Mar 18, 2017
2 parents fcf40d1 + 131fa56 commit a50757a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## v5.2.5 - 2017-03-18
### Fixed:
- Pagination fails on last response.

## v5.2.4 - 2017-03-16
### Added:
- Pinners *tried* pins.
Expand Down
9 changes: 4 additions & 5 deletions src/Api/Providers/Core/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ protected function post($requestOptions, $resourceUrl, $returnResponse = false)
*
* @param array $requestOptions
* @param string $resourceUrl
* @param bool $returnResponse
* @return array|bool|Response
*/
protected function get(array $requestOptions = [], $resourceUrl = '')
protected function get(array $requestOptions = [], $resourceUrl = '', $returnResponse = false)
{
$query = Request::createQuery(
$requestOptions,
Expand All @@ -75,9 +76,7 @@ protected function get(array $requestOptions = [], $resourceUrl = '')

$this->execute($resourceUrl . '?' . $query);

return $this->response->hasBookmarks() ?
$this->response :
$this->response->getResponseData();
return $returnResponse ? $this->response : $this->response->getResponseData();

}

Expand Down Expand Up @@ -123,7 +122,7 @@ public function isLoggedIn()
protected function paginate($data, $resourceUrl, $limit = Pagination::DEFAULT_LIMIT)
{
return $this->paginateCustom(function() use ($data, $resourceUrl) {
return $this->get($data, $resourceUrl);
return $this->get($data, $resourceUrl, true);
})->take($limit);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Api/Traits/HandlesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ abstract protected function post($requestOptions, $resourceUrl, $returnResponse
*
* @param array $requestOptions
* @param string $resourceUrl
* @param bool $returnResponse
* @return array|bool|Response
*/
abstract protected function get(array $requestOptions = [], $resourceUrl = '');
abstract protected function get(array $requestOptions = [], $resourceUrl = '', $returnResponse = false);
}
12 changes: 12 additions & 0 deletions tests/Bot/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace seregazhuk\tests\Bot;

use Mockery;
use PHPUnit_Framework_TestCase;
use seregazhuk\PinterestBot\Api\Response;
use seregazhuk\tests\Helpers\ResponseHelper;
Expand Down Expand Up @@ -119,6 +120,17 @@ public function it_accepts_limit_in_constructor()

$this->assertEquals($expected, $pagination->toArray());
}

/** @test */
public function it_stops_when_response_is_empty()
{
$pagination = new Pagination();
$pagination->paginateOver(function(){
return (new Response())->fill([]);
});

$this->assertCount(0, $pagination->toArray());
}
}


12 changes: 1 addition & 11 deletions tests/Bot/ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function tearDown()
}

/** @test */
public function it_returns_data_for_response_without_pagination()
public function it_returns_data_for_response()
{
$response = ['resource_response' => ['data' => 'value']];

Expand All @@ -31,16 +31,6 @@ public function it_returns_data_for_response_without_pagination()
$this->assertEquals($responseData, $provider->visitPage());
}

/** @test */
public function it_returns_response_object_if_it_has_pagination()
{
$response = ['resource' => ['options' => ['bookmarks' => 'bookmarks_string']]];

$provider = $this->makeProvider($response);

$this->assertInstanceOf(Response::class, $provider->visitPage());
}

/**
* @param $response
* @return Mockery\Mock|Provider
Expand Down

0 comments on commit a50757a

Please sign in to comment.