Skip to content

Deprecate ResultPager::postFetch method #986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## UPGRADE from 3.x to 4.0

### ResultPager

* `\Github\ResultPagerInterface::postFetch` is deprecated, and the method will be removed from the ResultPager interface/class.
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"psr/http-client-implementation": "^1.0",
"psr/http-factory-implementation": "^1.0",
"psr/http-message": "^1.0",
"symfony/polyfill-php80": "^1.17"
"symfony/polyfill-php80": "^1.17",
"symfony/deprecation-contracts": "^2.2"
},
"require-dev": {
"symfony/cache": "^5.1.8",
Expand All @@ -39,7 +40,8 @@
"phpstan/phpstan": "^0.12.57",
"phpstan/extension-installer": "^1.0.5",
"phpstan/phpstan-deprecation-rules": "^0.12.5",
"phpunit/phpunit": "^8.5 || ^9.4"
"phpunit/phpunit": "^8.5 || ^9.4",
"symfony/phpunit-bridge": "^5.2"
},
"autoload": {
"psr-4": { "Github\\": "lib/Github/" }
Expand All @@ -50,7 +52,7 @@
"extra": {
"branch-alias": {
"dev-2.x": "2.19.x-dev",
"dev-master": "3.1.x-dev"
"dev-master": "3.2.x-dev"
}
}
}
17 changes: 13 additions & 4 deletions lib/Github/ResultPager.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function fetch(AbstractApi $api, string $method, array $parameters = []):
$api = $closure($api);
$result = $api->$method(...$parameters);

$this->postFetch();
$this->postFetch(true);

return $result;
}
Expand Down Expand Up @@ -130,9 +130,13 @@ public function fetchAllLazy(AbstractApi $api, string $method, array $parameters
/**
* {@inheritdoc}
*/
public function postFetch(): void
public function postFetch(/* $skipDeprecation = false */): void
{
$this->pagination = ResponseMediator::getPagination($this->client->getLastResponse());
if (func_num_args() === 0 || (func_num_args() > 0 && false === func_get_arg(0))) {
trigger_deprecation('KnpLabs/php-github-api', '3.2', 'The "%s" method is deprecated and will be removed.', __METHOD__);
}

$this->setPagination();
}

/**
Expand Down Expand Up @@ -196,8 +200,13 @@ protected function get(string $key): array

$result = $this->client->getHttpClient()->get($this->pagination[$key]);

$this->postFetch();
$this->postFetch(true);

return ResponseMediator::getContent($result);
}

private function setPagination(): void
{
$this->pagination = ResponseMediator::getPagination($this->client->getLastResponse());
}
}
2 changes: 2 additions & 0 deletions lib/Github/ResultPagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function fetchAllLazy(AbstractApi $api, string $method, array $parameters
/**
* Method that performs the actual work to refresh the pagination property.
*
* @deprecated since 3.2 and will be removed in 4.0.
*
* @return void
*/
public function postFetch(): void;
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
<directory suffix=".php">./lib/Github/</directory>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
17 changes: 17 additions & 0 deletions test/Github/Tests/ResultPagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use GuzzleHttp\Psr7\Utils;
use Http\Client\HttpClient;
use Psr\Http\Client\ClientInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;

/**
* @author Ramon de la Fuente <ramon@future500.nl>
Expand All @@ -21,6 +22,8 @@
*/
class ResultPagerTest extends \PHPUnit\Framework\TestCase
{
use ExpectDeprecationTrait;

public function provideFetchCases()
{
return [
Expand Down Expand Up @@ -197,4 +200,18 @@ public function testFetchAllWithoutKeys()

$this->assertCount(9, $result);
}

/**
* @group legacy
*/
public function testPostFetchDeprecation()
{
$this->expectDeprecation('Since KnpLabs/php-github-api 3.2: The "Github\ResultPager::postFetch" method is deprecated and will be removed.');

$clientMock = $this->createMock(Client::class);
$clientMock->method('getLastResponse')->willReturn(new PaginatedResponse(3, []));

$paginator = new ResultPager($clientMock);
$paginator->postFetch();
}
}