From 52ba97dbec37e11fa1540fb511aca130d1c18988 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 29 Nov 2021 15:24:07 +0100 Subject: [PATCH 1/2] TimeoutExceptionTest: let the test fail --- tests/TimeoutExceptionTest.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/TimeoutExceptionTest.php b/tests/TimeoutExceptionTest.php index e9bedd9..eb2957e 100644 --- a/tests/TimeoutExceptionTest.php +++ b/tests/TimeoutExceptionTest.php @@ -2,6 +2,7 @@ namespace React\Tests\Promise\Timer; +use ErrorException; use React\Promise\Timer\TimeoutException; class TimeoutExceptionTest extends TestCase @@ -12,4 +13,36 @@ public function testAccessTimeout() $this->assertEquals(10, $e->getTimeout()); } + + public function testEnsureNoDeprecationsAreTriggered() + { + $formerReporting = error_reporting(); + error_reporting(E_ALL | E_STRICT); + $this->setStrictErrorHandling(); + + try { + $e = new TimeoutException(10); + } catch (ErrorException $e) { + error_reporting($formerReporting); + throw $e; + } + + error_reporting($formerReporting); + $this->assertEquals(10, $e->getTimeout()); + } + + protected function setStrictErrorHandling() + { + set_error_handler(function ($errno, $errstr, $errfile, $errline) { + if (! (error_reporting() & $errno)) { + return false; + } + switch ($errno) { + case E_DEPRECATED: + throw new ErrorException($errstr, 0, $errno, $errfile, $errline); + } + + return false; + }); + } } From d4a0b8c77e8d018ab809617a744f27625963c702 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 29 Nov 2021 15:47:39 +0100 Subject: [PATCH 2/2] TimeoutException: fix defaults to avoid notices --- src/TimeoutException.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/TimeoutException.php b/src/TimeoutException.php index 18ea72f..6f157ce 100644 --- a/src/TimeoutException.php +++ b/src/TimeoutException.php @@ -10,6 +10,13 @@ class TimeoutException extends RuntimeException public function __construct($timeout, $message = null, $code = null, $previous = null) { + // Preserve compatibility with our former signature, but avoid invalid arguments for the parent constructor: + if ($message === null) { + $message = ''; + } + if ($code === null) { + $code = 0; + } parent::__construct($message, $code, $previous); $this->timeout = $timeout;