Skip to content

Commit b2808bc

Browse files
committed
Support both guzzle6 and guzzle7-adapter
1 parent 068cd2e commit b2808bc

File tree

13 files changed

+75
-17
lines changed

13 files changed

+75
-17
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"nyholm/nsa": "^1.1",
5151
"nyholm/psr7": "^1.2.1",
5252
"php-http/cache-plugin": "^1.7",
53-
"php-http/guzzle6-adapter": "^1.1.1 || ^2.0.1",
53+
"php-http/guzzle7-adapter": "^0.1.1",
5454
"php-http/mock-client": "^1.2",
5555
"php-http/promise": "^1.0",
5656
"polishsymfonycommunity/symfony-mocker-container": "^1.0",

src/ClientFactory/Guzzle7Factory.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Http\HttplugBundle\ClientFactory;
6+
7+
use Http\Adapter\Guzzle7\Client;
8+
9+
/**
10+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
11+
*/
12+
class Guzzle7Factory implements ClientFactory
13+
{
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
public function createClient(array $config = [])
18+
{
19+
if (!class_exists('Http\Adapter\Guzzle7\Client')) {
20+
throw new \LogicException('To use the Guzzle7 adapter you need to install the "php-http/guzzle6-adapter" package.');
21+
}
22+
23+
return Client::createWithConfig($config);
24+
}
25+
}

src/Resources/config/data-collector.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
<argument type="service" id="httplug.collector.formatter"/>
7373
<argument type="service" id="debug.stopwatch"/>
7474
</service>
75+
<service id="httplug.collector.factory.guzzle7" class="Http\HttplugBundle\Collector\ProfileClientFactory" decorates="httplug.factory.guzzle7" public="false">
76+
<argument type="service" id="httplug.collector.factory.guzzle7.inner"/>
77+
<argument type="service" id="httplug.collector.collector"/>
78+
<argument type="service" id="httplug.collector.formatter"/>
79+
<argument type="service" id="debug.stopwatch"/>
80+
</service>
7581
<service id="httplug.collector.factory.react" class="Http\HttplugBundle\Collector\ProfileClientFactory" decorates="httplug.factory.react" public="false">
7682
<argument type="service" id="httplug.collector.factory.react.inner"/>
7783
<argument type="service" id="httplug.collector.collector"/>

src/Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<argument type="service" id="httplug.message_factory"/>
9191
</service>
9292
<service id="httplug.factory.guzzle6" class="Http\HttplugBundle\ClientFactory\Guzzle6Factory" public="false" />
93+
<service id="httplug.factory.guzzle7" class="Http\HttplugBundle\ClientFactory\Guzzle7Factory" public="false" />
9394
<service id="httplug.factory.react" class="Http\HttplugBundle\ClientFactory\ReactFactory" public="false">
9495
<argument type="service" id="httplug.message_factory"/>
9596
</service>

tests/Functional/DiscoveryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

7-
use Http\Adapter\Guzzle6\Client;
7+
use Http\Adapter\Guzzle7\Client;
88
use Http\Client\HttpAsyncClient;
99
use Http\Client\HttpClient;
1010
use Http\Discovery\HttpClientDiscovery;

