|
13 | 13 |
|
14 | 14 | class EventSourceTest extends TestCase
|
15 | 15 | {
|
16 |
| - /** |
17 |
| - * @expectedException InvalidArgumentException |
18 |
| - */ |
19 | 16 | public function testConstructorThrowsIfFirstArgumentIsNotAnUri()
|
20 | 17 | {
|
21 | 18 | $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
|
| 19 | + $this->setExpectedException('InvalidArgumentException'); |
22 | 20 | new EventSource('///', $loop);
|
23 | 21 | }
|
24 | 22 |
|
25 |
| - /** |
26 |
| - * @expectedException InvalidArgumentException |
27 |
| - */ |
28 | 23 | public function testConstructorThrowsIfUriArgumentDoesNotIncludeScheme()
|
29 | 24 | {
|
30 | 25 | $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
|
| 26 | + $this->setExpectedException('InvalidArgumentException'); |
31 | 27 | new EventSource('example.com', $loop);
|
32 | 28 | }
|
33 | 29 |
|
34 |
| - /** |
35 |
| - * @expectedException InvalidArgumentException |
36 |
| - */ |
37 | 30 | public function testConstructorThrowsIfUriArgumentIncludesInvalidScheme()
|
38 | 31 | {
|
39 | 32 | $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
|
| 33 | + $this->setExpectedException('InvalidArgumentException'); |
40 | 34 | new EventSource('ftp://example.com', $loop);
|
41 | 35 | }
|
42 | 36 |
|
@@ -620,4 +614,21 @@ public function testReconnectAfterStreamClosesUsesLastEventIdFromParsedEventStre
|
620 | 614 | $this->assertNotNull($timerReconnect);
|
621 | 615 | $timerReconnect();
|
622 | 616 | }
|
| 617 | + |
| 618 | + public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null) |
| 619 | + { |
| 620 | + if (method_exists($this, 'expectException')) { |
| 621 | + // PHPUnit 5.2+ |
| 622 | + $this->expectException($exception); |
| 623 | + if ($exceptionMessage !== '') { |
| 624 | + $this->expectExceptionMessage($exceptionMessage); |
| 625 | + } |
| 626 | + if ($exceptionCode !== null) { |
| 627 | + $this->expectExceptionCode($exceptionCode); |
| 628 | + } |
| 629 | + } else { |
| 630 | + // legacy PHPUnit 4 - PHPUnit 5.1 |
| 631 | + parent::setExpectedException($exception, $exceptionMessage, $exceptionCode); |
| 632 | + } |
| 633 | + } |
623 | 634 | }
|
0 commit comments