From e04f892fda22ae32e88d9e840ded7ba1d7512615 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sat, 23 Feb 2019 01:07:27 +0100 Subject: [PATCH] Add tests around usage of http_proxy option --- tests/ClientBuilderTest.php | 19 +++++++++++++ tests/phpt/http_proxy.phpt | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 tests/phpt/http_proxy.phpt diff --git a/tests/ClientBuilderTest.php b/tests/ClientBuilderTest.php index 984b0ca14d..12a53fa707 100644 --- a/tests/ClientBuilderTest.php +++ b/tests/ClientBuilderTest.php @@ -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 diff --git a/tests/phpt/http_proxy.phpt b/tests/phpt/http_proxy.phpt new file mode 100644 index 0000000000..3de779bb5b --- /dev/null +++ b/tests/phpt/http_proxy.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test that the http_proxy option works +--FILE-- +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