tests/Resources/Fixtures/config/full.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
'stream_factory' => 'my_stream_factory',
1212
],
1313
'classes' => [
14-
'client' => 'Http\Adapter\Guzzle6\Client',
14+
'client' => 'Http\Adapter\Guzzle7\Client',
1515
'message_factory' => 'Http\Message\MessageFactory\GuzzleMessageFactory',
1616
'uri_factory' => 'Http\Message\UriFactory\GuzzleUriFactory',
1717
'stream_factory' => 'Http\Message\StreamFactory\GuzzleStreamFactory',
18-
'psr18_client' => 'Http\Adapter\Guzzle6\Client',
18+
'psr18_client' => 'Http\Adapter\Guzzle7\Client',
1919
'psr17_request_factory' => 'Nyholm\Psr7\Factory\Psr17Factory',
2020
'psr17_response_factory' => 'Nyholm\Psr7\Factory\Psr17Factory',
2121
'psr17_stream_factory' => 'Nyholm\Psr7\Factory\Psr17Factory',
@@ -25,7 +25,7 @@
2525
],
2626
'clients' => [
2727
'test' => [
28-
'factory' => 'httplug.factory.guzzle6',
28+
'factory' => 'httplug.factory.guzzle7',
2929
'http_methods_client' => true,
3030
'plugins' => [
3131
'httplug.plugin.redirect',

tests/Resources/Fixtures/config/full.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
<stream-factory>my_stream_factory</stream-factory>
1111
</main-alias>
1212
<classes>
13-
<client>Http\Adapter\Guzzle6\Client</client>
13+
<client>Http\Adapter\Guzzle7\Client</client>
1414
<message-factory>Http\Message\MessageFactory\GuzzleMessageFactory</message-factory>
1515
<uri-factory>Http\Message\UriFactory\GuzzleUriFactory</uri-factory>
1616
<stream-factory>Http\Message\StreamFactory\GuzzleStreamFactory</stream-factory>
17-
<psr18-client>Http\Adapter\Guzzle6\Client</psr18-client>
17+
<psr18-client>Http\Adapter\Guzzle7\Client</psr18-client>
1818
<psr17-request-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-request-factory>
1919
<psr17-response-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-response-factory>
2020
<psr17-stream-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-stream-factory>
2121
<psr17-uri-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-uri-factory>
2222
<psr17-uploaded-file-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-uploaded-file-factory>
2323
<psr17-server-request-factory>Nyholm\Psr7\Factory\Psr17Factory</psr17-server-request-factory>
2424
</classes>
25-
<client name="test" factory="httplug.factory.guzzle6" http-methods-client="true">
25+
<client name="test" factory="httplug.factory.guzzle7" http-methods-client="true">
2626
<plugin>httplug.plugin.redirect</plugin>
2727
<plugin>
2828
<add-host host="http://localhost"/>

tests/Resources/Fixtures/config/full.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ httplug:
66
uri_factory: my_uri_factory
77
stream_factory: my_stream_factory
88
classes:
9-
client: Http\Adapter\Guzzle6\Client
9+
client: Http\Adapter\Guzzle7\Client
1010
message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
1111
uri_factory: Http\Message\UriFactory\GuzzleUriFactory
1212
stream_factory: Http\Message\StreamFactory\GuzzleStreamFactory
13-
psr18_client: Http\Adapter\Guzzle6\Client
13+
psr18_client: Http\Adapter\Guzzle7\Client
1414
psr17_request_factory: Nyholm\Psr7\Factory\Psr17Factory
1515
psr17_response_factory: Nyholm\Psr7\Factory\Psr17Factory
1616
psr17_stream_factory: Nyholm\Psr7\Factory\Psr17Factory
@@ -19,7 +19,7 @@ httplug:
1919
psr17_server_request_factory: Nyholm\Psr7\Factory\Psr17Factory
2020
clients:
2121
test:
22-
factory: httplug.factory.guzzle6
22+
factory: httplug.factory.guzzle7
2323
http_methods_client: true
2424
plugins:
2525
- 'httplug.plugin.redirect'

tests/Resources/app/config/config_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ httplug:
77
async_client: auto
88
clients:
99
acme:
10-
factory: httplug.factory.guzzle6
10+
factory: httplug.factory.guzzle7
1111
plugins:
1212
-
1313
decoder:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Http\HttplugBundle\Tests\Unit\ClientFactory;
6+
7+
use Http\Adapter\Guzzle7\Client;
8+
use Http\HttplugBundle\ClientFactory\Guzzle7Factory;
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
13+
*/
14+
class Guzzle7FactoryTest extends TestCase
15+
{
16+
public function testCreateClient(): void
17+
{
18+
if (!class_exists(Client::class)) {
19+
$this->markTestSkipped('Guzzle7 adapter is not installed');
20+
}
21+
22+
$factory = new Guzzle7Factory();
23+
$client = $factory->createClient();
24+
25+
$this->assertInstanceOf(Client::class, $client);
26+
}
27+
}

tests/Unit/Collector/StackPluginTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Http\HttplugBundle\Collector\StackPlugin;
1414
use Http\Promise\FulfilledPromise;
1515
use Http\Promise\RejectedPromise;
16-
use PHPUnit\Framework\Error\Warning;
1716
use PHPUnit\Framework\TestCase;
1817
use Psr\Http\Message\RequestInterface;
1918
use Psr\Http\Message\ResponseInterface;
@@ -179,7 +178,7 @@ public function testOnException(): void
179178

180179
public function testOnError(): void
181180
{
182-
$this->expectException(Warning::class);
181+
$this->expectExceptionMessage('Division by zero');
183182

184183
$this->collector
185184
->expects($this->once())

tests/Unit/DependencyInjection/ConfigurationTest.php

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

55
namespace Http\HttplugBundle\Tests\Unit\DependencyInjection;
66

7-
use Http\Adapter\Guzzle6\Client;
7+
use Http\Adapter\Guzzle7\Client;
88
use Http\HttplugBundle\DependencyInjection\Configuration;
99
use Http\HttplugBundle\DependencyInjection\HttplugExtension;
1010
use Http\Message\MessageFactory\GuzzleMessageFactory;
@@ -158,7 +158,7 @@ public function testSupportsAllConfigFormats(): void
158158
],
159159
'clients' => [
160160
'test' => [
161-
'factory' => 'httplug.factory.guzzle6',
161+
'factory' => 'httplug.factory.guzzle7',
162162
'http_methods_client' => true,
163163
'service' => null,
164164
'public' => null,

tests/Unit/DependencyInjection/HttplugExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Http\HttplugBundle\Tests\Unit\DependencyInjection;
66

7-
use Http\Adapter\Guzzle6\Client;
7+
use Http\Adapter\Guzzle7\Client;
88
use Http\Client\HttpClient;
99
use Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder;
1010
use Http\HttplugBundle\Collector\PluginClientFactoryListener;

0 commit comments

Comments
 (0)