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
2828 * @param ?LoopInterface $loop
2929 * @param ?MulticastFactory $multicast
3030 */
31- public function __construct (LoopInterface $ loop = null , MulticastFactory $ multicast = null )
31+ public function __construct ($ loop = null , $ multicast = null )
3232 {
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+ }
3339 $ this ->loop = $ loop ?: Loop::get ();
3440 $ this ->multicast = $ multicast ?: new MulticastFactory ($ this ->loop );
3541 }
Original file line number Diff line number Diff line change @@ -71,4 +71,33 @@ public function testSearchTimeout()
7171
7272 $ promise ->then ($ this ->expectCallableOnce (), $ this ->expectCallableNever (), $ this ->expectCallableNever ());
7373 }
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+ }
74103}
You can’t perform that action at this time.
0 commit comments