Skip to content

Commit e0f19f7

Browse files
committed
Abstract the HTTP Client by using HTTPlug
1 parent 4176d3e commit e0f19f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+234
-54
lines changed

README.md

Lines changed: 17 additions & 42 deletions

composer.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,25 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=5.3.2",
21-
"ext-curl": "*",
22-
"guzzle/guzzle": "~3.7"
20+
"php": ">=5.4",
21+
"php-http/httplug": "1.0.0-RC1",
22+
"php-http/promise": "1.0.0-RC1",
23+
"zendframework/zend-diactoros": "^1.3"
2324
},
2425
"require-dev": {
2526
"phpunit/phpunit": "~4.0",
26-
"sllh/php-cs-fixer-styleci-bridge": "~1.3"
27+
"phpspec/phpspec": "^2.4",
28+
"php-http/guzzle6-adapter": "^0.4.1"
2729
},
2830
"suggest": {
2931
"knplabs/gaufrette": "Needed for optional Gaufrette cache"
3032
},
3133
"autoload": {
32-
"psr-4": { "Github\\": "lib/Github/" }
34+
"psr-4": { "Github\\": "src/Github/" }
3335
},
3436
"extra": {
3537
"branch-alias": {
36-
"dev-master": "1.5.x-dev"
38+
"dev-master": "2.0.x-dev"
3739
}
3840
}
3941
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace spec\Github\HttpClient;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use Psr\Http\Message\RequestInterface;
8+
use Psr\Http\Message\ResponseInterface;
9+
use Http\Client\HttpClient;
10+
use Github\Factory\RequestFactory;
11+
12+
class HttplugClientSpec extends ObjectBehavior
13+
{
14+
function let(HttpClient $adapter, RequestFactory $factory)
15+
{
16+
$this->beConstructedWith($adapter, $factory);
17+
}
18+
19+
function it_is_a_http_client()
20+
{
21+
$this->shouldBeAnInstanceOf('Github\HttpClient\HttpClientInterface');
22+
}
23+
24+
function it_sends_GET_request(
25+
RequestInterface $request,
26+
ResponseInterface $response,
27+
$adapter,
28+
$factory
29+
) {
30+
$headers = [
31+
'Accept' => 'application/vnd.github.v3+json',
32+
'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)',
33+
'X-Debug-Token' => '13fe23ab',
34+
];
35+
36+
$factory->createRequest('GET', 'https://api.github.com/endpoint?page=1', $headers)->willReturn($request);
37+
$adapter->sendRequest($request)->willReturn($response);
38+
39+
$this->get('/endpoint', ['page' => 1], ['X-Debug-Token' => '13fe23ab'])->shouldReturn($response);
40+
}
41+
42+
function it_sends_POST_request(
43+
RequestInterface $request,
44+
ResponseInterface $response,
45+
$adapter,
46+
$factory
47+
) {
48+
$headers = [
49+
'Accept' => 'application/vnd.github.v3+json',
50+
'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)',
51+
'X-Debug-Token' => '13fe23ab',
52+
];
53+
54+
$factory->createRequest('POST', 'https://api.github.com/endpoint', $headers, 'body')->willReturn($request);
55+
$adapter->sendRequest($request)->willReturn($response);
56+
57+
$this->post('/endpoint', 'body', ['X-Debug-Token' => '13fe23ab'])->shouldReturn($response);
58+
}
59+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)