Skip to content

Commit 43c7910

Browse files
authored
Merge pull request #134 from php-http/2.x
2.x to become the new master
2 parents 9c21b60 + 414cde1 commit 43c7910

File tree

96 files changed

+1541
-1279
lines changed

Some content is hidden

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

96 files changed

+1541
-1279
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/.php_cs
2+
/.php_cs.cache
13
/behat.yml
24
/build/
35
/composer.lock

.php_cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

.php_cs.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* Configuration for fabpot/php-cs-fixer
5+
*
6+
* @link https://github.com/FriendsOfPHP/PHP-CS-Fixer
7+
*/
8+
9+
$finder = PhpCsFixer\Finder::create()
10+
->in('src')
11+
->in('spec')
12+
;
13+
return PhpCsFixer\Config::create()
14+
->setRules([
15+
'@PSR2' => true,
16+
'@Symfony' => true,
17+
'array_syntax' => [
18+
'syntax' => 'short',
19+
],
20+
'no_empty_phpdoc' => true,
21+
'no_superfluous_phpdoc_tags' => true,
22+
])
23+
->setFinder($finder);

.styleci.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

.travis.yml

Lines changed: 42 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,55 @@
11
language: php
2-
32
sudo: false
43

5-
dist: trusty
6-
74
cache:
8-
directories:
9-
- $HOME/.composer/cache/files
5+
directories:
6+
- $HOME/.composer/cache/files
107

11-
env:
12-
global:
13-
- TEST_COMMAND="composer test"
14-
15-
branches:
16-
except:
17-
- /^analysis-.*$/
8+
php:
9+
- 7.0
10+
- 7.1
11+
- 7.2
12+
- 7.3
1813

1914
matrix:
20-
fast_finish: true
21-
include:
22-
- php: 7.1
23-
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" DEPENDENCIES="doctrine/instantiator:^1.1"
24-
25-
# Test the latest stable release
26-
- php: 5.4
27-
- php: 5.5
28-
- php: 5.6
29-
- php: 7.0
30-
- php: 7.1
31-
- php: 7.2
32-
env: COVERAGE=true TEST_COMMAND="composer test-ci" DEPENDENCIES="henrikbjorn/phpspec-code-coverage:^1.0"
15+
fast_finish: true
16+
17+
jobs:
18+
include:
19+
- php: 7.0
20+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
21+
- php: 7.2
22+
env: COVERAGE=true DEPENDENCIES="leanphp/phpspec-code-coverage"
23+
script:
24+
- composer test-ci
25+
after_success:
26+
- wget https://scrutinizer-ci.com/ocular.phar
27+
- php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml --revision=$TRAVIS_COMMIT
28+
# Test LTS versions
29+
- php: 7.2
30+
env: DEPENDENCIES="dunglas/symfony-lock:^2"
31+
- php: 7.2
32+
env: DEPENDENCIES="dunglas/symfony-lock:^3"
33+
- php: 7.2
34+
env: DEPENDENCIES="dunglas/symfony-lock:^4"
35+
- php: 7.2
36+
env: TEST_COMMAND="./vendor/bin/phpunit" DEPENDENCIES="phpunit/phpunit:^7.5 nyholm/psr7:^1.0"
37+
38+
# Latest dev release
39+
- php: 7.3
40+
env: STABILITY="dev"
3341

34-
# Test LTS versions
35-
- php: 7.1
36-
env: DEPENDENCIES="dunglas/symfony-lock:^2"
37-
- php: 7.1
38-
env: DEPENDENCIES="dunglas/symfony-lock:^3"
39-
- php: 7.1
40-
env: DEPENDENCIES="dunglas/symfony-lock:^4" STABILITY="rc"
41-
42-
# Latest dev release
43-
- php: 7.1
44-
env: STABILITY="dev"
45-
46-
allow_failures:
47-
# Latest dev is allowed to fail.
48-
- env: STABILITY="dev"
49-
5042
before_install:
51-
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
52-
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
53-
- if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
43+
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
44+
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
45+
- if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
5446

5547
install:
56-
- cat composer.json
57-
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
58-
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
59-
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
48+
- cat composer.json
49+
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
50+
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
51+
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
6052

