From 876d2e52ebd3248ea8b9c5d1f8523c87e477e509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Hulard?= Date: Mon, 3 Jun 2019 17:36:55 +0200 Subject: [PATCH 1/4] CurlFactory: Add compatibility with curl-client v2 The curl-client rely on PSR17 factories, we must use those factories in the client. --- src/ClientFactory/CurlFactory.php | 20 ++++++++++---------- tests/Unit/ClientFactory/CurlFactoryTest.php | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ClientFactory/CurlFactory.php b/src/ClientFactory/CurlFactory.php index 374e05a9..6d65cdb8 100644 --- a/src/ClientFactory/CurlFactory.php +++ b/src/ClientFactory/CurlFactory.php @@ -3,8 +3,8 @@ namespace Http\HttplugBundle\ClientFactory; use Http\Client\Curl\Client; -use Http\Message\MessageFactory; -use Http\Message\StreamFactory; +use Psr\Http\Message\ResponseFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; /** * @author Tobias Nyholm @@ -12,22 +12,22 @@ class CurlFactory implements ClientFactory { /** - * @var MessageFactory + * @var ResponseFactoryInterface */ - private $messageFactory; + private $responseFactory; /** - * @var StreamFactory + * @var StreamFactoryInterface */ private $streamFactory; /** - * @param MessageFactory $messageFactory - * @param StreamFactory $streamFactory + * @param ResponseFactoryInterface $responseFactory + * @param StreamFactoryInterface $streamFactory */ - public function __construct(MessageFactory $messageFactory, StreamFactory $streamFactory) + public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory) { - $this->messageFactory = $messageFactory; + $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; } @@ -53,6 +53,6 @@ public function createClient(array $config = []) } } - return new Client($this->messageFactory, $this->streamFactory, $config); + return new Client($this->responseFactory, $this->streamFactory, $config); } } diff --git a/tests/Unit/ClientFactory/CurlFactoryTest.php b/tests/Unit/ClientFactory/CurlFactoryTest.php index e5c83f71..c78ee493 100644 --- a/tests/Unit/ClientFactory/CurlFactoryTest.php +++ b/tests/Unit/ClientFactory/CurlFactoryTest.php @@ -4,9 +4,9 @@ use Http\HttplugBundle\ClientFactory\CurlFactory; use Http\Client\Curl\Client; -use Http\Message\MessageFactory; -use Http\Message\StreamFactory; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ResponseFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; /** * @author Tobias Nyholm @@ -20,8 +20,8 @@ public function testCreateClient() } $factory = new CurlFactory( - $this->getMockBuilder(MessageFactory::class)->getMock(), - $this->getMockBuilder(StreamFactory::class)->getMock() + $this->getMockBuilder(ResponseFactoryInterface::class)->getMock(), + $this->getMockBuilder(StreamFactoryInterface::class)->getMock() ); $client = $factory->createClient(); From f72fddf63a7bf6de1447af42bdb1a02d14f2c083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Hulard?= Date: Mon, 3 Jun 2019 17:37:09 +0200 Subject: [PATCH 2/4] CI: Update travis matrix to test on curl-client v2. This will blacklist the curl-client v1 installation since there is no way to detect which version is installed and adapt the Factory based on that information. --- .travis.yml | 4 ++-- composer.json | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 48dad698..246a5dcb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,11 +38,11 @@ matrix: # Test with httplug 1.x clients - php: 7.2 - env: DEPENDENCIES="php-http/buzz-adapter:^1.0 php-http/curl-client:^1.0 php-http/guzzle6-adapter:^1.1.1 php-http/react-adapter:^0.2.1 php-http/socket-client:^1.0" + 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" + env: DEPENDENCIES="php-http/guzzle6-adapter:^2.0.1 php-http/curl-client:^2.0.0" # Latest commit to master - php: 7.3 diff --git a/composer.json b/composer.json index 18399915..29baffc5 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,8 @@ "symfony/options-resolver": "^3.4.20 || ^4.0.15 || ^4.1.9 || ^4.2.1" }, "conflict": { - "php-http/guzzle6-adapter": "<1.1" + "php-http/guzzle6-adapter": "<1.1", + "php-http/curl-client": "<2.0" }, "require-dev": { "guzzlehttp/psr7": "^1.0", From 9a994892da4a5e03e684633c135d44641108444b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Hulard?= Date: Mon, 3 Jun 2019 18:33:16 +0200 Subject: [PATCH 3/4] Update CHANGELOG with latest changes. --- CHANGELOG.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27360216..ca071f04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,12 +12,18 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added - Integration for VCR Plugin +- curl-client v1.* is marked in conflict with the current bundle version. + +### Fixed + +- Fix compatibility with curl-client v2.*, the `CurlFactory` now build the + client using PSR17 factories. ## 1.15.2 - 2019-04-18 ### Fixed -- Fix to pass only allowed options to the `ContentTypePlugin`. +- Fix to pass only allowed options to the `ContentTypePlugin`. ## 1.15.1 - 2019-04-12 @@ -34,7 +40,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee (Only available with Httplug 2) - Configuration for the content_type plugin - Support for namespaced Twig classes. -- Configuration option default_client_autowiring that you can set to false +- Configuration option default_client_autowiring that you can set to false to prevent autowiring the HttpClient and HttpAsyncClient ### Changed @@ -58,7 +64,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added -- Support for any PSR-18 client. +- Support for any PSR-18 client. ### Changed @@ -100,14 +106,14 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ## 1.10.0 - 2018-03-27 ### Added - + - Allow to configure the `AddPathPlugin` per client, under the `add_path` configuration key. -- Allow to configure clients with a `service` instead of a factory. +- Allow to configure clients with a `service` instead of a factory. ## 1.9.0 - 2018-03-06 ### Added - + - Allow to configure the `BaseUriPlugin` per client, under the `base_uri` configuration key. ## 1.8.1 - 2017-12-06 @@ -120,7 +126,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee ### Added -- Symfony 4 support. +- Symfony 4 support. - Support autowiring of `Http\Client\Common\PluginClientFactory`. - Any third party library using `Http\Client\Common\PluginClientFactory` to create `Http\Client\Common\PluginClient` instances now gets zero config profiling. @@ -170,8 +176,8 @@ services aliases for autowiring in Symfony 3.3. ### Changed -- We do collect profiler data after the request is processed by a plugin. With this change we -will for example see the changes of `HeaderAppendPlugin` at that plugin instead of the next one. +- We do collect profiler data after the request is processed by a plugin. With this change we +will for example see the changes of `HeaderAppendPlugin` at that plugin instead of the next one. ## 1.5.0 - 2017-05-05 From 4cc03faba5458c49793dbb2a9daa967489f19d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Hulard?= Date: Wed, 5 Jun 2019 11:39:57 +0200 Subject: [PATCH 4/4] VCR Plugin: Remove it from require-dev. Also skip the tests which rely on it when the plugin is not installed. The tests are still executed when check httplug 2.x clients. --- .travis.yml | 6 +++--- composer.json | 1 - tests/Unit/DependencyInjection/HttplugExtensionTest.php | 8 ++++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 246a5dcb..7d916a46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ matrix: - php: 7.1 - php: 7.2 - php: 7.3 - env: COVERAGE=true TEST_COMMAND="composer test-ci" + env: COVERAGE=true TEST_COMMAND="composer test-ci" DEPENDENCIES="php-http/vcr-plugin:^1.0@dev" # Test LTS versions - php: 7.3 @@ -42,11 +42,11 @@ matrix: # 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" + env: DEPENDENCIES="php-http/guzzle6-adapter:^2.0.1 php-http/curl-client:^2.0.0 php-http/vcr-plugin:^1.0@dev" # Latest commit to master - php: 7.3 - env: STABILITY="dev" + env: STABILITY="dev" DEPENDENCIES="php-http/vcr-plugin:^1.0@dev" allow_failures: # dev stability is allowed to fail. diff --git a/composer.json b/composer.json index 29baffc5..73b8c60b 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,6 @@ "php-http/guzzle6-adapter": "^1.1.1 || ^2.0.1", "php-http/mock-client": "^1.2", "php-http/promise": "^1.0", - "php-http/vcr-plugin": "^1.0@dev", "polishsymfonycommunity/symfony-mocker-container": "^1.0", "symfony/browser-kit": "^3.4.20 || ^4.0.15 || ^4.1.9 || ^4.2.1", "symfony/cache": "^3.4.20 || ^4.0.15 || ^4.1.9 || ^4.2.1", diff --git a/tests/Unit/DependencyInjection/HttplugExtensionTest.php b/tests/Unit/DependencyInjection/HttplugExtensionTest.php index 397f813a..8b2757f7 100644 --- a/tests/Unit/DependencyInjection/HttplugExtensionTest.php +++ b/tests/Unit/DependencyInjection/HttplugExtensionTest.php @@ -457,6 +457,10 @@ public function testBatchClientCanBePublic() */ public function testVcrPluginConfiguration(array $config, array $services, array $arguments = []) { + if (!class_exists(\Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder::class)) { + $this->markTestSkipped('VCR plugin is not installed.'); + } + $prefix = 'httplug.client.acme.vcr'; $this->load(['clients' => ['acme' => ['plugins' => [['vcr' => $config]]]]]); $this->assertContainerBuilderHasService('httplug.plugin.vcr.recorder.in_memory', InMemoryRecorder::class); @@ -477,6 +481,10 @@ public function testVcrPluginConfiguration(array $config, array $services, array */ public function testIsNotLoadedUnlessNeeded() { + if (!class_exists(\Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder::class)) { + $this->markTestSkipped('VCR plugin is not installed.'); + } + $this->load(['clients' => ['acme' => ['plugins' => []]]]); $this->assertContainerBuilderNotHasService('httplug.plugin.vcr.recorder.in_memory'); }