Skip to content

Commit

Permalink
Tests for base_uri
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyshockov committed Oct 24, 2019
1 parent ed0b4ab commit 8489090
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private function configureDefaults(array $config)
// We can only trust the HTTP_PROXY environment variable in a CLI
// process due to the fact that PHP has no reliable mechanism to
// get environment variables that start with "HTTP_".
if (php_sapi_name() == 'cli' && getenv('HTTP_PROXY')) {
if (php_sapi_name() === 'cli' && getenv('HTTP_PROXY')) {
$defaults['proxy']['http'] = getenv('HTTP_PROXY');
}

Expand Down
34 changes: 30 additions & 4 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,17 +697,21 @@ public function testResponseContent()
$this->assertSame($responseBody, $response->getBody()->getContents());
}

public function testIdnSupportIsEnabledByDefaultIfIntlExtensionIsAvailable()
public function testIdnSupportDefaultValue()
{
$mockHandler = new MockHandler([new Response()]);
$client = new Client(['handler' => $mockHandler]);

$config = $client->getConfig();

$this->assertTrue($config['idn_conversion']);
if (extension_loaded('intl')) {
$this->assertTrue($config['idn_conversion']);
} else {
$this->assertFalse($config['idn_conversion']);
}
}

public function testIdnIsTranslatedToAsciiWhenSupportIsEnabled()
public function testIdnIsTranslatedToAsciiWhenConversionIsEnabled()
{
$mockHandler = new MockHandler([new Response()]);
$client = new Client(['handler' => $mockHandler]);
Expand All @@ -720,7 +724,7 @@ public function testIdnIsTranslatedToAsciiWhenSupportIsEnabled()
$this->assertSame('xn--d1acpjx3f.xn--p1ai', (string) $request->getHeaderLine('Host'));
}

public function testIdnStaysTheSameWhenSupportIsDisabled()
public function testIdnStaysTheSameWhenConversionIsDisabled()
{
$mockHandler = new MockHandler([new Response()]);
$client = new Client(['handler' => $mockHandler]);
Expand All @@ -744,4 +748,26 @@ public function testExceptionOnInvalidIdn()

$client->request('GET', 'https://-яндекс.рф/images', ['idn_conversion' => true]);
}

/**
* @depends testCanUseRelativeUriWithSend
* @depends testIdnSupportDefaultValue
*/
public function testIdnBaseUri()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('intl PHP extension is not loaded');
}

$mock = new MockHandler([new Response()]);
$client = new Client([
'handler' => $mock,
'base_uri' => 'http://яндекс.рф',
]);
$this->assertSame('http://яндекс.рф', (string) $client->getConfig('base_uri'));
$request = new Request('GET', '/baz');
$client->send($request);
$this->assertSame('http://xn--d1acpjx3f.xn--p1ai/baz', (string) $mock->getLastRequest()->getUri());
$this->assertSame('xn--d1acpjx3f.xn--p1ai', (string) $mock->getLastRequest()->getHeaderLine('Host'));
}
}

0 comments on commit 8489090

Please sign in to comment.