Skip to content

Add compatibility with curl-client v2 (now relying on PSR17 factories) #339

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 4 commits into from
Jun 5, 2019
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
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,15 +38,15 @@ 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 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.
Expand Down
24 changes: 15 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -52,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",
Expand Down
20 changes: 10 additions & 10 deletions src/ClientFactory/CurlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
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 <tobias.nyholm@gmail.com>
*/
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;
}

Expand All @@ -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);
}
}
8 changes: 4 additions & 4 deletions tests/Unit/ClientFactory/CurlFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tobias.nyholm@gmail.com>
Expand All @@ -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();

Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/DependencyInjection/HttplugExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
}
Expand Down