6153
script:
62-
- composer validate --strict --no-check-lock
63-
- $TEST_COMMAND
64-
65-
after_success:
66-
- if [[ $COVERAGE = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
67-
- if [[ $COVERAGE = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi
54+
- composer validate --strict --no-check-lock
55+
- composer test

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Change Log
22

3+
## 2.0 (unreleased)
4+
5+
### Changed
6+
- RetryPlugin will no longer retry requests when the response failed with a HTTP code < 500.
7+
- Abstract method `HttpClientPool::chooseHttpClient()` has now an explicit return type (`Http\Client\Common\HttpClientPoolItem`)
8+
- Interface method `Plugin::handleRequest(...)` has now an explicit return type (`Http\Promise\Promise`)
9+
- Made classes final that are not intended to be extended.
10+
Added interfaces for BatchClient, HttpClientRouter and HttpMethodsClient.
11+
(These interfaces use the `Interface` suffix to avoid name collisions.)
12+
- Added an interface for HttpClientPool and moved the abstract class to the HttpClientPool sub namespace.
13+
- AddPathPlugin: Do not add the prefix if the URL already has the same prefix.
14+
15+
### Removed
16+
- Deprecated option `debug_plugins` has been removed from `PluginClient`
17+
318
## 1.9.0 - 2019-01-03
419

520
### Added
@@ -10,7 +25,7 @@
1025

1126
### Changed
1227

13-
- [RetryPlugin] Renamed the configuration options for the exception retry callback from `decider` to `exception_decider`
28+
- RetryPlugin: Renamed the configuration options for the exception retry callback from `decider` to `exception_decider`
1429
and `delay` to `exception_delay`. The old names still work but are deprecated.
1530

1631
## 1.8.2 - 2018-12-14

composer.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^5.4 || ^7.0",
15-
"php-http/httplug": "^1.1",
14+
"php": "^7.0",
15+
"php-http/httplug": "^2.0",
1616
"php-http/message-factory": "^1.0",
1717
"php-http/message": "^1.6",
1818
"symfony/options-resolver": "^2.6 || ^3.0 || ^4.0"
1919
},
2020
"require-dev": {
21-
"phpspec/phpspec": "^2.5 || ^3.4 || ^4.2",
22-
"guzzlehttp/psr7": "^1.4"
21+
"doctrine/instantiator": ">=1.0.5",
22+
"guzzlehttp/psr7": "^1.4",
23+
"phpspec/phpspec": "^3.4 || ^4.2",
24+
"phpspec/prophecy": ">=1.8",
25+
"sebastian/comparator": ">=2"
2326
},
2427
"suggest": {
28+
"ext-json": "To detect JSON responses with the ContentTypePlugin",
29+
"ext-libxml": "To detect XML responses with the ContentTypePlugin",
2530
"php-http/logger-plugin": "PSR-3 Logger plugin",
2631
"php-http/cache-plugin": "PSR-6 Cache plugin",
2732
"php-http/stopwatch-plugin": "Symfony Stopwatch plugin"
@@ -31,13 +36,18 @@
3136
"Http\\Client\\Common\\": "src/"
3237
}
3338
},
39+
"autoload-dev": {
40+
"psr-4": {
41+
"spec\\Http\\Client\\Common\\": "spec/"
42+
}
43+
},
3444
"scripts": {
3545
"test": "vendor/bin/phpspec run",
3646
"test-ci": "vendor/bin/phpspec run -c phpspec.ci.yml"
3747
},
3848
"extra": {
3949
"branch-alias": {
40-
"dev-master": "1.9.x-dev"
50+
"dev-master": "2.x-dev"
4151
}
4252
}
4353
}

phpspec.ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ suites:
44
psr4_prefix: Http\Client\Common
55
formatter.name: pretty
66
extensions:
7-
- PhpSpec\Extension\CodeCoverageExtension
7+
LeanPHP\PhpSpec\CodeCoverage\CodeCoverageExtension: ~
88
code_coverage:
99
format: clover
1010
output: build/coverage.xml

phpunit.xml.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit bootstrap="./vendor/autoload.php"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true">
8+
9+
<testsuites>
10+
<testsuite name="HTTPlug unit tests">
11+
<directory suffix="Test.php">./tests</directory>
12+
</testsuite>
13+
</testsuites>
14+
</phpunit>

spec/BatchClientSpec.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,31 @@
66
use Psr\Http\Message\RequestInterface;
77
use Psr\Http\Message\ResponseInterface;
88
use PhpSpec\ObjectBehavior;
9+
use Http\Client\Common\BatchClient;
10+
use Http\Client\Common\BatchResult;
11+
use Http\Client\Exception\HttpException;
12+
use Http\Client\Common\Exception\BatchException;
913

1014
class BatchClientSpec extends ObjectBehavior
1115
{
12-
function let(HttpClient $client)
16+
public function let(HttpClient $client)
1317
{
14-
$this->beAnInstanceOf('Http\Client\Common\BatchClient', [$client]);
18+
$this->beAnInstanceOf(BatchClient::class, [$client]);
1519
}
1620

17-
function it_send_multiple_request_using_send_request(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response1, ResponseInterface $response2)
21+
public function it_send_multiple_request_using_send_request(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response1, ResponseInterface $response2)
1822
{
1923
$client->sendRequest($request1)->willReturn($response1);
2024
$client->sendRequest($request2)->willReturn($response2);
2125

22-
$this->sendRequests([$request1, $request2])->shouldReturnAnInstanceOf('Http\Client\Common\BatchResult');
26+
$this->sendRequests([$request1, $request2])->shouldReturnAnInstanceOf(BatchResult::class);
2327
}
2428

25-
function it_throw_batch_exception_if_one_or_more_request_failed(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response)
29+
public function it_throw_batch_exception_if_one_or_more_request_failed(HttpClient $client, RequestInterface $request1, RequestInterface $request2, ResponseInterface $response)
2630
{
2731
$client->sendRequest($request1)->willReturn($response);
28-
$client->sendRequest($request2)->willThrow('Http\Client\Exception\HttpException');
32+
$client->sendRequest($request2)->willThrow(HttpException::class);
2933

30-
$this->shouldThrow('Http\Client\Common\Exception\BatchException')->duringSendRequests([$request1, $request2]);
34+
$this->shouldThrow(BatchException::class)->duringSendRequests([$request1, $request2]);
3135
}
3236
}

spec/BatchResultSpec.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66
use Psr\Http\Message\RequestInterface;
77
use Psr\Http\Message\ResponseInterface;
88
use PhpSpec\ObjectBehavior;
9+
use Http\Client\Common\BatchResult;
910

1011
class BatchResultSpec extends ObjectBehavior
1112
{
12-
function it_is_initializable()
13+
public function it_is_initializable()
1314
{
14-
$this->beAnInstanceOf('Http\Client\Common\BatchResult');
15+
$this->beAnInstanceOf(BatchResult::class);
1516
}
1617

17-
function it_is_immutable(RequestInterface $request, ResponseInterface $response)
18+
public function it_is_immutable(RequestInterface $request, ResponseInterface $response)
1819
{
1920
$new = $this->addResponse($request, $response);
2021

2122
$this->getResponses()->shouldReturn([]);
22-
$new->shouldHaveType('Http\Client\Common\BatchResult');
23+
$new->shouldHaveType(BatchResult::class);
2324
$new->getResponses()->shouldReturn([$response]);
2425
}
2526

26-
function it_has_a_responses(RequestInterface $request, ResponseInterface $response)
27+
public function it_has_a_responses(RequestInterface $request, ResponseInterface $response)
2728
{
2829
$new = $this->addResponse($request, $response);
2930

@@ -33,17 +34,17 @@ function it_has_a_responses(RequestInterface $request, ResponseInterface $respon
3334
$new->getResponses()->shouldReturn([$response]);
3435
}
3536

36-
function it_has_a_response_for_a_request(RequestInterface $request, ResponseInterface $response)
37+
public function it_has_a_response_for_a_request(RequestInterface $request, ResponseInterface $response)
3738
{
3839
$new = $this->addResponse($request, $response);
3940

40-
$this->shouldThrow('UnexpectedValueException')->duringGetResponseFor($request);
41+
$this->shouldThrow(\UnexpectedValueException::class)->duringGetResponseFor($request);
4142
$this->isSuccessful($request)->shouldReturn(false);
4243
$new->getResponseFor($request)->shouldReturn($response);
4344
$new->isSuccessful($request)->shouldReturn(true);
4445
}
4546

46-
function it_keeps_exception_after_add_request(RequestInterface $request1, Exception $exception, RequestInterface $request2, ResponseInterface $response)
47+
public function it_keeps_exception_after_add_request(RequestInterface $request1, Exception $exception, RequestInterface $request2, ResponseInterface $response)
4748
{
4849
$new = $this->addException($request1, $exception);
4950
$new = $new->addResponse($request2, $response);

0 commit comments

Comments
 (0)