Skip to content
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

feat: drop support for php < 8.1, drop support for symfony < 5.4 (WIP) #243

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from
Open
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 .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Remove phpspec
run: composer remove --dev friends-of-phpspec/phpspec-code-coverage phpspec/phpspec

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
Chris53897 marked this conversation as resolved.
Show resolved Hide resolved
env:
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: tests

on:
push:
branches:
- '*.x'
branches:
- '*.x'
pull_request:

jobs:
Expand All @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php: ['8.1', '8.2', '8.3']

steps:
- name: Checkout code
Expand All @@ -36,7 +36,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.4', '8.2', '8.3']
php: ['8.1']

steps:
- name: Checkout code
Expand All @@ -61,10 +61,8 @@ jobs:
strategy:
matrix:
include:
- symfony: '4.4.*'
php-version: '7.1'
- symfony: '5.4.*'
php-version: '7.4'
php-version: '8.1'
- symfony: '6.4.*'
php-version: '8.2'
- symfony: '7.0.*'
Expand Down Expand Up @@ -103,13 +101,13 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
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 require "friends-of-phpspec/phpspec-code-coverage:^6.3" --no-interaction --no-update
composer update --prefer-dist --no-interaction --no-progress

- name: Execute tests
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## unreleased

- drop support for php < 8.1
- drop support for symfony < 5.4
- Cleaned up phpdoc.

## 2.7.1 - 2023-11-30
Expand Down
21 changes: 10 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@
}
],
"require": {
"php": "^7.1 || ^8.0",
"php-http/httplug": "^2.0",
"php": "^8.1",
"php-http/httplug": "^2.4",
"php-http/message": "^1.6",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0 || ^2.0",
"symfony/options-resolver": "~4.0.15 || ~4.1.9 || ^4.2.1 || ^5.0 || ^6.0 || ^7.0",
"symfony/polyfill-php80": "^1.17"
"psr/http-message": "^2.0",
"symfony/options-resolver": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
"doctrine/instantiator": "^1.1",
"guzzlehttp/psr7": "^1.4",
"nyholm/psr7": "^1.2",
"phpspec/phpspec": "^5.1 || ^6.3 || ^7.1",
"phpspec/prophecy": "^1.10.2",
"phpunit/phpunit": "^7.5.20 || ^8.5.33 || ^9.6.7"
"guzzlehttp/psr7": "^2.6",
dbu marked this conversation as resolved.
Show resolved Hide resolved
"nyholm/psr7": "^1.8",
"phpspec/phpspec": "^7.5",
"phpspec/prophecy": "^1.18",
"phpunit/phpunit": "^10.5.8",
"phpspec/prophecy-phpunit": "^2.1"
},
"suggest": {
"ext-json": "To detect JSON responses with the ContentTypePlugin",
Expand Down
20 changes: 10 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
>

<testsuites>
<testsuite name="HTTPlug unit tests">
<directory>./tests</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="HTTPlug unit tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
16 changes: 8 additions & 8 deletions spec/Plugin/ContentTypePluginSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function it_is_a_plugin()
public function it_adds_json_content_type_header(RequestInterface $request)
{
$request->hasHeader('Content-Type')->shouldBeCalled()->willReturn(false);
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for(json_encode(['foo' => 'bar'])));
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor(json_encode(['foo' => 'bar'])));
$request->withHeader('Content-Type', 'application/json')->shouldBeCalled()->willReturn($request);

$this->handleRequest($request, PluginStub::next(), function () {});
Expand All @@ -31,7 +31,7 @@ public function it_adds_json_content_type_header(RequestInterface $request)
public function it_adds_xml_content_type_header(RequestInterface $request)
{
$request->hasHeader('Content-Type')->shouldBeCalled()->willReturn(false);
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('<foo>bar</foo>'));
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor()('<foo>bar</foo>'));
$request->withHeader('Content-Type', 'application/xml')->shouldBeCalled()->willReturn($request);

$this->handleRequest($request, PluginStub::next(), function () {});
Expand All @@ -40,7 +40,7 @@ public function it_adds_xml_content_type_header(RequestInterface $request)
public function it_does_not_set_content_type_header(RequestInterface $request)
{
$request->hasHeader('Content-Type')->shouldBeCalled()->willReturn(false);
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('foo'));
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor()('foo'));
$request->withHeader('Content-Type', null)->shouldNotBeCalled();

