Skip to content

Commit aed7e5a

Browse files
authored
Merge pull request #339 from shulard/compatibility/curl-client-v2
Add compatibility with curl-client v2 (now relying on PSR17 factories)
2 parents cb15a25 + 4cc03fa commit aed7e5a

File tree

6 files changed

+43
-29
lines changed

6 files changed

+43
-29
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ matrix:
2828
- php: 7.1
2929
- php: 7.2
3030
- php: 7.3
31-
env: COVERAGE=true TEST_COMMAND="composer test-ci"
31+
env: COVERAGE=true TEST_COMMAND="composer test-ci" DEPENDENCIES="php-http/vcr-plugin:^1.0@dev"
3232

3333
# Test LTS versions
3434
- php: 7.3
@@ -38,15 +38,15 @@ matrix:
3838

3939
# Test with httplug 1.x clients
4040
- php: 7.2
41-
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"
41+
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"
4242

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

4747
# Latest commit to master
4848
- php: 7.3
49-
env: STABILITY="dev"
49+
env: STABILITY="dev" DEPENDENCIES="php-http/vcr-plugin:^1.0@dev"
5050

5151
allow_failures:
5252
# dev stability is allowed to fail.

CHANGELOG.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
1212
### Added
1313

1414
- Integration for VCR Plugin
15+
- curl-client v1.* is marked in conflict with the current bundle version.
16+
17+
### Fixed
18+
19+
- Fix compatibility with curl-client v2.*, the `CurlFactory` now build the
20+
client using PSR17 factories.
1521

1622
## 1.15.2 - 2019-04-18
1723

1824
### Fixed
1925

20-
- Fix to pass only allowed options to the `ContentTypePlugin`.
26+
- Fix to pass only allowed options to the `ContentTypePlugin`.
2127

2228
## 1.15.1 - 2019-04-12
2329

@@ -34,7 +40,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
3440
(Only available with Httplug 2)
3541
- Configuration for the content_type plugin
3642
- Support for namespaced Twig classes.
37-
- Configuration option default_client_autowiring that you can set to false
43+
- Configuration option default_client_autowiring that you can set to false
3844
to prevent autowiring the HttpClient and HttpAsyncClient
3945

4046
### Changed
@@ -58,7 +64,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
5864

5965
### Added
6066

61-
- Support for any PSR-18 client.
67+
- Support for any PSR-18 client.
6268

6369
### Changed
6470

@@ -100,14 +106,14 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
100106
## 1.10.0 - 2018-03-27
101107

102108
### Added
103-
109+
104110
- Allow to configure the `AddPathPlugin` per client, under the `add_path` configuration key.
105-
- Allow to configure clients with a `service` instead of a factory.
111+
- Allow to configure clients with a `service` instead of a factory.
106112

107113
## 1.9.0 - 2018-03-06
108114

109115
### Added
110-
116+
111117
- Allow to configure the `BaseUriPlugin` per client, under the `base_uri` configuration key.
112118

113119
## 1.8.1 - 2017-12-06
@@ -120,7 +126,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
120126

121127
### Added
122128

123-
- Symfony 4 support.
129+
- Symfony 4 support.
124130
- Support autowiring of `Http\Client\Common\PluginClientFactory`.
125131
- Any third party library using `Http\Client\Common\PluginClientFactory` to create `Http\Client\Common\PluginClient`
126132
instances now gets zero config profiling.
@@ -170,8 +176,8 @@ services aliases for autowiring in Symfony 3.3.
170176

171177
### Changed
172178

173-
- We do collect profiler data after the request is processed by a plugin. With this change we
174-
will for example see the changes of `HeaderAppendPlugin` at that plugin instead of the next one.
179+
- We do collect profiler data after the request is processed by a plugin. With this change we
180+
will for example see the changes of `HeaderAppendPlugin` at that plugin instead of the next one.
175181

