Skip to content

Commit 2054e20

Browse files
PSR-17 and HttpMethodsClientInterface
1 parent 1e30efd commit 2054e20

File tree

7 files changed

+52
-56
lines changed

7 files changed

+52
-56
lines changed

README.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,29 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4]
2020
## Requirements
2121

2222
* PHP >= 7.1
23-
* A [HTTP client](https://packagist.org/providers/psr/http-client-implementation)
24-
* A [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation)
25-
* (optional) PHPUnit to run tests.
23+
* A [PSR-17 implementation](https://packagist.org/providers/psr/http-factory-implementation)
24+
* A [PSR-18 implementation](https://packagist.org/providers/psr/http-client-implementation)
2625

2726
## Install
2827

2928
Via [Composer](https://getcomposer.org).
3029

31-
### PHP 7.2+:
30+
### PHP 7.1+:
3231

3332
```bash
34-
composer require knplabs/github-api guzzlehttp/guzzle:^7.0.1
33+
composer require knplabs/github-api:^3.0 php-http/guzzle6-adapter:^2.0.1 http-interop/http-factory-guzzle:^1.0
3534
```
3635

37-
### PHP 7.1+:
36+
### PHP 7.2+:
3837

3938
```bash
40-
composer require knplabs/github-api php-http/guzzle6-adapter:^2.0.1
39+
composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
4140
```
4241

43-
### Laravel 5.5+:
42+
### Laravel 6+:
4443

4544
```bash
46-
composer require graham-campbell/github guzzlehttp/guzzle:^7.0.1
45+
composer require graham-campbell/github^10.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
4746
```
4847

4948
We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io). Read about clients in our [docs](doc/customize.md). [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub) is by [Graham Campbell](https://github.com/GrahamCampbell).

composer.json

+13-10
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,33 @@
1818
],
1919
"require": {
2020
"php": "^7.1",
21-
"php-http/client-common": "^2.1",
21+
"php-http/client-common": "^2.2",
2222
"php-http/cache-plugin": "^1.7",
23-
"php-http/discovery": "^1.7",
23+
"php-http/discovery": "^1.9",
2424
"php-http/httplug": "^2.1",
25+
"php-http/multipart-stream-builder": "^1.1",
2526
"psr/cache": "^1.0",
2627
"psr/http-client-implementation": "^1.0",
28+
"psr/http-factory-implementation": "^1.0",
2729
"psr/http-message": "^1.0"
2830
},
2931
"require-dev": {
30-
"phpunit/phpunit": "^7.0 || ^8.0",
31-
"php-http/guzzle6-adapter": "^2.0",
32-
"php-http/mock-client": "^1.2",
33-
"guzzlehttp/psr7": "^1.2",
34-
"cache/array-adapter": "^0.4",
35-
"phpstan/phpstan": "^0.12.23"
32+
"cache/array-adapter": "^1.0.1",
33+
"guzzlehttp/psr7": "^1.5.2",
34+
"http-interop/http-factory-guzzle": "^1.0",
35+
"php-http/guzzle6-adapter": "^2.0.1",
36+
"php-http/mock-client": "^1.4",
37+
"phpstan/phpstan": "^0.12.32",
38+
"phpstan/extension-installer": "^1.0.4",
39+
"phpstan/phpstan-deprecation-rules": "^0.12.4",
40+
"phpunit/phpunit": "^7.5.15 || ^8.4 || ^9.0"
3641
},
3742
"autoload": {
3843
"psr-4": { "Github\\": "lib/Github/" }
3944
},
4045
"autoload-dev": {
4146
"psr-4": { "Github\\Tests\\": "test/Github/Tests/"}
4247
},
43-
"minimum-stability": "dev",
44-
"prefer-stable": true,
4548
"extra": {
4649
"branch-alias": {
4750
"dev-master": "3.0.x-dev"

lib/Github/Client.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
use Github\HttpClient\Plugin\GithubExceptionThrower;
1111
use Github\HttpClient\Plugin\History;
1212
use Github\HttpClient\Plugin\PathPrepend;
13-
use Http\Client\Common\HttpMethodsClient;
13+
use Http\Client\Common\HttpMethodsClientInterface;
1414
use Http\Client\Common\Plugin;
15-
use Http\Discovery\UriFactoryDiscovery;
15+
use Http\Discovery\Psr17FactoryDiscovery;
1616
use Psr\Cache\CacheItemPoolInterface;
1717
use Psr\Http\Client\ClientInterface;
1818

@@ -116,12 +116,12 @@ class Client
116116
public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null)
117117
{
118118
$this->responseHistory = new History();
119-
$this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder();
119+
$this->httpClientBuilder = $builder = $httpClientBuilder ?? new Builder();
120120

121121
$builder->addPlugin(new GithubExceptionThrower());
122122
$builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory));
123123
$builder->addPlugin(new Plugin\RedirectPlugin());
124-
$builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com')));
124+
$builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUrlFactory()->createUri('https://api.github.com')));
125125
$builder->addPlugin(new Plugin\HeaderDefaultsPlugin([
126126
'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)',
127127
]));
@@ -331,7 +331,7 @@ private function setEnterpriseUrl($enterpriseUrl)
331331
$builder->removePlugin(Plugin\AddHostPlugin::class);
332332
$builder->removePlugin(PathPrepend::class);
333333

334-
$builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl)));
334+
$builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUrlFactory()->createUri($enterpriseUrl)));
335335
$builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion())));
336336
}
337337

