Skip to content

Commit 80ace96

Browse files
authored
Allow PHP 8 (#389)
1 parent 1e9a170 commit 80ace96

File tree

18 files changed

+126
-31
lines changed

18 files changed

+126
-31
lines changed

.travis.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
- SYMFONY_PHPUNIT_VERSION="8"
1414
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
1515
- SYMFONY_DEPRECATIONS_HELPER="max[self]=0"
16+
- DEPENDENCIES="php-http/guzzle7-adapter"
1617

1718
branches:
1819
except:
@@ -22,14 +23,14 @@ matrix:
2223
fast_finish: true
2324
include:
2425
# Minimum supported Symfony version and lowest PHP version
25-
- php: 7.2
26-
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak"
26+
- php: 7.3
27+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak" DEPENDENCIES="php-http/guzzle6-adapter"
2728

2829
# Test the latest stable release
29-
- php: 7.2
3030
- php: 7.3
31-
env: COVERAGE=true TEST_COMMAND="composer test-ci" DEPENDENCIES="php-http/vcr-plugin:^1.0@dev"
31+
env: COVERAGE=true TEST_COMMAND="composer test-ci" DEPENDENCIES="php-http/guzzle7-adapter php-http/vcr-plugin:^1.0@dev"
3232
- php: 7.4
33+
- php: 8.0
3334

3435
# Test LTS versions
3536
- php: 7.3
@@ -39,21 +40,23 @@ matrix:
3940
- php: 7.3
4041
env: SYMFONY_REQUIRE=4.3.*
4142
- php: 7.3
42-
env: SYMFONY_REQUIRE=4.4.* DEPENDENCIES="symfony/http-client:^4.4"
43+
env: SYMFONY_REQUIRE=4.4.* DEPENDENCIES="php-http/guzzle7-adapter symfony/http-client:^4.4"
4344
- php: 7.3
44-
env: SYMFONY_REQUIRE=5.0.* DEPENDENCIES="symfony/http-client:^5.0"
45+
env: SYMFONY_REQUIRE=5.0.* DEPENDENCIES="php-http/guzzle7-adapter symfony/http-client:^5.0"
4546

4647
# Test with httplug 1.x clients
47-
- php: 7.2
48+
- php: 7.3
4849
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"
4950

5051
# Test with httplug 2.x clients
51-
- php: 7.2
52-
env: DEPENDENCIES="php-http/guzzle6-adapter:^2.0.1 php-http/curl-client:^2.0.0 php-http/vcr-plugin:^1.0@dev"
52+
- php: 7.3
53+
env: DEPENDENCIES="php-http/guzzle7-adapter php-http/curl-client:^2.0.0 php-http/vcr-plugin:^1.0@dev"
5354

5455
# Latest commit to master
5556
- php: 7.4
56-
env: STABILITY="dev" DEPENDENCIES="php-http/vcr-plugin:^1.0@dev"
57+
env: STABILITY="dev" DEPENDENCIES="php-http/guzzle7-adapter php-http/vcr-plugin:^1.0@dev"
58+
- php: 8.0
59+
env: STABILITY="dev"
5760

5861
allow_failures:
5962
# dev stability is allowed to fail.
@@ -67,7 +70,6 @@ before_install:
6770

6871
install:
6972
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
70-
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
7173
- COMPOSER_MEMORY_LIMIT=-1 composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
7274
- vendor/bin/simple-phpunit install
7375

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
# 1.20.0 - to be released
6+
7+
- Support PHP 8.
8+
59
## 1.19.0 - 2020-10-21
610

711
### Changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Please see the [official documentation](http://docs.php-http.org/en/latest/integ
2828
## Testing
2929

3030
``` bash
31+
$ composer require --dev php-http/guzzle7-adapter
3132
$ composer test
3233
```
3334

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
}
2626
],
2727
"require": {
28-
"php": "^7.2",
28+
"php": "^7.3 || ^8.0",
2929
"php-http/client-common": "^1.9 || ^2.0",
3030
"php-http/client-implementation": "^1.0",
3131
"php-http/discovery": "^1.0",
@@ -46,11 +46,11 @@
4646
"php-http/curl-client": "<2.0"
4747
},
4848
"require-dev": {
49+
"guzzlehttp/psr7": "^1.7",
4950
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
5051
"nyholm/nsa": "^1.1",
5152
"nyholm/psr7": "^1.2.1",
5253
"php-http/cache-plugin": "^1.7",
53-
"php-http/guzzle6-adapter": "^1.1.1 || ^2.0.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 <[email protected]>
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/guzzle7-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/DiscoveredClientsTest.php

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

55
namespace Http\HttplugBundle\Tests\Functional;
66

7+
use Http\Adapter\Guzzle7\Client;
78
use Http\Client\HttpAsyncClient;
89
use Http\Client\HttpClient;
910
use Http\Discovery\HttpAsyncClientDiscovery;
@@ -101,6 +102,10 @@ public function testDisabledDiscovery(): void
101102
*/
102103
public function testForcedDiscovery(): void
103104
{
105+
if (!class_exists(Client::class)) {
106+
$this->markTestSkipped('Guzzle7 adapter is not installed');
107+
}
108+
104109
$container = $this->getContainer(true, 'discovery_forced');
105110

106111
$this->assertFalse($container->has('httplug.auto_discovery.auto_discovered_client'));

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/Functional/ServiceInstantiationTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Http\HttplugBundle\Tests\Functional;
66

77
use GuzzleHttp\Psr7\Request as GuzzleRequest;
8+
use Http\Adapter\Guzzle7\Client;
89
use Http\Client\Common\Plugin\RedirectPlugin;
910
use Http\Client\Common\PluginClient;
1011
use Http\Client\HttpClient;
@@ -29,6 +30,10 @@ class ServiceInstantiationTest extends WebTestCase
2930
{
3031
public function testHttpClient(): void
3132
{
33+
if (!class_exists(Client::class)) {
34+
$this->markTestSkipped('Guzzle7 adapter is not installed');
35+
}
36+
3237
static::bootKernel();
3338
$container = static::$kernel->getContainer();
3439
$this->assertTrue($container->has('httplug.client'));
@@ -38,6 +43,10 @@ public function testHttpClient(): void
3843

3944
public function testHttpClientNoDebug(): void
4045
{
46+
if (!class_exists(Client::class)) {
47+
$this->markTestSkipped('Guzzle7 adapter is not installed');
48+
}
49+
4150
static::bootKernel(['debug' => false]);
4251
$container = static::$kernel->getContainer();
4352
$this->assertTrue($container->has('httplug.client'));
@@ -70,6 +79,10 @@ public function testProfilingShouldNotChangeServiceReference(): void
7079

7180
public function testProfilingDecoration(): void
7281
{
82+
if (!class_exists(Client::class)) {
83+
$this->markTestSkipped('Guzzle7 adapter is not installed');
84+
}
85+
7386
static::bootKernel(['debug' => true]);
7487
$container = static::$kernel->getContainer();
7588

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 <[email protected]>
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ public function testOnException(): void
179179

180180
public function testOnError(): void
181181
{
182-
$this->expectException(Warning::class);
182+
if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
183+
$this->expectException(\DivisionByZeroError::class);
184+
} else {
185+
$this->expectException(Warning::class);
186+
}
183187

184188
$this->collector
185189
->expects($this->once())

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 8 additions & 4 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;
@@ -128,6 +128,10 @@ public function testEmptyConfiguration(): void
128128

129129
public function testSupportsAllConfigFormats(): void
130130
{
131+
if (!class_exists(Client::class)) {
132+
$this->markTestSkipped('Guzzle 7 adapter is not installed');
133+
}
134+
131135
$expectedConfiguration = [
132136
'default_client_autowiring' => false,
133137
'main_alias' => [
@@ -158,7 +162,7 @@ public function testSupportsAllConfigFormats(): void
158162
],
159163
'clients' => [
160164
'test' => [
161-
'factory' => 'httplug.factory.guzzle6',
165+
'factory' => 'httplug.factory.guzzle7',
162166
'http_methods_client' => true,
163167
'service' => null,
164168
'public' => null,
@@ -435,7 +439,7 @@ public function testClientCacheConfigMustHavePool(): void
435439
$file = __DIR__.'/../../Resources/Fixtures/config/client_cache_config_with_no_pool.yml';
436440

437441
$this->expectException(InvalidConfigurationException::class);
438-
$this->expectExceptionMessage('The child node "cache_pool" at path "httplug.clients.test.plugins.0.cache" must be configured.');
442+
$this->expectExceptionMessage('httplug.clients.test.plugins.0.cache');
439443
$this->assertProcessedConfigurationEquals([], [$file]);
440444
}
441445

@@ -444,7 +448,7 @@ public function testCacheConfigMustHavePool(): void
444448
$file = __DIR__.'/../../Resources/Fixtures/config/cache_config_with_no_pool.yml';
445449

446450
$this->expectException(InvalidConfigurationException::class);
447-
$this->expectExceptionMessage('The child node "cache_pool" at path "httplug.plugins.cache" must be configured.');
451+
$this->expectExceptionMessage('cache_pool');
448452
$this->assertProcessedConfigurationEquals([], [$file]);
449453
}
450454

0 commit comments

Comments
 (0)