diff --git a/src/TimeoutException.php b/src/TimeoutException.php index 09c439c..f5afaf5 100644 --- a/src/TimeoutException.php +++ b/src/TimeoutException.php @@ -17,6 +17,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; 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; + }); + } }