Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/TimeoutException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions tests/TimeoutExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace React\Tests\Promise\Timer;

use ErrorException;
use React\Promise\Timer\TimeoutException;

class TimeoutExceptionTest extends TestCase
Expand All @@ -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;
});
}
}