Skip to content

Allow PHP 8 #389

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 27 commits into from
Dec 23, 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
24 changes: 13 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
- SYMFONY_PHPUNIT_VERSION="8"
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
- SYMFONY_DEPRECATIONS_HELPER="max[self]=0"
- DEPENDENCIES="php-http/guzzle7-adapter"

branches:
except:
Expand All @@ -22,14 +23,14 @@ matrix:
fast_finish: true
include:
# Minimum supported Symfony version and lowest PHP version
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak"
- php: 7.3
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak" DEPENDENCIES="php-http/guzzle6-adapter"

# Test the latest stable release
- php: 7.2
- php: 7.3
env: COVERAGE=true TEST_COMMAND="composer test-ci" DEPENDENCIES="php-http/vcr-plugin:^1.0@dev"
env: COVERAGE=true TEST_COMMAND="composer test-ci" DEPENDENCIES="php-http/guzzle7-adapter php-http/vcr-plugin:^1.0@dev"
- php: 7.4
- php: 8.0

# Test LTS versions
- php: 7.3
Expand All @@ -39,21 +40,23 @@ matrix:
- php: 7.3
env: SYMFONY_REQUIRE=4.3.*
- php: 7.3
env: SYMFONY_REQUIRE=4.4.* DEPENDENCIES="symfony/http-client:^4.4"
env: SYMFONY_REQUIRE=4.4.* DEPENDENCIES="php-http/guzzle7-adapter symfony/http-client:^4.4"
- php: 7.3
env: SYMFONY_REQUIRE=5.0.* DEPENDENCIES="symfony/http-client:^5.0"
env: SYMFONY_REQUIRE=5.0.* DEPENDENCIES="php-http/guzzle7-adapter symfony/http-client:^5.0"

# Test with httplug 1.x clients
- php: 7.2
- php: 7.3
env: DEPENDENCIES="php-http/buzz-adapter:^1.0 php-http/guzzle6-adapter:^1.1.1 php-http/react-adapter:^0.2.1 php-http/socket-client:^1.0"

# Test with httplug 2.x clients
- php: 7.2
env: DEPENDENCIES="php-http/guzzle6-adapter:^2.0.1 php-http/curl-client:^2.0.0 php-http/vcr-plugin:^1.0@dev"
- php: 7.3
env: DEPENDENCIES="php-http/guzzle7-adapter php-http/curl-client:^2.0.0 php-http/vcr-plugin:^1.0@dev"

# Latest commit to master
- php: 7.4
env: STABILITY="dev" DEPENDENCIES="php-http/vcr-plugin:^1.0@dev"
env: STABILITY="dev" DEPENDENCIES="php-http/guzzle7-adapter php-http/vcr-plugin:^1.0@dev"
- php: 8.0
env: STABILITY="dev"

allow_failures:
# dev stability is allowed to fail.
Expand All @@ -67,7 +70,6 @@ before_install:

install:
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
- COMPOSER_MEMORY_LIMIT=-1 composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
- vendor/bin/simple-phpunit install

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

The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.

# 1.20.0 - to be released

- Support PHP 8.