$this->handleRequest($request, PluginStub::next(), function () {});
Expand All @@ -49,7 +49,7 @@ public function it_does_not_set_content_type_header(RequestInterface $request)
public function it_does_not_set_content_type_header_if_already_one(RequestInterface $request)
{
$request->hasHeader('Content-Type')->shouldBeCalled()->willReturn(true);
$request->getBody()->shouldNotBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('foo'));
$request->getBody()->shouldNotBeCalled()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor()('foo'));
$request->withHeader('Content-Type', null)->shouldNotBeCalled();

$this->handleRequest($request, PluginStub::next(), function () {});
Expand All @@ -58,7 +58,7 @@ public function it_does_not_set_content_type_header_if_already_one(RequestInterf
public function it_does_not_set_content_type_header_if_size_0_or_unknown(RequestInterface $request)
{
$request->hasHeader('Content-Type')->shouldBeCalled()->willReturn(false);
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for());
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor());
$request->withHeader('Content-Type', null)->shouldNotBeCalled();

$this->handleRequest($request, PluginStub::next(), function () {});
Expand All @@ -71,7 +71,7 @@ public function it_adds_xml_content_type_header_if_size_limit_is_not_reached_usi
]);

$request->hasHeader('Content-Type')->shouldBeCalled()->willReturn(false);
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('<foo>bar</foo>'));
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor()('<foo>bar</foo>'));
$request->withHeader('Content-Type', 'application/xml')->shouldBeCalled()->willReturn($request);

$this->handleRequest($request, PluginStub::next(), function () {});
Expand All @@ -85,7 +85,7 @@ public function it_adds_xml_content_type_header_if_size_limit_is_not_reached(Req
]);

$request->hasHeader('Content-Type')->shouldBeCalled()->willReturn(false);
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('<foo>bar</foo>'));
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor()('<foo>bar</foo>'));
$request->withHeader('Content-Type', 'application/xml')->shouldBeCalled()->willReturn($request);

$this->handleRequest($request, PluginStub::next(), function () {});
Expand All @@ -99,7 +99,7 @@ public function it_does_not_set_content_type_header_if_size_limit_is_reached(Req
]);

$request->hasHeader('Content-Type')->shouldBeCalled()->willReturn(false);
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\stream_for('<foo>bar</foo>'));
$request->getBody()->shouldBeCalled()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor()('<foo>bar</foo>'));
$request->withHeader('Content-Type', null)->shouldNotBeCalled();

$this->handleRequest($request, PluginStub::next(), function () {});
Expand Down
11 changes: 3 additions & 8 deletions tests/HttpMethodsClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Http\Client\Common\HttpMethodsClient;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Response;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
Expand All @@ -16,15 +17,9 @@ class HttpMethodsClientTest extends TestCase
private const HEADER_VALUE = 'text/plain';
private const BODY = 'body';

/**
* @var ClientInterface
*/
private $httpClient;
private ClientInterface|MockObject $httpClient;

/**
* @var HttpMethodsClient
*/
private $httpMethodsClient;
private HttpMethodsClient $httpMethodsClient;

protected function setUp(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Plugin/RedirectPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function (RequestInterface $request) {
$this->assertSame('https://example.com/other', $response->getHeaderLine('uri'));
}

public function provideRedirections(): array
public static function provideRedirections(): array
{
return [
'no path on target' => ['https://example.com/path?query=value', 'https://example.com?query=value', 'https://example.com?query=value'],
Expand Down
3 changes: 3 additions & 0 deletions tests/PluginChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
use Http\Client\Common\PluginChain;
use Http\Promise\Promise;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Http\Message\RequestInterface;

class PluginChainTest extends TestCase
{
use ProphecyTrait;

private function createPlugin(callable $func): Plugin
{
return new class($func) implements Plugin {
Expand Down
5 changes: 4 additions & 1 deletion tests/PluginClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class PluginClientBuilderTest extends TestCase
{
use ProphecyTrait;

/** @dataProvider clientProvider */
public function testPriority(string $client): void
{
Expand Down Expand Up @@ -71,7 +74,7 @@ function (): array {
$this->assertSame(5, $options['max_restarts']);
}

public function clientProvider(): iterable
public static function clientProvider(): iterable
{
yield 'sync\'d http client' => [HttpClient::class];
yield 'async\'d http client' => [HttpAsyncClient::class];
Expand Down
2 changes: 1 addition & 1 deletion tests/PluginClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testRestartChain(PluginClient $client, string $method, string $r
$this->assertInstanceOf($returnType, $result);
}

public function clientAndMethodProvider()
public static function clientAndMethodProvider()
{
$syncClient = new class() implements ClientInterface {
public function sendRequest(RequestInterface $request): ResponseInterface
Expand Down
Loading