Skip to content

Commit

Permalink
Add tests around usage of http_proxy option
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed Feb 25, 2019
1 parent ef58615 commit e04f892
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/ClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,25 @@ public function testCreateWithHttpProxyAndCustomTransportThrowsException(): void

$clientBuilder->getClient();
}

public function testCreateWithHttpProxyThrowsExceptionIfCurlClientIsMissing(): void
{
if (class_exists(\Http\Client\Curl\Client::class)) {
$this->markTestSkipped('This test works only if the Curl client is not installed');
}

$options = new Options([
'dsn' => 'http://public:secret@example.com/sentry/1',
'http_proxy' => 'some-proxy',
]);

$clientBuilder = new ClientBuilder($options);

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('The `http_proxy` option requires the `php-http/curl-client` package to be installed.');

$clientBuilder->getClient();
}
}

final class StubIntegration implements IntegrationInterface
Expand Down
55 changes: 55 additions & 0 deletions tests/phpt/http_proxy.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--TEST--
Test that the http_proxy option works
--FILE--
<?php

namespace Http\Client\Curl;

use Http\Promise\FulfilledPromise;
use function Sentry\init;
use Http\Client\HttpAsyncClient;
use Http\Promise\Promise;
use Psr\Http\Message\RequestInterface;
use Zend\Diactoros\Response;

$vendor = __DIR__;

while (! file_exists($vendor . '/vendor')) {
$vendor = dirname($vendor);
}

require $vendor . '/vendor/autoload.php';

class Client implements HttpAsyncClient
{
private $proxy;

/**
* Client constructor.
* @param $proxy
*/
public function __construct($a, $b, $c)
{
$this->proxy = $c[CURLOPT_PROXY];
}

public function sendAsyncRequest(RequestInterface $request): Promise
{
echo 'Handling with proxy ' . $this->proxy . PHP_EOL;

return new FulfilledPromise(new Response());
}
}

init([
'dsn' => 'http://public@example.com/',
'http_proxy' => '127.0.0.100',
]);

\Sentry\captureMessage('test');

echo 'Test concluded'
?>
--EXPECTF--
Handling with proxy 127.0.0.100
Test concluded

0 comments on commit e04f892

Please sign in to comment.