Skip to content

Support PHP 7.1-8.0 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
.php_cs export-ignore
.scrutinizer.yml export-ignore
.styleci.yml export-ignore
.travis.yml export-ignore
phpspec.yml.ci export-ignore
phpspec.yml.dist export-ignore
phpunit.xml.dist export-ignore
spec/ export-ignore
tests/ export-ignore
91 changes: 91 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: tests

on:
push:
pull_request:

jobs:
latest:
name: PHP ${{ matrix.php }} Latest
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0']

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none

- name: Install PHP 7 dependencies
run: composer update --prefer-dist --no-interaction --no-progress
if: "matrix.php != '8.0'"

- name: Install PHP 8 dependencies
run: |
composer require "phpdocumentor/reflection-docblock:^5.2@dev" --no-interaction --no-update
composer update --prefer-dist --prefer-stable --no-interaction --no-progress --ignore-platform-req=php
if: "matrix.php == '8.0'"

- name: Execute tests
run: composer test

lowest:
name: PHP ${{ matrix.php }} Lowest
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4']

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer require "sebastian/comparator:^3.0.2" --no-interaction --no-update
composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress

- name: Execute tests
run: composer test

coverage:
name: Code Coverage
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2
coverage: xdebug

- name: Install dependencies
run: |
composer require "friends-of-phpspec/phpspec-code-coverage:^4.3.2" --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: composer test-ci

- name: Upload coverage
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml
42 changes: 0 additions & 42 deletions .travis.yml

This file was deleted.

14 changes: 6 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
}
],
"require": {
"php": "^5.4 || ^7.0",
"php": "^7.1 || ^7.0",
"psr/log": "^1.0",
"php-http/client-common": "^1.9 || ^2.0",
"php-http/message": "^1.0"
"php-http/message": "^1.0",
"symfony/polyfill-php73": "^1.17"
},
"require-dev": {
"phpspec/phpspec": "^2.5",
"henrikbjorn/phpspec-code-coverage" : "^1.0"
"phpspec/phpspec": "^5.1 || ^6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -31,9 +31,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
"dev-master": "1.2-dev"
}
},
"prefer-stable": true,
"minimum-stability": "dev"
}
}
2 changes: 1 addition & 1 deletion phpspec.yml.ci
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ suites:
psr4_prefix: Http\Client\Common\Plugin
formatter.name: pretty
extensions:
- PhpSpec\Extension\CodeCoverageExtension
FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension: ~
code_coverage:
format: clover
output: build/coverage.xml
8 changes: 5 additions & 3 deletions spec/LoggerPluginSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace spec\Http\Client\Common\Plugin;

use Http\Client\Common\Plugin;
use Http\Client\Common\Plugin\LoggerPlugin;
use Http\Client\Exception\HttpException;
use Http\Client\Exception\NetworkException;
use Http\Promise\FulfilledPromise;
Expand All @@ -23,12 +25,12 @@ function let(LoggerInterface $logger, Formatter $formatter)

function it_is_initializable()
{
$this->shouldHaveType('Http\Client\Common\Plugin\LoggerPlugin');
$this->shouldHaveType(LoggerPlugin::class);
}

function it_is_a_plugin()
{
$this->shouldImplement('Http\Client\Common\Plugin');
$this->shouldImplement(Plugin::class);
}

function it_logs_request_and_response(
Expand Down Expand Up @@ -106,7 +108,7 @@ function(array $context) use ($request, $response, $exception) {
&& $context['response'] === $response->getWrappedObject()
&& $context['exception'] === $exception
&& is_int($context['milliseconds'])
;
;
}
)
)->shouldBeCalled();
Expand Down
6 changes: 3 additions & 3 deletions src/LoggerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public function __construct(LoggerInterface $logger, Formatter $formatter = null

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

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

return $response;
}, function (Exception $exception) use ($request, $start) {
$milliseconds = (int) round((microtime(true) - $start) * 1000);
$milliseconds = (int) round((hrtime(true) / 1E6 - $start));
if ($exception instanceof Exception\HttpException) {
$this->logger->error(
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)),
Expand Down