diff --git a/.travis.yml b/.travis.yml index 678f7a6a..45e7fdc4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: @@ -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 @@ -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. @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index a7395b4e..8e178734 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index c2151b2f..e5c21ad9 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/composer.json b/composer.json index 8c61e378..a2cf6645 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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", diff --git a/src/ClientFactory/Guzzle7Factory.php b/src/ClientFactory/Guzzle7Factory.php new file mode 100644 index 00000000..6045ab03 --- /dev/null +++ b/src/ClientFactory/Guzzle7Factory.php @@ -0,0 +1,25 @@ + + */ +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); + } +} diff --git a/src/Resources/config/data-collector.xml b/src/Resources/config/data-collector.xml index dd3f3b85..be607ac2 100644 --- a/src/Resources/config/data-collector.xml +++ b/src/Resources/config/data-collector.xml @@ -72,6 +72,12 @@ + + + + + + diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 67c828bf..8cab29a2 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -90,6 +90,7 @@ + diff --git a/tests/Functional/DiscoveredClientsTest.php b/tests/Functional/DiscoveredClientsTest.php index fe019960..507bd64c 100644 --- a/tests/Functional/DiscoveredClientsTest.php +++ b/tests/Functional/DiscoveredClientsTest.php @@ -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; @@ -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')); diff --git a/tests/Functional/DiscoveryTest.php b/tests/Functional/DiscoveryTest.php index 511aecec..a7210a02 100644 --- a/tests/Functional/DiscoveryTest.php +++ b/tests/Functional/DiscoveryTest.php @@ -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; diff --git a/tests/Functional/ServiceInstantiationTest.php b/tests/Functional/ServiceInstantiationTest.php index aaceefa2..9bb7d0f3 100644 --- a/tests/Functional/ServiceInstantiationTest.php +++ b/tests/Functional/ServiceInstantiationTest.php @@ -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; @@ -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')); @@ -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')); @@ -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(); diff --git a/tests/Resources/Fixtures/config/full.php b/tests/Resources/Fixtures/config/full.php index 13c4de0f..f73b0769 100644 --- a/tests/Resources/Fixtures/config/full.php +++ b/tests/Resources/Fixtures/config/full.php @@ -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', @@ -25,7 +25,7 @@ ], 'clients' => [ 'test' => [ - 'factory' => 'httplug.factory.guzzle6', + 'factory' => 'httplug.factory.guzzle7', 'http_methods_client' => true, 'plugins' => [ 'httplug.plugin.redirect', diff --git a/tests/Resources/Fixtures/config/full.xml b/tests/Resources/Fixtures/config/full.xml index 48449964..b109dbb3 100644 --- a/tests/Resources/Fixtures/config/full.xml +++ b/tests/Resources/Fixtures/config/full.xml @@ -10,11 +10,11 @@ my_stream_factory - Http\Adapter\Guzzle6\Client + Http\Adapter\Guzzle7\Client Http\Message\MessageFactory\GuzzleMessageFactory Http\Message\UriFactory\GuzzleUriFactory Http\Message\StreamFactory\GuzzleStreamFactory - Http\Adapter\Guzzle6\Client + Http\Adapter\Guzzle7\Client Nyholm\Psr7\Factory\Psr17Factory Nyholm\Psr7\Factory\Psr17Factory Nyholm\Psr7\Factory\Psr17Factory @@ -22,7 +22,7 @@ Nyholm\Psr7\Factory\Psr17Factory Nyholm\Psr7\Factory\Psr17Factory - + httplug.plugin.redirect diff --git a/tests/Resources/Fixtures/config/full.yml b/tests/Resources/Fixtures/config/full.yml index 1190f9c9..1f4269cd 100644 --- a/tests/Resources/Fixtures/config/full.yml +++ b/tests/Resources/Fixtures/config/full.yml @@ -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 @@ -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' diff --git a/tests/Resources/app/config/config_test.yml b/tests/Resources/app/config/config_test.yml index 3535e9de..929e5bdf 100644 --- a/tests/Resources/app/config/config_test.yml +++ b/tests/Resources/app/config/config_test.yml @@ -7,7 +7,7 @@ httplug: async_client: auto clients: acme: - factory: httplug.factory.guzzle6 + factory: httplug.factory.guzzle7 plugins: - decoder: diff --git a/tests/Unit/ClientFactory/Guzzle7FactoryTest.php b/tests/Unit/ClientFactory/Guzzle7FactoryTest.php new file mode 100644 index 00000000..886ba9a6 --- /dev/null +++ b/tests/Unit/ClientFactory/Guzzle7FactoryTest.php @@ -0,0 +1,27 @@ + + */ +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); + } +} diff --git a/tests/Unit/Collector/StackPluginTest.php b/tests/Unit/Collector/StackPluginTest.php index aebad53e..8eb443cd 100644 --- a/tests/Unit/Collector/StackPluginTest.php +++ b/tests/Unit/Collector/StackPluginTest.php @@ -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()) diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index 20871ed3..35f56953 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -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; @@ -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' => [ @@ -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, @@ -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]); } @@ -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]); } diff --git a/tests/Unit/DependencyInjection/HttplugExtensionTest.php b/tests/Unit/DependencyInjection/HttplugExtensionTest.php index 662fda31..3858010a 100644 --- a/tests/Unit/DependencyInjection/HttplugExtensionTest.php +++ b/tests/Unit/DependencyInjection/HttplugExtensionTest.php @@ -4,7 +4,7 @@ namespace Http\HttplugBundle\Tests\Unit\DependencyInjection; -use Http\Adapter\Guzzle6\Client; +use Http\Adapter\Guzzle7\Client; use Http\Client\HttpClient; use Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder; use Http\HttplugBundle\Collector\PluginClientFactoryListener; @@ -49,6 +49,10 @@ public function testConfigLoadDefault(): void public function testConfigLoadClass(): void { + if (!class_exists(Client::class)) { + $this->markTestSkipped('Guzzle 7 adapter is not installed'); + } + $this->load([ 'classes' => [ 'client' => Client::class, @@ -353,7 +357,6 @@ public function testClientShouldHaveDefaultVisibility(): void if (version_compare(Kernel::VERSION, '3.4', '>=')) { // Symfony made services private by default starting from 3.4 - $this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPublic()); $this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPrivate()); } else { // Legacy Symfony