Skip to content

Commit dcb28fa

Browse files
authored
full support to PHP 8.0 + add support for CurlHandle resource objects (#71)
1 parent f0cb980 commit dcb28fa

File tree

7 files changed

+136
-67
lines changed

7 files changed

+136
-67
lines changed

Diff for: .github/workflows/Build-Test.yml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
# Run this workflow every time a new commit pushed to your repository
3+
on:
4+
push:
5+
6+
jobs:
7+
tests:
8+
if: "! contains(toJSON(github.event.commits.*.msg), 'skip') && ! contains(toJSON(github.event.commits.*.msg), 'ci')" #skip ci...
9+
runs-on: ${{ matrix.operating-system }}
10+
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
operating-system: [ubuntu-20.04]
15+
php-versions: ['7.2', '7.3', '7.4', '8.0']
16+
include:
17+
- operating-system: ubuntu-16.04
18+
php-versions: '7.1'
19+
COMPOSER_FLAGS: '--prefer-stable --prefer-lowest'
20+
COVERAGE: 'true'
21+
PHPUNIT_FLAGS: '--coverage-clover build/coverage.xml'
22+
23+
name: PHP ${{ matrix.php-versions }} - ${{ matrix.operating-system }}
24+
25+
env:
26+
extensions: curl json libxml dom
27+
key: cache-v1 # can be any string, change to clear the extension cache.
28+
29+
steps:
30+
# Checks out a copy of your repository on the ubuntu machine
31+
- name: Checkout code
32+
uses: actions/checkout@v2
33+
34+
- name: Setup cache environment
35+
id: extcache
36+
uses: shivammathur/cache-extensions@v1
37+
with:
38+
php-version: ${{ matrix.php-versions }}
39+
extensions: ${{ env.extensions }}
40+
key: ${{ env.key }}
41+
42+
- name: Cache PHP Extensions
43+
uses: actions/cache@v2
44+
with:
45+
path: ${{ steps.extcache.outputs.dir }}
46+
key: ${{ steps.extcache.outputs.key }}
47+
restore-keys: ${{ steps.extcache.outputs.key }}
48+
49+
- name: Cache Composer Dependencies
50+
uses: actions/cache@v1
51+
with:
52+
path: ~/.composer/cache/files
53+
key: dependencies-composer-${{ hashFiles('composer.json') }}
54+
55+
- name: Setup PHP Action
56+
uses: shivammathur/[email protected]
57+
with:
58+
php-version: ${{ matrix.php-versions }}
59+
extensions: ${{ env.extensions }}
60+
coverage: xdebug
61+
tools: pecl, composer
62+
63+
- name: Get composer cache directory
64+
id: composer-cache
65+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
66+
67+
- name: Cache dependencies
68+
uses: actions/cache@v2
69+
with:
70+
path: ${{ steps.composer-cache.outputs.dir }}
71+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
72+
restore-keys: ${{ runner.os }}-composer-
73+
74+
- name: Composer self update
75+
run: composer self-update
76+
77+
- name: Install Composer dependencies
78+
run: composer update ${{ matrix.COMPOSER_FLAGS }} --prefer-source --no-interaction
79+
80+
- name: boot test server
81+
run: vendor/bin/http_test_server > /dev/null 2>&1 &
82+
83+
- name: Apply tests
84+
run: composer test
85+
86+
- name: Apply coverage
87+
if: ${{ matrix.COVERAGE == 'true' }}
88+
run: |
89+
wget https://scrutinizer-ci.com/ocular.phar
90+
php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml

Diff for: .travis.yml

-38
This file was deleted.

Diff for: composer.json

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
"psr-18"
99
],
1010
"homepage": "http://php-http.org",
11-
"authors": [
12-
{
13-
"name": "Михаил Красильников",
14-
"email": "[email protected]"
15-
}
16-
],
11+
"authors": [{
12+
"name": "Михаил Красильников",
13+
"email": "[email protected]"
14+
}],
1715
"prefer-stable": true,
1816
"minimum-stability": "dev",
1917
"require": {
20-
"php": "^7.1",
18+
"php": "^7.1 || ^8.0",
2119
"ext-curl": "*",
2220
"php-http/discovery": "^1.6",
2321
"php-http/httplug": "^2.0",
@@ -28,8 +26,8 @@
2826
},
2927
"require-dev": {
3028
"guzzlehttp/psr7": "^1.0",
31-
"php-http/client-integration-tests": "^2.0",
32-
"phpunit/phpunit": "^7.5",
29+
"php-http/client-integration-tests": "^3.0",
30+
"phpunit/phpunit": "^7.5 || ^9.4",
3331
"laminas/laminas-diactoros": "^2.0"
3432
},
3533
"autoload": {
@@ -56,4 +54,4 @@
5654
"dev-master": "2.x-dev"
5755
}
5856
}
59-
}
57+
}

Diff for: src/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Client implements HttpClient, HttpAsyncClient
5353
/**
5454
* cURL synchronous requests handle.
5555
*
56-
* @var resource|null
56+
* @var resource|\CurlHandle|null
5757
*/
5858
private $handle;
5959

