Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTTPlug 2 / PSR-18 #777

Merged
merged 14 commits into from
Feb 25, 2019
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
"ext-mbstring": "*",
"jean85/pretty-package-versions": "^1.2",
"php-http/async-client-implementation": "^1.0",
"php-http/client-common": "^1.5",
"php-http/discovery": "^1.2",
"php-http/httplug": "^1.1",
"php-http/client-common": "^1.5|^2.0",
"php-http/discovery": "^1.6.1",
"php-http/httplug": "^1.1|^2.0",
"php-http/message": "^1.5",
"psr/http-message-implementation": "^1.0",
"ramsey/uuid": "^3.3",
"symfony/options-resolver": "^2.7|^3.0|^4.0",
Expand All @@ -32,8 +33,6 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.13",
"monolog/monolog": "^1.3",
"php-http/curl-client": "^1.7.1",
"php-http/message": "^1.5",
"php-http/mock-client": "^1.0",
"phpstan/phpstan-phpunit": "^0.10",
"phpstan/phpstan": "^0.10.3",
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ parameters:
- '/Argument of an invalid type object supplied for foreach, only iterables are supported/'
- '/Binary operation "\*" between array and 2 results in an error\./'
- '/Method Sentry\\Serializer\\RepresentationSerializer::(representationSerialize|serializeValue)\(\) should return [\w|]+ but returns [\w|]+/'
- '/Http\\Client\\Curl\\Client/'
excludes_analyse:
- tests/resources
includes:
Expand Down
11 changes: 6 additions & 5 deletions src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Http\Client\Common\PluginClient;
use Http\Client\Curl\Client as HttpCurlClient;
use Http\Client\HttpAsyncClient;
use Http\Discovery\ClassDiscovery;
use Http\Discovery\HttpAsyncClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Discovery\UriFactoryDiscovery;
Expand Down Expand Up @@ -321,13 +322,13 @@ private function createTransportInstance(): TransportInterface
throw new \RuntimeException('The `http_proxy` option does not work together with a custom client.');
}

if (HttpAsyncClientDiscovery::safeClassExists(HttpCurlClient::class)) {
$this->httpClient = new HttpCurlClient(null, null, [
CURLOPT_PROXY => $this->options->getHttpProxy(),
]);
} else {
if (!ClassDiscovery::safeClassExists(HttpCurlClient::class)) {
throw new \RuntimeException('The `http_proxy` option requires the `php-http/curl-client` package to be installed.');
}

$this->httpClient = new HttpCurlClient(null, null, [
CURLOPT_PROXY => $this->options->getHttpProxy(),
]);
}

$this->httpClient = $this->httpClient ?? HttpAsyncClientDiscovery::find();
Expand Down
5 changes: 3 additions & 2 deletions tests/ClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Http\Client\HttpAsyncClient;
use Http\Message\MessageFactory;
use Http\Message\UriFactory;
use Http\Promise\Promise;
use Jean85\PrettyVersions;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -317,14 +318,14 @@ public function setupOnce(): void

final class PluginStub1 implements Plugin
{
public function handleRequest(RequestInterface $request, callable $next, callable $first)
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
}
}

final class PluginStub2 implements Plugin
{
public function handleRequest(RequestInterface $request, callable $next, callable $first)
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
}
}
5 changes: 5 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

declare(strict_types=1);

use Http\Discovery\ClassDiscovery;
use Http\Discovery\Strategy\MockClientStrategy;

error_reporting(E_ALL | E_STRICT);

session_start();

require_once __DIR__ . '/../vendor/autoload.php';

ClassDiscovery::appendStrategy(MockClientStrategy::class);
5 changes: 1 addition & 4 deletions tests/phpt/fatal_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ while (!file_exists($vendor . '/vendor')) {

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

init([
'dsn' => 'http://public:secret@local.host/1',
'send_attempts' => 1,
]);
init();

ErrorHandler::addErrorListener(new StubErrorListener(function () {
echo 'Listener called';
Expand Down
26 changes: 12 additions & 14 deletions tests/phpt/out_of_memory.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Test catching out of memory fatal error
namespace Sentry\Tests;

use PHPUnit\Framework\Assert;
use Sentry\Event;
use Sentry\Severity;
use function Sentry\init;
use Sentry\State\Hub;

ini_set('memory_limit', '20M');

Expand All @@ -20,23 +21,20 @@ while (!file_exists($vendor . '/vendor')) {
require $vendor . '/vendor/autoload.php';

init([
'dsn' => 'http://public:secret@local.host/1',
'send_attempts' => 1,
]);

register_shutdown_function('register_shutdown_function', function () {
$client = Hub::getCurrent()->getClient();
'before_send' => function (Event $event): ?Event {
Assert::assertArrayHasKey(0, $event->getExceptions());
$error = $event->getExceptions()[0];
Jean85 marked this conversation as resolved.
Show resolved Hide resolved
Assert::assertContains('Allowed memory size', $error['value']);
Assert::assertTrue($event->getLevel()->isEqualTo(Severity::fatal()));

/** @var \Sentry\Transport\HttpTransport $transport */
$transport = Assert::getObjectAttribute($client, 'transport');
echo 'Sending event';

Assert::assertAttributeEmpty('pendingRequests', $transport);

echo 'Shutdown function called';
});
return null;
},
]);

$foo = str_repeat('x', 1024 * 1024 * 30);
?>
--EXPECTF--
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line %d
Shutdown function called
Sending event