## 1.19.0 - 2020-10-21

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Please see the [official documentation](http://docs.php-http.org/en/latest/integ
## Testing

``` bash
$ composer require --dev php-http/guzzle7-adapter
$ composer test
```

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.3 || ^8.0",
"php-http/client-common": "^1.9 || ^2.0",
"php-http/client-implementation": "^1.0",
"php-http/discovery": "^1.0",
Expand All @@ -46,11 +46,11 @@
"php-http/curl-client": "<2.0"
},
"require-dev": {
"guzzlehttp/psr7": "^1.7",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"nyholm/nsa": "^1.1",
"nyholm/psr7": "^1.2.1",
"php-http/cache-plugin": "^1.7",
"php-http/guzzle6-adapter": "^1.1.1 || ^2.0.1",
"php-http/mock-client": "^1.2",
"php-http/promise": "^1.0",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
Expand Down
25 changes: 25 additions & 0 deletions src/ClientFactory/Guzzle7Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Http\HttplugBundle\ClientFactory;

use Http\Adapter\Guzzle7\Client;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class Guzzle7Factory implements ClientFactory
{
/**
* {@inheritdoc}
*/
public function createClient(array $config = [])
{
if (!class_exists('Http\Adapter\Guzzle7\Client')) {
throw new \LogicException('To use the Guzzle7 adapter you need to install the "php-http/guzzle7-adapter" package.');
}

return Client::createWithConfig($config);
}
}
6 changes: 6 additions & 0 deletions src/Resources/config/data-collector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
<argument type="service" id="httplug.collector.formatter"/>
<argument type="service" id="debug.stopwatch"/>
</service>
<service id="httplug.collector.factory.guzzle7" class="Http\HttplugBundle\Collector\ProfileClientFactory" decorates="httplug.factory.guzzle7" public="false">
<argument type="service" id="httplug.collector.factory.guzzle7.inner"/>
<argument type="service" id="httplug.collector.collector"/>
<argument type="service" id="httplug.collector.formatter"/>
<argument type="service" id="debug.stopwatch"/>
</service>
<service id="httplug.collector.factory.react" class="Http\HttplugBundle\Collector\ProfileClientFactory" decorates="httplug.factory.react" public="false">
<argument type="service" id="httplug.collector.factory.react.inner"/>
<argument type="service" id="httplug.collector.collector"/>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<argument type="service" id="httplug.message_factory"/>
</service>
<service id="httplug.factory.guzzle6" class="Http\HttplugBundle\ClientFactory\Guzzle6Factory" public="false" />
<service id="httplug.factory.guzzle7" class="Http\HttplugBundle\ClientFactory\Guzzle7Factory" public="false" />
<service id="httplug.factory.react" class="Http\HttplugBundle\ClientFactory\ReactFactory" public="false">
<argument type="service" id="httplug.message_factory"/>
</service>
Expand Down
5 changes: 5 additions & 0 deletions tests/Functional/DiscoveredClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Http\HttplugBundle\Tests\Functional;

use Http\Adapter\Guzzle7\Client;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\Discovery\HttpAsyncClientDiscovery;
Expand Down Expand Up @@ -101,6 +102,10 @@ public function testDisabledDiscovery(): void
*/
public function testForcedDiscovery(): void
{
if (!class_exists(Client::class)) {
$this->markTestSkipped('Guzzle7 adapter is not installed');
}

$container = $this->getContainer(true, 'discovery_forced');

$this->assertFalse($container->has('httplug.auto_discovery.auto_discovered_client'));
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/DiscoveryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Http\HttplugBundle\Tests\Unit\DependencyInjection\Compiler;

use Http\Adapter\Guzzle6\Client;
use Http\Adapter\Guzzle7\Client;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\Discovery\HttpClientDiscovery;
Expand Down
13 changes: 13 additions & 0 deletions tests/Functional/ServiceInstantiationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Http\HttplugBundle\Tests\Functional;

use GuzzleHttp\Psr7\Request as GuzzleRequest;
use Http\Adapter\Guzzle7\Client;
use Http\Client\Common\Plugin\RedirectPlugin;
use Http\Client\Common\PluginClient;
use Http\Client\HttpClient;
Expand All @@ -29,6 +30,10 @@ class ServiceInstantiationTest extends WebTestCase
{
public function testHttpClient(): void
{
if (!class_exists(Client::class)) {
$this->markTestSkipped('Guzzle7 adapter is not installed');
}

static::bootKernel();
$container = static::$kernel->getContainer();
$this->assertTrue($container->has('httplug.client'));
Expand All @@ -38,6 +43,10 @@ public function testHttpClient(): void

public function testHttpClientNoDebug(): void
{
if (!class_exists(Client::class)) {
$this->markTestSkipped('Guzzle7 adapter is not installed');
}

static::bootKernel(['debug' => false]);
$container = static::$kernel->getContainer();
$this->assertTrue($container->has('httplug.client'));
Expand Down Expand Up @@ -70,6 +79,10 @@ public function testProfilingShouldNotChangeServiceReference(): void

public function testProfilingDecoration(): void
{
if (!class_exists(Client::class)) {
$this->markTestSkipped('Guzzle7 adapter is not installed');
}

static::bootKernel(['debug' => true]);
$container = static::$kernel->getContainer();

Expand Down
6 changes: 3 additions & 3 deletions tests/Resources/Fixtures/config/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
'stream_factory' => 'my_stream_factory',
],
'classes' => [
'client' => 'Http\Adapter\Guzzle6\Client',
'client' => 'Http\Adapter\Guzzle7\Client',
'message_factory' => 'Http\Message\MessageFactory\GuzzleMessageFactory',
'uri_factory' => 'Http\Message\UriFactory\GuzzleUriFactory',
'stream_factory' => 'Http\Message\StreamFactory\GuzzleStreamFactory',
'psr18_client' => 'Http\Adapter\Guzzle6\Client',
'psr18_client' => 'Http\Adapter\Guzzle7\Client',
'psr17_request_factory' => 'Nyholm\Psr7\Factory\Psr17Factory',
'psr17_response_factory' => 'Nyholm\Psr7\Factory\Psr17Factory',
'psr17_stream_factory' => 'Nyholm\Psr7\Factory\Psr17Factory',
Expand All @@ -25,7 +25,7 @@
],
'clients' => [
'test' => [
'factory' => 'httplug.factory.guzzle6',
'factory' => 'httplug.factory.guzzle7',
'http_methods_client' => true,
'plugins' => [
'httplug.plugin.redirect',
Expand Down
6 changes: 3 additions & 3 deletions tests/Resources/Fixtures/config/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
<stream-factory>my_stream_factory</stream-factory>
</main-alias>
<classes>
<client>Http\Adapter\Guzzle6\Client</client>
<client>Http\Adapter\Guzzle7\Client</client>
<message-factory>Http\Message\MessageFactory\GuzzleMessageFactory</message-factory>
<uri-factory>Http\Message\UriFactory\GuzzleUriFactory</uri-factory>
<stream-factory>Http\Message\StreamFactory\GuzzleStreamFactory</stream-factory>
<psr18-client>Http\Adapter\Guzzle6\Client</psr18-client>
<psr18-client>Http\Adapter\Guzzle7\Client</psr18-client>
<psr17-request-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-request-factory>
<psr17-response-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-response-factory>
<psr17-stream-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-stream-factory>
<psr17-uri-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-uri-factory>
<psr17-uploaded-file-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-uploaded-file-factory>
<psr17-server-request-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-server-request-factory>
</classes>
<client name="test" factory="httplug.factory.guzzle6" http-methods-client="true">
<client name="test" factory="httplug.factory.guzzle7" http-methods-client="true">
<plugin>httplug.plugin.redirect</plugin>
<plugin>
<add-host host="http://localhost"/>
Expand Down
6 changes: 3 additions & 3 deletions tests/Resources/Fixtures/config/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ httplug:
uri_factory: my_uri_factory
stream_factory: my_stream_factory
classes:
client: Http\Adapter\Guzzle6\Client
client: Http\Adapter\Guzzle7\Client
message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
uri_factory: Http\Message\UriFactory\GuzzleUriFactory
stream_factory: Http\Message\StreamFactory\GuzzleStreamFactory
psr18_client: Http\Adapter\Guzzle6\Client
psr18_client: Http\Adapter\Guzzle7\Client
psr17_request_factory: Nyholm\Psr7\Factory\Psr17Factory
psr17_response_factory: Nyholm\Psr7\Factory\Psr17Factory
psr17_stream_factory: Nyholm\Psr7\Factory\Psr17Factory
Expand All @@ -19,7 +19,7 @@ httplug:
psr17_server_request_factory: Nyholm\Psr7\Factory\Psr17Factory
clients:
test:
factory: httplug.factory.guzzle6
factory: httplug.factory.guzzle7
http_methods_client: true
plugins:
- 'httplug.plugin.redirect'
Expand Down
2 changes: 1 addition & 1 deletion tests/Resources/app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ httplug:
async_client: auto
clients:
acme:
factory: httplug.factory.guzzle6
factory: httplug.factory.guzzle7
plugins:
-
decoder:
Expand Down
27 changes: 27 additions & 0 deletions tests/Unit/ClientFactory/Guzzle7FactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Http\HttplugBundle\Tests\Unit\ClientFactory;

use Http\Adapter\Guzzle7\Client;
use Http\HttplugBundle\ClientFactory\Guzzle7Factory;
use PHPUnit\Framework\TestCase;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class Guzzle7FactoryTest extends TestCase
{
public function testCreateClient(): void
{
if (!class_exists(Client::class)) {
$this->markTestSkipped('Guzzle7 adapter is not installed');
}

$factory = new Guzzle7Factory();
$client = $factory->createClient();

$this->assertInstanceOf(Client::class, $client);
}
}
6 changes: 5 additions & 1 deletion tests/Unit/Collector/StackPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ public function testOnException(): void

public function testOnError(): void
{
$this->expectException(Warning::class);
if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
$this->expectException(\DivisionByZeroError::class);
} else {
$this->expectException(Warning::class);
}

$this->collector
->expects($this->once())
Expand Down
12 changes: 8 additions & 4 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Http\HttplugBundle\Tests\Unit\DependencyInjection;

use Http\Adapter\Guzzle6\Client;
use Http\Adapter\Guzzle7\Client;
use Http\HttplugBundle\DependencyInjection\Configuration;
use Http\HttplugBundle\DependencyInjection\HttplugExtension;
use Http\Message\MessageFactory\GuzzleMessageFactory;
Expand Down Expand Up @@ -128,6 +128,10 @@ public function testEmptyConfiguration(): void

public function testSupportsAllConfigFormats(): void
{
if (!class_exists(Client::class)) {
$this->markTestSkipped('Guzzle 7 adapter is not installed');
}

$expectedConfiguration = [
'default_client_autowiring' => false,
'main_alias' => [
Expand Down Expand Up @@ -158,7 +162,7 @@ public function testSupportsAllConfigFormats(): void
],
'clients' => [
'test' => [
'factory' => 'httplug.factory.guzzle6',
'factory' => 'httplug.factory.guzzle7',
'http_methods_client' => true,
'service' => null,
'public' => null,
Expand Down Expand Up @@ -435,7 +439,7 @@ public function testClientCacheConfigMustHavePool(): void
$file = __DIR__.'/../../Resources/Fixtures/config/client_cache_config_with_no_pool.yml';

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The child node "cache_pool" at path "httplug.clients.test.plugins.0.cache" must be configured.');
$this->expectExceptionMessage('httplug.clients.test.plugins.0.cache');
$this->assertProcessedConfigurationEquals([], [$file]);
}

Expand All @@ -444,7 +448,7 @@ public function testCacheConfigMustHavePool(): void
$file = __DIR__.'/../../Resources/Fixtures/config/cache_config_with_no_pool.yml';

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('The child node "cache_pool" at path "httplug.plugins.cache" must be configured.');
$this->expectExceptionMessage('cache_pool');
$this->assertProcessedConfigurationEquals([], [$file]);
}

Expand Down
Loading