Diff for: src/PromiseCore.php

+23-14
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ class PromiseCore
6969
/**
7070
* Create shared core.
7171
*
72-
* @param RequestInterface $request HTTP request.
73-
* @param resource $handle cURL handle.
74-
* @param ResponseBuilder $responseBuilder Response builder.
72+
* @param RequestInterface $request HTTP request.
73+
* @param resource|\CurlHandle $handle cURL handle.
74+
* @param ResponseBuilder $responseBuilder Response builder.
7575
*
7676
* @throws \InvalidArgumentException If $handle is not a cURL resource.
7777
*/
@@ -80,20 +80,29 @@ public function __construct(
8080
$handle,
8181
ResponseBuilder $responseBuilder
8282
) {
83-
if (!is_resource($handle)) {
84-
throw new \InvalidArgumentException(
85-
sprintf(
86-
'Parameter $handle expected to be a cURL resource, %s given',
87-
gettype($handle)
88-
)
89-
);
83+
if (PHP_MAJOR_VERSION === 7) {
84+
if (!is_resource($handle)) {
85+
throw new \InvalidArgumentException(
86+
sprintf(
87+
'Parameter $handle expected to be a cURL resource, %s given',
88+
gettype($handle)
89+
)
90+
);
91+
} elseif (get_resource_type($handle) !== 'curl') {
92+
throw new \InvalidArgumentException(
93+
sprintf(
94+
'Parameter $handle expected to be a cURL resource, %s resource given',
95+
get_resource_type($handle)
96+
)
97+
);
98+
}
9099
}
91100

92-
if (get_resource_type($handle) !== 'curl') {
101+
if (PHP_MAJOR_VERSION > 7 && !$handle instanceof \CurlHandle) {
93102
throw new \InvalidArgumentException(
94103
sprintf(
95-
'Parameter $handle expected to be a cURL resource, %s resource given',
96-
get_resource_type($handle)
104+
'Parameter $handle expected to be a cURL resource, %s given',
105+
get_debug_type($handle)
97106
)
98107
);
99108
}
@@ -138,7 +147,7 @@ public function addOnRejected(callable $callback): void
138147
/**
139148
* Return cURL handle.
140149
*
141-
* @return resource
150+
* @return resource|\CurlHandle
142151
*/
143152
public function getHandle()
144153
{

Diff for: tests/Functional/HttpClientDiactorosTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Http\Client\Curl\Tests\Functional;
66

7+
78
use Http\Client\Curl\Client;
9+
use Psr\Http\Client\ClientInterface;
810
use Http\Client\HttpClient;
911
use Psr\Http\Message\StreamInterface;
1012
use Laminas\Diactoros\ResponseFactory;
@@ -21,7 +23,7 @@ protected function createFileStream(string $filename): StreamInterface
2123
return new Stream($filename);
2224
}
2325

24-
protected function createHttpAdapter(): HttpClient
26+
protected function createHttpAdapter(): ClientInterface
2527
{
2628
return new Client(new ResponseFactory(), new StreamFactory());
2729
}

Diff for: tests/Unit/PromiseCoreTest.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ public function testHandleIsNotACurlResource(): void
3636
$responseBuilder = $this->createMock(ResponseBuilder::class);
3737

3838
$this->expectException(\InvalidArgumentException::class);
39-
$this->expectExceptionMessage('Parameter $handle expected to be a cURL resource, stream resource given');
39+
if (PHP_MAJOR_VERSION > 7) {
40+
$this->expectExceptionMessage('Parameter $handle expected to be a cURL resource, resource (stream) given');
41+
} else {
42+
$this->expectExceptionMessage('Parameter $handle expected to be a cURL resource, stream resource given');
43+
}
4044

4145
new PromiseCore($request, fopen('php://memory', 'r+b'), $responseBuilder);
4246
}
@@ -50,7 +54,11 @@ public function testHandleIsNotAResource(): void
5054
$responseBuilder = $this->createMock(ResponseBuilder::class);
5155

5256
$this->expectException(\InvalidArgumentException::class);
53-
$this->expectExceptionMessage('Parameter $handle expected to be a cURL resource, NULL given');
57+
if (PHP_MAJOR_VERSION > 7) {
58+
$this->expectExceptionMessage('Parameter $handle expected to be a cURL resource, null given');
59+
} else {
60+
$this->expectExceptionMessage('Parameter $handle expected to be a cURL resource, NULL given');
61+
}
5462

5563
new PromiseCore($request, null, $responseBuilder);
5664
}
@@ -152,7 +160,7 @@ function (RequestException $exception) {
152160
self::assertEquals('Bar', $core->getException()->getMessage());
153161
}
154162

155-
protected function tearDown()
163+
protected function tearDown(): void
156164
{
157165
if (is_resource($this->handle)) {
158166
curl_close($this->handle);

0 commit comments

Comments
 (0)