diff --git a/composer.json b/composer.json index 2923c55..7788b7d 100644 --- a/composer.json +++ b/composer.json @@ -12,16 +12,16 @@ ], "require": { "php": ">=5.3", - "react/promise": "^3 || ^2.1 || ^1.2.1", - "react/socket": "^1.12", + "react/promise": "^3.2 || ^2.1 || ^1.2.1", + "react/socket": "^1.16", "ringcentral/psr7": "^1.2" }, "require-dev": { "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36", - "react/async": "^4 || ^3 || ^2", + "react/async": "^4.3 || ^3 || ^2", "react/event-loop": "^1.2", - "react/http": "^1.5", - "react/promise-timer": "^1.10" + "react/http": "^1.11", + "react/promise-timer": "^1.11" }, "autoload": { "psr-4": { diff --git a/src/ProxyConnector.php b/src/ProxyConnector.php index d7f2863..0e7bcdb 100644 --- a/src/ProxyConnector.php +++ b/src/ProxyConnector.php @@ -60,7 +60,7 @@ class ProxyConnector implements ConnectorInterface public function __construct( #[\SensitiveParameter] $proxyUrl, - ConnectorInterface $connector = null, + $connector = null, array $httpHeaders = array() ) { // support `http+unix://` scheme for Unix domain socket (UDS) paths @@ -84,6 +84,10 @@ public function __construct( throw new InvalidArgumentException('Invalid proxy URL "' . $proxyUrl . '"'); } + if ($connector !== null && !$connector instanceof ConnectorInterface) { // manual type check to support legacy PHP < 7.1 + throw new \InvalidArgumentException('Argument #2 ($connector) expected null|React\Socket\ConnectorInterface'); + } + // apply default port and TCP/TLS transport for given scheme if (!isset($parts['port'])) { $parts['port'] = $parts['scheme'] === 'https' ? 443 : 80; diff --git a/tests/ProxyConnectorTest.php b/tests/ProxyConnectorTest.php index f2d5795..0839692 100644 --- a/tests/ProxyConnectorTest.php +++ b/tests/ProxyConnectorTest.php @@ -48,6 +48,12 @@ public function testInvalidHttpsUnixScheme() new ProxyConnector('https+unix:///tmp/proxy.sock', $this->connector); } + public function testContructorThrowsExceptionForInvalidConnector() + { + $this->setExpectedException('InvalidArgumentException', 'Argument #2 ($connector) expected null|React\Socket\ConnectorInterface'); + new ProxyConnector('proxy.example.com', 'connector'); + } + public function testCreatesConnectionToHttpPort() { $promise = new Promise(function () { });