diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b7353f45..d988eeb3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,6 +9,10 @@ beStrictAboutChangesToGlobalState="true" beStrictAboutTodoAnnotatedTests="true" forceCoversAnnotation="true" + convertWarningsToExceptions="false" + convertErrorsToExceptions="false" + convertNoticesToExceptions="false" + convertDeprecationsToExceptions="false" > @@ -20,6 +24,7 @@ + diff --git a/src/Connector/SocketConnector.php b/src/Connector/SocketConnector.php index 4c54fca3..ec61457c 100644 --- a/src/Connector/SocketConnector.php +++ b/src/Connector/SocketConnector.php @@ -4,14 +4,20 @@ namespace Scoutapm\Connector; +use ErrorException; use Scoutapm\Connector\Exception\FailedToConnect; use Scoutapm\Connector\Exception\NotConnected; use Throwable; use const AF_UNIX; +use const E_NOTICE; +use const E_STRICT; +use const E_WARNING; use const SOCK_STREAM; use function json_encode; use function pack; use function register_shutdown_function; +use function restore_error_handler; +use function set_error_handler; use function socket_clear_error; use function socket_close; use function socket_connect; @@ -56,11 +62,23 @@ public function connect() : void try { socket_clear_error($this->socket); + + // phpcs:disable SlevomatCodingStandard.TypeHints.TypeHintDeclaration.IncorrectReturnTypeHint + set_error_handler( + static function (int $severity, string $message, string $file = '', int $line = 0, array $context = []) : bool { + throw new ErrorException($message, 0, $severity, $file, $line); + }, + E_STRICT | E_NOTICE | E_WARNING + ); + // phpcs:enable + $this->connected = socket_connect($this->socket, $this->socketPath); register_shutdown_function([&$this, 'shutdown']); } catch (Throwable $e) { $this->connected = false; throw FailedToConnect::fromSocketPathAndPrevious($this->socketPath, $e); + } finally { + restore_error_handler(); } }