@@ -62,6 +62,19 @@ public function testStaticAddReadStreamCallsAddReadStreamOnLoopInstance()
6262 Loop::addReadStream ($ stream , $ listener );
6363 }
6464
65+ public function testStaticAddReadStreamWithNoDefaultLoopCallsAddReadStreamOnNewLoopInstance ()
66+ {
67+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
68+ $ ref ->setAccessible (true );
69+ $ ref ->setValue (null );
70+
71+ $ stream = stream_socket_server ('127.0.0.1:0 ' );
72+ $ listener = function () { };
73+ Loop::addReadStream ($ stream , $ listener );
74+
75+ $ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ ref ->getValue ());
76+ }
77+
6578 public function testStaticAddWriteStreamCallsAddWriteStreamOnLoopInstance ()
6679 {
6780 $ stream = tmpfile ();
@@ -75,6 +88,19 @@ public function testStaticAddWriteStreamCallsAddWriteStreamOnLoopInstance()
7588 Loop::addWriteStream ($ stream , $ listener );
7689 }
7790
91+ public function testStaticAddWriteStreamWithNoDefaultLoopCallsAddWriteStreamOnNewLoopInstance ()
92+ {
93+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
94+ $ ref ->setAccessible (true );
95+ $ ref ->setValue (null );
96+
97+ $ stream = stream_socket_server ('127.0.0.1:0 ' );
98+ $ listener = function () { };
99+ Loop::addWriteStream ($ stream , $ listener );
100+
101+ $ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ ref ->getValue ());
102+ }
103+
78104 public function testStaticRemoveReadStreamCallsRemoveReadStreamOnLoopInstance ()
79105 {
80106 $ stream = tmpfile ();
@@ -87,6 +113,18 @@ public function testStaticRemoveReadStreamCallsRemoveReadStreamOnLoopInstance()
87113 Loop::removeReadStream ($ stream );
88114 }
89115
116+ public function testStaticRemoveReadStreamWithNoDefaultLoopIsNoOp ()
117+ {
118+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
119+ $ ref ->setAccessible (true );
120+ $ ref ->setValue (null );
121+
122+ $ stream = tmpfile ();
123+ Loop::removeReadStream ($ stream );
124+
125+ $ this ->assertNull ($ ref ->getValue ());
126+ }
127+
90128 public function testStaticRemoveWriteStreamCallsRemoveWriteStreamOnLoopInstance ()
91129 {
92130 $ stream = tmpfile ();
@@ -99,6 +137,18 @@ public function testStaticRemoveWriteStreamCallsRemoveWriteStreamOnLoopInstance(
99137 Loop::removeWriteStream ($ stream );
100138 }
101139
140+ public function testStaticRemoveWriteStreamWithNoDefaultLoopIsNoOp ()
141+ {
142+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
143+ $ ref ->setAccessible (true );
144+ $ ref ->setValue (null );
145+
146+ $ stream = tmpfile ();
147+ Loop::removeWriteStream ($ stream );
148+
149+ $ this ->assertNull ($ ref ->getValue ());
150+ }
151+
102152 public function testStaticAddTimerCallsAddTimerOnLoopInstanceAndReturnsTimerInstance ()
103153 {
104154 $ interval = 1.0 ;
@@ -115,6 +165,20 @@ public function testStaticAddTimerCallsAddTimerOnLoopInstanceAndReturnsTimerInst
115165 $ this ->assertSame ($ timer , $ ret );
116166 }
117167
168+ public function testStaticAddTimerWithNoDefaultLoopCallsAddTimerOnNewLoopInstance ()
169+ {
170+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
171+ $ ref ->setAccessible (true );
172+ $ ref ->setValue (null );
173+
174+ $ interval = 1.0 ;
175+ $ callback = function () { };
176+ $ ret = Loop::addTimer ($ interval , $ callback );
177+
178+ $ this ->assertInstanceOf ('React\EventLoop\TimerInterface ' , $ ret );
179+ $ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ ref ->getValue ());
180+ }
181+
118182 public function testStaticAddPeriodicTimerCallsAddPeriodicTimerOnLoopInstanceAndReturnsTimerInstance ()
119183 {
120184 $ interval = 1.0 ;
@@ -131,6 +195,21 @@ public function testStaticAddPeriodicTimerCallsAddPeriodicTimerOnLoopInstanceAnd
131195 $ this ->assertSame ($ timer , $ ret );
132196 }
133197
198+ public function testStaticAddPeriodicTimerWithNoDefaultLoopCallsAddPeriodicTimerOnNewLoopInstance ()
199+ {
200+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
201+ $ ref ->setAccessible (true );
202+ $ ref ->setValue (null );
203+
204+ $ interval = 1.0 ;
205+ $ callback = function () { };
206+ $ ret = Loop::addPeriodicTimer ($ interval , $ callback );
207+
208+ $ this ->assertInstanceOf ('React\EventLoop\TimerInterface ' , $ ret );
209+ $ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ ref ->getValue ());
210+ }
211+
212+
134213 public function testStaticCancelTimerCallsCancelTimerOnLoopInstance ()
135214 {
136215 $ timer = $ this ->getMockBuilder ('React\EventLoop\TimerInterface ' )->getMock ();
@@ -143,6 +222,18 @@ public function testStaticCancelTimerCallsCancelTimerOnLoopInstance()
143222 Loop::cancelTimer ($ timer );
144223 }
145224
225+ public function testStaticCancelTimerWithNoDefaultLoopIsNoOp ()
226+ {
227+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
228+ $ ref ->setAccessible (true );
229+ $ ref ->setValue (null );
230+
231+ $ timer = $ this ->getMockBuilder ('React\EventLoop\TimerInterface ' )->getMock ();
232+ Loop::cancelTimer ($ timer );
233+
234+ $ this ->assertNull ($ ref ->getValue ());
235+ }
236+
146237 public function testStaticFutureTickCallsFutureTickOnLoopInstance ()
147238 {
148239 $ listener = function () { };
@@ -155,6 +246,18 @@ public function testStaticFutureTickCallsFutureTickOnLoopInstance()
155246 Loop::futureTick ($ listener );
156247 }
157248
249+ public function testStaticFutureTickWithNoDefaultLoopCallsFutureTickOnNewLoopInstance ()
250+ {
251+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
252+ $ ref ->setAccessible (true );
253+ $ ref ->setValue (null );
254+
255+ $ listener = function () { };
256+ Loop::futureTick ($ listener );
257+
258+ $ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ ref ->getValue ());
259+ }
260+
158261 public function testStaticAddSignalCallsAddSignalOnLoopInstance ()
159262 {
160263 $ signal = 1 ;
@@ -168,6 +271,27 @@ public function testStaticAddSignalCallsAddSignalOnLoopInstance()
168271 Loop::addSignal ($ signal , $ listener );
169272 }
170273
274+ public function testStaticAddSignalWithNoDefaultLoopCallsAddSignalOnNewLoopInstance ()
275+ {
276+ if (DIRECTORY_SEPARATOR === '\\' ) {
277+ $ this ->markTestSkipped ('Not supported on Windows ' );
278+ }
279+
280+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
281+ $ ref ->setAccessible (true );
282+ $ ref ->setValue (null );
283+
284+ $ signal = 1 ;
285+ $ listener = function () { };
286+ try {
287+ Loop::addSignal ($ signal , $ listener );
288+ } catch (\BadMethodCallException $ e ) {
289+ $ this ->markTestSkipped ('Skipped: ' . $ e ->getMessage ());
290+ }
291+
292+ $ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ ref ->getValue ());
293+ }
294+
171295 public function testStaticRemoveSignalCallsRemoveSignalOnLoopInstance ()
172296 {
173297 $ signal = 1 ;
@@ -181,6 +305,19 @@ public function testStaticRemoveSignalCallsRemoveSignalOnLoopInstance()
181305 Loop::removeSignal ($ signal , $ listener );
182306 }
183307
308+ public function testStaticRemoveSignalWithNoDefaultLoopIsNoOp ()
309+ {
310+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
311+ $ ref ->setAccessible (true );
312+ $ ref ->setValue (null );
313+
314+ $ signal = 1 ;
315+ $ listener = function () { };
316+ Loop::removeSignal ($ signal , $ listener );
317+
318+ $ this ->assertNull ($ ref ->getValue ());
319+ }
320+
184321 public function testStaticRunCallsRunOnLoopInstance ()
185322 {
186323 $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
@@ -191,6 +328,17 @@ public function testStaticRunCallsRunOnLoopInstance()
191328 Loop::run ();
192329 }
193330
331+ public function testStaticRunWithNoDefaultLoopCallsRunsOnNewLoopInstance ()
332+ {
333+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
334+ $ ref ->setAccessible (true );
335+ $ ref ->setValue (null );
336+
337+ Loop::run ();
338+
339+ $ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ ref ->getValue ());
340+ }
341+
194342 public function testStaticStopCallsStopOnLoopInstance ()
195343 {
196344 $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
@@ -201,6 +349,17 @@ public function testStaticStopCallsStopOnLoopInstance()
201349 Loop::stop ();
202350 }
203351
352+ public function testStaticStopCallWithNoDefaultLoopIsNoOp ()
353+ {
354+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
355+ $ ref ->setAccessible (true );
356+ $ ref ->setValue (null );
357+
358+ Loop::stop ();
359+
360+ $ this ->assertNull ($ ref ->getValue ());
361+ }
362+
204363 /**
205364 * @after
206365 * @before
0 commit comments