From 274209f1adf527a0d90efa365b9e87192b77c457 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 3 Dec 2019 14:35:09 +0000 Subject: [PATCH 1/2] Don't convert warnings to exceptions in phpunit, let them bubble up and cause risky tests --- phpunit.xml.dist | 5 +++++ 1 file changed, 5 insertions(+) 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 @@ + From b169ad8f543b2a7f47aaeefa13e8aea1051bfae0 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 3 Dec 2019 14:42:43 +0000 Subject: [PATCH 2/2] Convert warnings/notices/stricts to exceptions when using socket_connect to avoid warnings bubbling up --- src/Connector/SocketConnector.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Connector/SocketConnector.php b/src/Connector/SocketConnector.php index ecff1710..5826addc 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(); } }