Skip to content

Commit 8bda6ea

Browse files
authored
Merge pull request #11 from GrahamCampbell/php8
Support PHP 7.1-8.0
2 parents c1c6e90 + 1de6dce commit 8bda6ea

File tree

7 files changed

+106
-60
lines changed

7 files changed

+106
-60
lines changed

.gitattributes

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
.php_cs export-ignore
66
.scrutinizer.yml export-ignore
77
.styleci.yml export-ignore
8-
.travis.yml export-ignore
98
phpspec.yml.ci export-ignore
109
phpspec.yml.dist export-ignore
11-
phpunit.xml.dist export-ignore
1210
spec/ export-ignore
13-
tests/ export-ignore

.github/workflows/tests.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
latest:
9+
name: PHP ${{ matrix.php }} Latest
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Setup PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php }}
23+
tools: composer:v2
24+
coverage: none
25+
26+
- name: Install PHP 7 dependencies
27+
run: composer update --prefer-dist --no-interaction --no-progress
28+
if: "matrix.php != '8.0'"
29+
30+
- name: Install PHP 8 dependencies
31+
run: |
32+
composer require "phpdocumentor/reflection-docblock:^5.2@dev" --no-interaction --no-update
33+
composer update --prefer-dist --prefer-stable --no-interaction --no-progress --ignore-platform-req=php
34+
if: "matrix.php == '8.0'"
35+
36+
- name: Execute tests
37+
run: composer test
38+
39+
lowest:
40+
name: PHP ${{ matrix.php }} Lowest
41+
runs-on: ubuntu-latest
42+
strategy:
43+
matrix:
44+
php: ['7.1', '7.2', '7.3', '7.4']
45+
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v2
49+
50+
- name: Setup PHP
51+
uses: shivammathur/setup-php@v2
52+
with:
53+
php-version: ${{ matrix.php }}
54+
tools: composer:v2
55+
coverage: none
56+
57+
- name: Install dependencies
58+
run: |
59+
composer require "sebastian/comparator:^3.0.2" --no-interaction --no-update
60+
composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress
61+
62+
- name: Execute tests
63+
run: composer test
64+
65+
coverage:
66+
name: Code Coverage
67+
runs-on: ubuntu-latest
68+
69+
steps:
70+
- name: Checkout code
71+
uses: actions/checkout@v2
72+
73+
- name: Setup PHP
74+
uses: shivammathur/setup-php@v2
75+
with:
76+
php-version: 7.4
77+
tools: composer:v2
78+
coverage: xdebug
79+
80+
- name: Install dependencies
81+
run: |
82+
composer require "friends-of-phpspec/phpspec-code-coverage:^4.3.2" --no-interaction --no-update
83+
composer update --prefer-dist --no-interaction --no-progress
84+
85+
- name: Execute tests
86+
run: composer test-ci
87+
88+
- name: Upload coverage
89+
run: |
90+
wget https://scrutinizer-ci.com/ocular.phar
91+
php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml

.travis.yml

-42
This file was deleted.

composer.json

+6-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^5.4 || ^7.0",
14+
"php": "^7.1 || ^7.0",
1515
"psr/log": "^1.0",
1616
"php-http/client-common": "^1.9 || ^2.0",
17-
"php-http/message": "^1.0"
17+
"php-http/message": "^1.0",
18+
"symfony/polyfill-php73": "^1.17"
1819
},
1920
"require-dev": {
20-
"phpspec/phpspec": "^2.5",
21-
"henrikbjorn/phpspec-code-coverage" : "^1.0"
21+
"phpspec/phpspec": "^5.1 || ^6.0"
2222
},
2323
"autoload": {
2424
"psr-4": {
@@ -31,9 +31,7 @@
3131
},
3232
"extra": {
3333
"branch-alias": {
34-
"dev-master": "1.1-dev"
34+
"dev-master": "1.2-dev"
3535
}
36-
},
37-
"prefer-stable": true,
38-
"minimum-stability": "dev"
36+
}
3937
}

phpspec.yml.ci

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

spec/LoggerPluginSpec.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace spec\Http\Client\Common\Plugin;
44

5+
use Http\Client\Common\Plugin;
6+
use Http\Client\Common\Plugin\LoggerPlugin;
57
use Http\Client\Exception\HttpException;
68
use Http\Client\Exception\NetworkException;
79
use Http\Promise\FulfilledPromise;
@@ -23,12 +25,12 @@ function let(LoggerInterface $logger, Formatter $formatter)
2325

2426
function it_is_initializable()
2527
{
26-
$this->shouldHaveType('Http\Client\Common\Plugin\LoggerPlugin');
28+
$this->shouldHaveType(LoggerPlugin::class);
2729
}
2830

2931
function it_is_a_plugin()
3032
{
31-
$this->shouldImplement('Http\Client\Common\Plugin');
33+
$this->shouldImplement(Plugin::class);
3234
}
3335

3436
function it_logs_request_and_response(
@@ -106,7 +108,7 @@ function(array $context) use ($request, $response, $exception) {
106108
&& $context['response'] === $response->getWrappedObject()
107109
&& $context['exception'] === $exception
108110
&& is_int($context['milliseconds'])
109-
;
111+
;
110112
}
111113
)
112114
)->shouldBeCalled();

src/LoggerPlugin.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public function __construct(LoggerInterface $logger, Formatter $formatter = null
3131

3232
protected function doHandleRequest(RequestInterface $request, callable $next, callable $first)
3333
{
34-
$start = microtime(true);
34+
$start = hrtime(true) / 1E6;
3535
$this->logger->info(sprintf("Sending request:\n%s", $this->formatter->formatRequest($request)), ['request' => $request]);
3636

3737
return $next($request)->then(function (ResponseInterface $response) use ($request, $start) {
38-
$milliseconds = (int) round((microtime(true) - $start) * 1000);
38+
$milliseconds = (int) round(hrtime(true) / 1E6 - $start);
3939
$this->logger->info(
4040
sprintf("Received response:\n%s\n\nfor request:\n%s", $this->formatter->formatResponse($response), $this->formatter->formatRequest($request)),
4141
[
@@ -47,7 +47,7 @@ protected function doHandleRequest(RequestInterface $request, callable $next, ca
4747

4848
return $response;
4949
}, function (Exception $exception) use ($request, $start) {
50-
$milliseconds = (int) round((microtime(true) - $start) * 1000);
50+
$milliseconds = (int) round((hrtime(true) / 1E6 - $start));
5151
if ($exception instanceof Exception\HttpException) {
5252
$this->logger->error(
5353
sprintf("Error:\n%s\nwith response:\n%s\n\nwhen sending request:\n%s", $exception->getMessage(), $this->formatter->formatResponse($exception->getResponse()), $this->formatter->formatRequest($request)),

0 commit comments

Comments
 (0)