File tree Expand file tree Collapse file tree 4 files changed +34
-7
lines changed Expand file tree Collapse file tree 4 files changed +34
-7
lines changed Original file line number Diff line number Diff line change 22
22
},
23
23
"require" : {
24
24
"php" : " >=5.3" ,
25
- "react/event-loop " : " ^1.2 " ,
26
- "react/datagram " : " ~1.0 "
25
+ "react/datagram " : " ^1.10 " ,
26
+ "react/event-loop " : " ^1.2 "
27
27
},
28
28
"require-dev" : {
29
29
"clue/hexdump" : " 0.2.*" ,
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ class Factory
15
15
16
16
/**
17
17
* The `Factory` is responsible for creating your [`SocketInterface`](#socketinterface) instances.
18
- *
18
+ *
19
19
* This class takes an optional `LoopInterface|null $loop` parameter that can be used to
20
20
* pass the event loop instance to use for this object. You can use a `null` value
21
21
* here in order to use the [default loop](https://github.com/reactphp/event-loop#loop).
@@ -29,8 +29,12 @@ class Factory
29
29
*
30
30
* @param LoopInterface $loop
31
31
*/
32
- public function __construct (LoopInterface $ loop = null )
32
+ public function __construct ($ loop = null )
33
33
{
34
+ if ($ loop !== null && !$ loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
35
+ throw new \InvalidArgumentException ('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface ' );
36
+ }
37
+
34
38
$ this ->loop = $ loop ?: Loop::get ();
35
39
}
36
40
Original file line number Diff line number Diff line change @@ -57,15 +57,21 @@ public function testMultipleReceivers()
57
57
58
58
$ this ->loop ->run ();
59
59
}
60
-
60
+
61
61
public function testConstructWithoutLoopAssignsLoopAutomatically ()
62
62
{
63
63
$ factory = new Factory ();
64
-
64
+
65
65
$ ref = new \ReflectionProperty ($ factory , 'loop ' );
66
66
$ ref ->setAccessible (true );
67
67
$ loop = $ ref ->getValue ($ factory );
68
-
68
+
69
69
$ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ loop );
70
70
}
71
+
72
+ public function testCtorThrowsForInvalidLoop ()
73
+ {
74
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface ' );
75
+ new Factory ('loop ' );
76
+ }
71
77
}
Original file line number Diff line number Diff line change @@ -41,4 +41,21 @@ protected function createCallableMock()
41
41
{
42
42
return $ this ->getMockBuilder ('stdClass ' )->setMethods (array ('__invoke ' ))->getMock ();
43
43
}
44
+
45
+ public function setExpectedException ($ exception , $ exceptionMessage = '' , $ exceptionCode = null )
46
+ {
47
+ if (method_exists ($ this , 'expectException ' )) {
48
+ // PHPUnit 5.2+
49
+ $ this ->expectException ($ exception );
50
+ if ($ exceptionMessage !== '' ) {
51
+ $ this ->expectExceptionMessage ($ exceptionMessage );
52
+ }
53
+ if ($ exceptionCode !== null ) {
54
+ $ this ->expectExceptionCode ($ exceptionCode );
55
+ }
56
+ } else {
57
+ // legacy PHPUnit
58
+ parent ::setExpectedException ($ exception , $ exceptionMessage , $ exceptionCode );
59
+ }
60
+ }
44
61
}
You can’t perform that action at this time.
0 commit comments