Skip to content

Commit

Permalink
Add tests/Handler/Network/StreamHandlerTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWolla committed Mar 14, 2022
1 parent b17fb3c commit 35b5a09
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/Handler/Network/StreamHandlerTest.php
@@ -0,0 +1,71 @@
<?php

namespace GuzzleHttp\Test\Handler\Network;

use GuzzleHttp\Client;
use GuzzleHttp\Handler\StreamHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use PHPUnit\Framework\TestCase;

/**
* @covers \GuzzleHttp\Handler\StreamHandler
*/
class StreamHandlerTest extends TestCase
{
public function setUp(): void
{
if (!($_SERVER['GUZZLE_TEST_ALLOW_NETWORK'] ?? false)) {
self::markTestSkipped("This test requires the GUZZLE_TEST_ALLOW_NETWORK environment variable.");
}
}

public function testSslRequestWorks()
{
$handler = new StreamHandler();

$response = $handler(
new Request('GET', 'https://www.example.com/'),
[
RequestOptions::STREAM => true,
]
)->wait();

self::assertSame(200, $response->getStatusCode());
self::assertStringContainsString('<h1>Example Domain</h1>', (string)$response->getBody());
}

public function testSslRequestWorksWithForceIpResolve()
{
$handler = new StreamHandler();

$response = $handler(
new Request('GET', 'https://www.example.com/'),
[
RequestOptions::STREAM => true,
'force_ip_resolve' => 'v4',
]
)->wait();

self::assertSame(200, $response->getStatusCode());
self::assertStringContainsString('<h1>Example Domain</h1>', (string)$response->getBody());
}

public function testSslRequestWorksWithForceIpResolveAfterRedirect()
{
$client = new Client(['handler' => HandlerStack::create(new StreamHandler())]);

$response = $client->send(
// Redirects to https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun.
new Request('GET', 'https://git.io/JvXDl'),
[
RequestOptions::STREAM => true,
'force_ip_resolve' => 'v4',
]
);

self::assertSame(200, $response->getStatusCode());
self::assertStringContainsString('jobsjob_idstepsrun', (string)$response->getBody());
}
}

0 comments on commit 35b5a09

Please sign in to comment.