176182
## 1.5.0 - 2017-05-05
177183

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"symfony/options-resolver": "^3.4.20 || ^4.2.1"
4343
},
4444
"conflict": {
45-
"php-http/guzzle6-adapter": "<1.1"
45+
"php-http/guzzle6-adapter": "<1.1",
46+
"php-http/curl-client": "<2.0"
4647
},
4748
"require-dev": {
4849
"guzzlehttp/psr7": "^1.0",
@@ -52,7 +53,6 @@
5253
"php-http/guzzle6-adapter": "^1.1.1 || ^2.0.1",
5354
"php-http/mock-client": "^1.2",
5455
"php-http/promise": "^1.0",
55-
"php-http/vcr-plugin": "^1.0@dev",
5656
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
5757
"symfony/browser-kit": "^3.4.20 || ^4.2.1",
5858
"symfony/cache": "^3.4.20 || ^4.2.1",

src/ClientFactory/CurlFactory.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@
33
namespace Http\HttplugBundle\ClientFactory;
44

55
use Http\Client\Curl\Client;
6-
use Http\Message\MessageFactory;
7-
use Http\Message\StreamFactory;
6+
use Psr\Http\Message\ResponseFactoryInterface;
7+
use Psr\Http\Message\StreamFactoryInterface;
88

99
/**
1010
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
1111
*/
1212
class CurlFactory implements ClientFactory
1313
{
1414
/**
15-
* @var MessageFactory
15+
* @var ResponseFactoryInterface
1616
*/
17-
private $messageFactory;
17+
private $responseFactory;
1818

1919
/**
20-
* @var StreamFactory
20+
* @var StreamFactoryInterface
2121
*/
2222
private $streamFactory;
2323

2424
/**
25-
* @param MessageFactory $messageFactory
26-
* @param StreamFactory $streamFactory
25+
* @param ResponseFactoryInterface $responseFactory
26+
* @param StreamFactoryInterface $streamFactory
2727
*/
28-
public function __construct(MessageFactory $messageFactory, StreamFactory $streamFactory)
28+
public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
2929
{
30-
$this->messageFactory = $messageFactory;
30+
$this->responseFactory = $responseFactory;
3131
$this->streamFactory = $streamFactory;
3232
}
3333

@@ -53,6 +53,6 @@ public function createClient(array $config = [])
5353
}
5454
}
5555

56-
return new Client($this->messageFactory, $this->streamFactory, $config);
56+
return new Client($this->responseFactory, $this->streamFactory, $config);
5757
}
5858
}

tests/Unit/ClientFactory/CurlFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use Http\HttplugBundle\ClientFactory\CurlFactory;
66
use Http\Client\Curl\Client;
7-
use Http\Message\MessageFactory;
8-
use Http\Message\StreamFactory;
97
use PHPUnit\Framework\TestCase;
8+
use Psr\Http\Message\ResponseFactoryInterface;
9+
use Psr\Http\Message\StreamFactoryInterface;
1010

1111
/**
1212
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
@@ -20,8 +20,8 @@ public function testCreateClient()
2020
}
2121

2222
$factory = new CurlFactory(
23-
$this->getMockBuilder(MessageFactory::class)->getMock(),
24-
$this->getMockBuilder(StreamFactory::class)->getMock()
23+
$this->getMockBuilder(ResponseFactoryInterface::class)->getMock(),
24+
$this->getMockBuilder(StreamFactoryInterface::class)->getMock()
2525
);
2626
$client = $factory->createClient();
2727

tests/Unit/DependencyInjection/HttplugExtensionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,10 @@ public function testBatchClientCanBePublic()
457457
*/
458458
public function testVcrPluginConfiguration(array $config, array $services, array $arguments = [])
459459
{
460+
if (!class_exists(\Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder::class)) {
461+
$this->markTestSkipped('VCR plugin is not installed.');
462+
}
463+
460464
$prefix = 'httplug.client.acme.vcr';
461465
$this->load(['clients' => ['acme' => ['plugins' => [['vcr' => $config]]]]]);
462466
$this->assertContainerBuilderHasService('httplug.plugin.vcr.recorder.in_memory', InMemoryRecorder::class);
@@ -477,6 +481,10 @@ public function testVcrPluginConfiguration(array $config, array $services, array
477481
*/
478482
public function testIsNotLoadedUnlessNeeded()
479483
{
484+
if (!class_exists(\Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder::class)) {
485+
$this->markTestSkipped('VCR plugin is not installed.');
486+
}
487+
480488
$this->load(['clients' => ['acme' => ['plugins' => []]]]);
481489
$this->assertContainerBuilderNotHasService('httplug.plugin.vcr.recorder.in_memory');
482490
}

0 commit comments

Comments
 (0)