File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-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,32 @@ public function testSearchTimeout()
71
71
72
72
$ promise ->then ($ this ->expectCallableOnce (), $ this ->expectCallableNever (), $ this ->expectCallableNever ());
73
73
}
74
+
75
+ public function testCtorThrowsForInvalidLoop ()
76
+ {
77
+ if (method_exists ($ this , 'expectException ' )) {
78
+ // PHPUnit 5.2+
79
+ $ this ->expectException ('InvalidArgumentException ' );
80
+ $ this ->expectExceptionMessage ('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface ' );
81
+ } else {
82
+ // legacy PHPUnit
83
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface ' );
84
+ }
85
+
86
+ new Client ('loop ' );
87
+ }
88
+
89
+ public function testCtorThrowsForInvalidMulticast ()
90
+ {
91
+ if (method_exists ($ this , 'expectException ' )) {
92
+ // PHPUnit 5.2+
93
+ $ this ->expectException ('InvalidArgumentException ' );
94
+ $ this ->expectExceptionMessage ('Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory ' );
95
+ } else {
96
+ // legacy PHPUnit
97
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory ' );
98
+ }
99
+
100
+ new Client (null , 'multicast ' );
101
+ }
74
102
}
You can’t perform that action at this time.
0 commit comments