Skip to content

Commit

Permalink
[6.5] Install symfony's intl-idn polyfill (#2550)
Browse files Browse the repository at this point in the history
* Install symfony's intl-idn polyfill

* idn conversion always available

* remove "skipped because of intl"

* PHPStan CI fix

Co-authored-by: Nyholm <tobias.nyholm@gmail.com>
  • Loading branch information
GrahamCampbell and Nyholm committed Apr 15, 2020
1 parent 9189d46 commit 3325c9d
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/static.yml
Expand Up @@ -17,6 +17,8 @@ jobs:

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
env:
REQUIRE_DEV: true
with:
args: analyze --no-progress

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -23,6 +23,7 @@
"require": {
"php": ">=5.5",
"ext-json": "*",
"symfony/polyfill-intl-idn": "^1.11",
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.6.1"
},
Expand All @@ -32,8 +33,7 @@
"psr/log": "^1.1"
},
"suggest": {
"psr/log": "Required for using the Log middleware",
"ext-intl": "Required for Internationalized Domain Name (IDN) support"
"psr/log": "Required for using the Log middleware"
},
"config": {
"sort-packages": true
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Expand Up @@ -5,4 +5,3 @@ parameters:
level: max
paths:
- src
bootstrap: tests/bootstrap-phpstan.php
13 changes: 2 additions & 11 deletions src/Client.php
Expand Up @@ -236,19 +236,10 @@ private function configureDefaults(array $config)
'http_errors' => true,
'decode_content' => true,
'verify' => true,
'cookies' => false
'cookies' => false,
'idn_conversion' => true,
];

// idn_to_ascii() is a part of ext-intl and might be not available
$defaults['idn_conversion'] = function_exists('idn_to_ascii')
// Old ICU versions don't have this constant, so we are basically stuck (see https://github.com/guzzle/guzzle/pull/2424
// and https://github.com/guzzle/guzzle/issues/2448 for details)
&& (
defined('INTL_IDNA_VARIANT_UTS46')
||
PHP_VERSION_ID < 70200
);

// Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set.

// We can only trust the HTTP_PROXY environment variable in a CLI
Expand Down
19 changes: 1 addition & 18 deletions tests/ClientTest.php
Expand Up @@ -721,18 +721,11 @@ public function testIdnSupportDefaultValue()

$config = $client->getConfig();

if (extension_loaded('intl')) {
self::assertTrue($config['idn_conversion']);
} else {
self::assertFalse($config['idn_conversion']);
}
self::assertTrue($config['idn_conversion']);
}

public function testIdnIsTranslatedToAsciiWhenConversionIsEnabled()
{
if (!extension_loaded('intl')) {
self::markTestSkipped('intl PHP extension is not loaded');
}
$mockHandler = new MockHandler([new Response()]);
$client = new Client(['handler' => $mockHandler]);

Expand Down Expand Up @@ -763,9 +756,6 @@ public function testIdnStaysTheSameWhenConversionIsDisabled()
*/
public function testExceptionOnInvalidIdn()
{
if (!extension_loaded('intl')) {
self::markTestSkipped('intl PHP extension is not loaded');
}
$mockHandler = new MockHandler([new Response()]);
$client = new Client(['handler' => $mockHandler]);

Expand All @@ -778,10 +768,6 @@ public function testExceptionOnInvalidIdn()
*/
public function testIdnBaseUri()
{
if (!extension_loaded('intl')) {
self::markTestSkipped('intl PHP extension is not loaded');
}

$mock = new MockHandler([new Response()]);
$client = new Client([
'handler' => $mock,
Expand All @@ -796,9 +782,6 @@ public function testIdnBaseUri()

public function testIdnWithRedirect()
{
if (!extension_loaded('intl')) {
self::markTestSkipped('intl PHP extension is not loaded');
}
$mockHandler = new MockHandler([
new Response(302, ['Location' => 'http://www.tést.com/whatever']),
new Response()
Expand Down
4 changes: 0 additions & 4 deletions tests/InternalUtilsTest.php
Expand Up @@ -14,10 +14,6 @@ public function testCurrentTime()

public function testIdnConvert()
{
if (!extension_loaded('intl')) {
self::markTestSkipped('intl PHP extension is not loaded');
}

$uri = Psr7\uri_for('https://яндекс.рф/images');
$uri = Utils::idnUriConvert($uri);
self::assertSame('xn--d1acpjx3f.xn--p1ai', $uri->getHost());
Expand Down
9 changes: 0 additions & 9 deletions tests/bootstrap-phpstan.php

This file was deleted.

0 comments on commit 3325c9d

Please sign in to comment.