Skip to content

Commit

Permalink
Update composer and tests to support php 8 (#417)
Browse files Browse the repository at this point in the history
* Update composer and tests to support php8

* fix: deactivate multi curl server push for php 8
feat: add the php 8 build to the ci config

* chore: fix build

* chore: fix build

* chore: fix build

* chore: fix build

* chore: ci changes

* Remove conflict section from composer.json

Testing if ci work without it

* Use php7.4 image for testing of http2 push

Co-authored-by: Chris Doehring <info@chrisdoehring.de>
  • Loading branch information
sunkan and chris-doehring committed Oct 22, 2020
1 parent 40d2cec commit e7468d1
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 29 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
max-parallel: 10
matrix:
php: ['7.2', '7.3', '7.4']
php: ['7.2', '7.3', '7.4', '8.0']
sf_version: ['3.4.*', '4.4.*', '5.0.*']

steps:
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@2.1.0
with:
php-version: 7.3
php-version: 7.4
tools: flex

- name: Checkout code
Expand All @@ -122,7 +122,7 @@ jobs:
- name: Run tests
run: |
docker run --rm --net buzz-bridge -v "$PWD":/usr/src/myapp -w /usr/src/myapp -e BUZZ_TEST_SERVER=http://test-server/index.php tommymuehle/docker-alpine-php-nightly php vendor/bin/phpunit
docker run --rm --net buzz-bridge -v "$PWD":/usr/src/myapp -w /usr/src/myapp -e BUZZ_TEST_SERVER=http://test-server/index.php php:7.4-cli php vendor/bin/phpunit
lowest:
name: Lowest deps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Expand Up @@ -42,6 +42,6 @@ jobs:
uses: actions/checkout@v2

- name: Psalm
uses: docker://muglug/psalm-github-actions
uses: docker://vimeo/psalm-github-actions
with:
args: --no-progress --show-info=false --stats
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,4 +1,4 @@
FROM php:7.3-fpm-stretch
FROM php:7.4-fpm-buster

# Install Nginx
RUN apt-get update -qq && apt-get install -y --no-install-recommends -qq nginx
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -18,18 +18,18 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.1 || ^8.0",
"psr/http-message": "^1.0",
"psr/http-client": "^1.0",
"php-http/httplug": "^1.1 || ^2.0",
"symfony/options-resolver": "^3.4 || ^4.0 || ^5.0",
"psr/http-factory": "^1.0"
},
"require-dev": {
"php-http/client-integration-tests": "^2.0.1",
"php-http/client-integration-tests": "^3.0",
"nyholm/psr7": "^1.0",
"psr/log": "^1.0",
"phpunit/phpunit": "7.5.20"
"phpunit/phpunit": "^7.5 || ^9.4"
},
"provide": {
"php-http/client-implementation": "1.0",
Expand Down
2 changes: 1 addition & 1 deletion lib/Client/AbstractClient.php
Expand Up @@ -13,7 +13,7 @@
abstract class AbstractClient
{
/**
* @var OptionsResolver
* @var OptionsResolver|null
*/
private $optionsResolver;

Expand Down
8 changes: 7 additions & 1 deletion lib/Client/MultiCurl.php
Expand Up @@ -56,7 +56,13 @@ public function __construct($responseFactory, array $options = [])
{
parent::__construct($responseFactory, $options);

if (\PHP_VERSION_ID < 70215 || \PHP_VERSION_ID === 70300 || \PHP_VERSION_ID === 70301 || !(CURL_VERSION_HTTP2 & curl_version()['features'])) {
if (
\PHP_VERSION_ID < 70215 ||
\PHP_VERSION_ID === 70300 ||
\PHP_VERSION_ID === 70301 ||
\PHP_VERSION_ID >= 80000 ||
!(CURL_VERSION_HTTP2 & curl_version()['features'])
) {
// Dont use HTTP/2 push when it's unsupported or buggy, see https://bugs.php.net/76675
$this->serverPushSupported = false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/BaseIntegrationTest.php
Expand Up @@ -8,7 +8,7 @@

abstract class BaseIntegrationTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (getenv('BUZZ_TEST_SERVER')) {
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/BuzzIntegrationTest.php
Expand Up @@ -21,7 +21,7 @@

class BuzzIntegrationTest extends BaseIntegrationTest
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (empty($_SERVER['BUZZ_TEST_SERVER'])) {
Expand Down Expand Up @@ -125,7 +125,7 @@ public function testFormPostWithRequestBuilder($client, $async)
$this->assertNotEmpty($response->getBody()->__toString(), 'Response from server should not be empty');

$data = json_decode($response->getBody()->__toString(), true);
$this->assertInternalType('array', $data, $response->getBody()->__toString());
$this->assertIsArray($data, $response->getBody()->__toString());
$this->assertArrayHasKey('SERVER', $data);

$this->assertStringStartsWith('multipart/form-data', $data['SERVER']['CONTENT_TYPE']);
Expand Down Expand Up @@ -156,7 +156,7 @@ public function testFormPostWithLargeRequestBody($client, $async)
$this->assertNotEmpty($response->getBody()->__toString(), 'Response from server should not be empty');

$data = json_decode($response->getBody()->__toString(), true);
$this->assertInternalType('array', $data, $response->getBody()->__toString());
$this->assertIsArray($data, $response->getBody()->__toString());
$this->assertArrayHasKey('SERVER', $data);

$this->assertStringStartsWith('multipart/form-data', $data['SERVER']['CONTENT_TYPE']);
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Httplug/BaseIntegrationTest.php
Expand Up @@ -9,7 +9,7 @@

abstract class BaseIntegrationTest extends HttpClientTest
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (false === PHPUnitUtility::getUri()) {
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/Httplug/BrowserIntegrationTest.php
Expand Up @@ -7,10 +7,11 @@
use Buzz\Browser;
use Buzz\Client\FileGetContents;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Client\ClientInterface;

class BrowserIntegrationTest extends BaseIntegrationTest
{
protected function createHttpAdapter()
protected function createHttpAdapter(): ClientInterface
{
$client = new FileGetContents(new Psr17Factory(), []);
$browser = new Browser($client, new Psr17Factory());
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/Httplug/CurlIntegrationTest.php
Expand Up @@ -6,10 +6,11 @@

use Buzz\Client\Curl;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Client\ClientInterface;

class CurlIntegrationTest extends BaseIntegrationTest
{
protected function createHttpAdapter()
protected function createHttpAdapter(): ClientInterface
{
return new Curl(new Psr17Factory(), []);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/Httplug/FileGetContentsIntegrationTest.php
Expand Up @@ -6,10 +6,11 @@

use Buzz\Client\FileGetContents;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Client\ClientInterface;

class FileGetContentsIntegrationTest extends BaseIntegrationTest
{
protected function createHttpAdapter()
protected function createHttpAdapter(): ClientInterface
{
return new FileGetContents(new Psr17Factory(), []);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/Httplug/MultiCurlIntegrationTest.php
Expand Up @@ -6,10 +6,11 @@

use Buzz\Client\MultiCurl;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Client\ClientInterface;

class MultiCurlIntegrationTest extends BaseIntegrationTest
{
protected function createHttpAdapter()
protected function createHttpAdapter(): ClientInterface
{
return new MultiCurl(new Psr17Factory(), []);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/MultiCurlServerPushTest.php
Expand Up @@ -10,10 +10,10 @@

class MultiCurlServerPushTest extends BaseIntegrationTest
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (\PHP_VERSION_ID < 70400 || curl_version()['version_number'] < 472065) {
if (\PHP_VERSION_ID < 70400 || \PHP_VERSION_ID >= 80000 || curl_version()['version_number'] < 472065) {
$this->markTestSkipped('This environment does not support server push');
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/MultiCurlTest.php
Expand Up @@ -11,7 +11,7 @@

class MultiCurlTest extends BaseIntegrationTest
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (empty($_SERVER['BUZZ_TEST_SERVER'])) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/BrowserTest.php
Expand Up @@ -20,7 +20,7 @@ class BrowserTest extends TestCase
/** @var Browser */
private $browser;

protected function setUp()
protected function setUp(): void
{
$this->client = $this->getMockBuilder('Buzz\Client\Curl')
->disableOriginalConstructor()
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testSubmitForm(array $fields, array $headers, array $requestHead
$regex = substr($requestBody, 5);
$regex = str_replace("\n", "\r\n", $regex);

return preg_match($regex, $input);
return false !== preg_match($regex, $input);
};

$browser = $this->getMockBuilder(Browser::class)
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Middleware/History/JournalTest.php
Expand Up @@ -23,7 +23,7 @@ class JournalTest extends TestCase

protected $response3;

protected function setUp()
protected function setUp(): void
{
$this->request1 = new Request('GET', '/r1', [], 'request1');
$this->request2 = new Request('GET', '/r2', [], 'request2');
Expand All @@ -33,7 +33,7 @@ protected function setUp()
$this->response3 = new Response(200, [], 'response3');
}

protected function tearDown()
protected function tearDown(): void
{
$this->request1 = null;
$this->request2 = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Middleware/HistoryMiddlewareTest.php
Expand Up @@ -16,7 +16,7 @@ class HistoryMiddlewareTest extends TestCase
/** @var HistoryMiddleware */
private $middleware;

protected function setUp()
protected function setUp(): void
{
$this->journal = $this->getMockBuilder('Buzz\Middleware\History\Journal')
->disableOriginalConstructor()
Expand Down
9 changes: 8 additions & 1 deletion tests/Unit/Middleware/LoggerMiddlewareTest.php
Expand Up @@ -19,7 +19,14 @@ public function testLogger()

// TODO Use PSR3 logger
$logger = new CallbackLogger(function ($level, $message, array $context) use ($that) {
$that->assertRegExp('~^Sent "GET http://google.com/" in \d+ms$~', $message);
$pattern = '~^Sent "GET http://google.com/" in \d+ms$~';
if (method_exists($this, 'assertMatchesRegularExpression')) {
$that->assertMatchesRegularExpression($pattern, $message);

return;
}
// phpunit 7 compatibility
$that->assertRegExp($pattern, $message);
});

$request = new Request('GET', 'http://google.com/');
Expand Down
9 changes: 8 additions & 1 deletion tests/Unit/Middleware/WsseAuthMiddlewareTest.php
Expand Up @@ -22,6 +22,13 @@ public function testBasicAuthHeader()

$this->assertEquals('WSSE profile="UsernameToken"', $newRequest->getHeaderLine('Authorization'));
$wsse = $newRequest->getHeaderLine('X-WSSE');
$this->assertRegExp('|UsernameToken Username="foo", PasswordDigest=".+?", Nonce=".+?", Created=".+?"|', $wsse);
$pattern = '|UsernameToken Username="foo", PasswordDigest=".+?", Nonce=".+?", Created=".+?"|';
if (method_exists($this, 'assertMatchesRegularExpression')) {
$this->assertMatchesRegularExpression($pattern, $wsse);

return;
}
// phpunit 7 compatibility
$this->assertRegExp($pattern, $wsse);
}
}

0 comments on commit e7468d1

Please sign in to comment.