File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -28,8 +28,14 @@ class Client
28
28
* @param ?LoopInterface $loop
29
29
* @param ?MulticastFactory $multicast
30
30
*/
31
- public function __construct (LoopInterface $ loop = null , MulticastFactory $ multicast = null )
31
+ public function __construct ($ loop = null , $ multicast = null )
32
32
{
33
+ if ($ loop !== null && !$ loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
34
+ throw new \InvalidArgumentException ('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface ' );
35
+ }
36
+ if ($ multicast !== null && !$ multicast instanceof MulticastFactory) { // manual type check to support legacy PHP < 7.1
37
+ throw new \InvalidArgumentException ('Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory ' );
38
+ }
33
39
$ this ->loop = $ loop ?: Loop::get ();
34
40
$ this ->multicast = $ multicast ?: new MulticastFactory ($ this ->loop );
35
41
}
Original file line number Diff line number Diff line change @@ -71,4 +71,33 @@ public function testSearchTimeout()
71
71
72
72
$ promise ->then ($ this ->expectCallableOnce (), $ this ->expectCallableNever (), $ this ->expectCallableNever ());
73
73
}
74
+
75
+
76
+ public function testCtorThrowsForInvalidLoop ()
77
+ {
78
+ if (method_exists ($ this , 'expectException ' )) {
79
+ // PHPUnit 5.2+
80
+ $ this ->expectException ('InvalidArgumentException ' );
81
+ $ this ->expectExceptionMessage ('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface ' );
82
+ } else {
83
+ // legacy PHPUnit
84
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface ' );
85
+ }
86
+
87
+ new Client ('loop ' );
88
+ }
89
+
90
+ public function testCtorThrowsForInvalidMulticast ()
91
+ {
92
+ if (method_exists ($ this , 'expectException ' )) {
93
+ // PHPUnit 5.2+
94
+ $ this ->expectException ('InvalidArgumentException ' );
95
+ $ this ->expectExceptionMessage ('Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory ' );
96
+ } else {
97
+ // legacy PHPUnit
98
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory ' );
99
+ }
100
+
101
+ new Client (null , 'multicast ' );
102
+ }
74
103
}
You can’t perform that action at this time.
0 commit comments