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 2222 },
2323 "require" : {
2424 "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 "
2727 },
2828 "require-dev" : {
2929 "clue/hexdump" : " 0.2.*" ,
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ class Factory
1515
1616 /**
1717 * The `Factory` is responsible for creating your [`SocketInterface`](#socketinterface) instances.
18- *
18+ *
1919 * This class takes an optional `LoopInterface|null $loop` parameter that can be used to
2020 * pass the event loop instance to use for this object. You can use a `null` value
2121 * here in order to use the [default loop](https://github.com/reactphp/event-loop#loop).
@@ -29,8 +29,12 @@ class Factory
2929 *
3030 * @param LoopInterface $loop
3131 */
32- public function __construct (LoopInterface $ loop = null )
32+ public function __construct ($ loop = null )
3333 {
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+
3438 $ this ->loop = $ loop ?: Loop::get ();
3539 }
3640
Original file line number Diff line number Diff line change @@ -57,15 +57,21 @@ public function testMultipleReceivers()
5757
5858 $ this ->loop ->run ();
5959 }
60-
60+
6161 public function testConstructWithoutLoopAssignsLoopAutomatically ()
6262 {
6363 $ factory = new Factory ();
64-
64+
6565 $ ref = new \ReflectionProperty ($ factory , 'loop ' );
6666 $ ref ->setAccessible (true );
6767 $ loop = $ ref ->getValue ($ factory );
68-
68+
6969 $ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ loop );
7070 }
71+
72+ public function testCtorThrowsForInvalidLoop ()
73+ {
74+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface ' );
75+ new Factory ('loop ' );
76+ }
7177}
Original file line number Diff line number Diff line change @@ -41,4 +41,21 @@ protected function createCallableMock()
4141 {
4242 return $ this ->getMockBuilder ('stdClass ' )->setMethods (array ('__invoke ' ))->getMock ();
4343 }
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+ }
4461}
You can’t perform that action at this time.
0 commit comments