@@ -390,7 +390,7 @@ public function getLastResponse()
390390
}
391391

392392
/**
393-
* @return HttpMethodsClient
393+
* @return HttpMethodsClientInterface
394394
*/
395395
public function getHttpClient()
396396
{

lib/Github/HttpClient/Builder.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
namespace Github\HttpClient;
44

55
use Http\Client\Common\HttpMethodsClient;
6+
use Http\Client\Common\HttpMethodsClientInterface;
67
use Http\Client\Common\Plugin;
78
use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator;
89
use Http\Client\Common\PluginClientFactory;
9-
use Http\Discovery\MessageFactoryDiscovery;
10+
use Http\Discovery\Psr17FactoryDiscovery;
1011
use Http\Discovery\Psr18ClientDiscovery;
11-
use Http\Discovery\StreamFactoryDiscovery;
12-
use Http\Message\RequestFactory;
13-
use Http\Message\StreamFactory;
1412
use Psr\Cache\CacheItemPoolInterface;
1513
use Psr\Http\Client\ClientInterface;
14+
use Psr\Http\Message\RequestFactoryInterface;
15+
use Psr\Http\Message\StreamFactoryInterface;
1616

1717
/**
1818
* A builder that builds the API client.
@@ -32,17 +32,17 @@ class Builder
3232
/**
3333
* A HTTP client with all our plugins.
3434
*
35-
* @var HttpMethodsClient
35+
* @var HttpMethodsClientInterface
3636
*/
3737
private $pluginClient;
3838

3939
/**
40-
* @var RequestFactory
40+
* @var RequestFactoryInterface
4141
*/
4242
private $requestFactory;
4343

4444
/**
45-
* @var StreamFactory
45+
* @var StreamFactoryInterface
4646
*/
4747
private $streamFactory;
4848

@@ -73,22 +73,22 @@ class Builder
7373
private $headers = [];
7474

7575
/**
76-
* @param ClientInterface $httpClient
77-
* @param RequestFactory $requestFactory
78-
* @param StreamFactory $streamFactory
76+
* @param ClientInterface|null $httpClient
77+
* @param RequestFactoryInterface|null $requestFactory
78+
* @param StreamFactoryInterface|null $streamFactory
7979
*/
8080
public function __construct(
8181
ClientInterface $httpClient = null,
82-
RequestFactory $requestFactory = null,
83-
StreamFactory $streamFactory = null
82+
RequestFactoryInterface $requestFactory = null,
83+
StreamFactoryInterface $streamFactory = null
8484
) {
85-
$this->httpClient = $httpClient ?: Psr18ClientDiscovery::find();
86-
$this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find();
87-
$this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find();
85+
$this->httpClient = $httpClient ?? Psr18ClientDiscovery::find();
86+
$this->requestFactory = $requestFactory ?? Psr17FactoryDiscovery::findRequestFactory();
87+
$this->streamFactory = $streamFactory ?? Psr17FactoryDiscovery::findStreamFactory();
8888
}
8989

9090
/**
91-
* @return HttpMethodsClient
91+
* @return HttpMethodsClientInterface
9292
*/
9393
public function getHttpClient()
9494
{

test/Github/Tests/Api/AbstractApiTest.php

+3-10
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,12 @@ protected function getClientMock()
209209
*
210210
* @param array $methods
211211
*
212-
* @return \Http\Client\Common\HttpMethodsClient
212+
* @return \Http\Client\Common\HttpMethodsClientInterface
213213
*/
214214
protected function getHttpMethodsMock(array $methods = [])
215215
{
216-
if (interface_exists(HttpMethodsClientInterface::class)) {
217-
$mock = $this->createMock(HttpMethodsClientInterface::class);
218-
} else {
219-
$methods = array_merge(['sendRequest'], $methods);
220-
$mock = $this->getMockBuilder(\Http\Client\Common\HttpMethodsClient::class)
221-
->disableOriginalConstructor()
222-
->setMethods($methods)
223-
->getMock();
224-
}
216+
$mock = $this->createMock(HttpMethodsClientInterface::class);
217+
225218
$mock
226219
->expects($this->any())
227220
->method('sendRequest');

test/Github/Tests/Api/RateLimitTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ class RateLimitTest extends TestCase
3737
protected $api;
3838

3939
/**
40-
* Used to construct common expectations for the API input data in each unit test.
41-
*
42-
* {@inheritdoc}
40+
* @before
4341
*/
44-
protected function setUp(): void
42+
public function initMocks()
4543
{
4644
$this->api = $this->getApiMock();
4745
$this->api->expects($this->once())

test/Github/Tests/Integration/TestCase.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ class TestCase extends \PHPUnit\Framework\TestCase
1616
*/
1717
protected $client;
1818

19-
public function setUp(): void
19+
/**
20+
* @before
21+
*/
22+
public function initClient()
2023
{
2124
// You have to specify authentication here to run full suite
2225
$client = new Client();

0 commit comments

Comments
 (0)