|
2 | 2 |
|
3 | 3 | namespace React\Tests\Promise\Timer;
|
4 | 4 |
|
5 |
| -use ErrorException; |
6 | 5 | use React\Promise\Timer\TimeoutException;
|
7 | 6 |
|
8 | 7 | class TimeoutExceptionTest extends TestCase
|
9 | 8 | {
|
10 |
| - public function testAccessTimeout() |
| 9 | + public function testCtorWithAllParameters() |
11 | 10 | {
|
12 |
| - $e = new TimeoutException(10); |
| 11 | + $previous = new \Exception(); |
| 12 | + $e = new TimeoutException(1.0, 'Error', 42, $previous); |
13 | 13 |
|
14 |
| - $this->assertEquals(10, $e->getTimeout()); |
| 14 | + $this->assertEquals(1.0, $e->getTimeout()); |
| 15 | + $this->assertEquals('Error', $e->getMessage()); |
| 16 | + $this->assertEquals(42, $e->getCode()); |
| 17 | + $this->assertSame($previous, $e->getPrevious()); |
15 | 18 | }
|
16 | 19 |
|
17 |
| - public function testEnsureNoDeprecationsAreTriggered() |
| 20 | + public function testCtorWithDefaultValues() |
18 | 21 | {
|
19 |
| - $formerReporting = error_reporting(); |
20 |
| - error_reporting(E_ALL | E_STRICT); |
21 |
| - $this->setStrictErrorHandling(); |
22 |
| - |
23 |
| - try { |
24 |
| - $e = new TimeoutException(10); |
25 |
| - } catch (ErrorException $e) { |
26 |
| - error_reporting($formerReporting); |
27 |
| - throw $e; |
28 |
| - } |
29 |
| - |
30 |
| - error_reporting($formerReporting); |
31 |
| - $this->assertEquals(10, $e->getTimeout()); |
| 22 | + $e = new TimeoutException(2.0); |
| 23 | + |
| 24 | + $this->assertEquals(2.0, $e->getTimeout()); |
| 25 | + $this->assertEquals('', $e->getMessage()); |
| 26 | + $this->assertEquals(0, $e->getCode()); |
| 27 | + $this->assertNull($e->getPrevious()); |
| 28 | + } |
| 29 | + |
| 30 | + public function testCtorWithIntTimeoutWillBeReturnedAsFloat() |
| 31 | + { |
| 32 | + $e = new TimeoutException(1); |
| 33 | + |
| 34 | + $this->assertSame(1.0, $e->getTimeout()); |
32 | 35 | }
|
33 | 36 |
|
34 |
| - protected function setStrictErrorHandling() |
| 37 | + public function testLegacyCtorWithNullValues() |
35 | 38 | {
|
36 |
| - set_error_handler(function ($errno, $errstr, $errfile, $errline) { |
37 |
| - if (! (error_reporting() & $errno)) { |
38 |
| - return false; |
39 |
| - } |
40 |
| - switch ($errno) { |
41 |
| - case E_DEPRECATED: |
42 |
| - throw new ErrorException($errstr, 0, $errno, $errfile, $errline); |
43 |
| - } |
44 |
| - |
45 |
| - return false; |
46 |
| - }); |
| 39 | + $e = new TimeoutException(10, null, null, null); |
| 40 | + |
| 41 | + $this->assertEquals(10.0, $e->getTimeout()); |
| 42 | + $this->assertEquals('', $e->getMessage()); |
| 43 | + $this->assertEquals(0, $e->getCode()); |
| 44 | + $this->assertNull($e->getPrevious()); |
47 | 45 | }
|
48 | 46 | }
|
0 commit comments