@@ -62,6 +62,19 @@ public function testStaticAddReadStreamCallsAddReadStreamOnLoopInstance()
62
62
Loop::addReadStream ($ stream , $ listener );
63
63
}
64
64
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
+
65
78
public function testStaticAddWriteStreamCallsAddWriteStreamOnLoopInstance ()
66
79
{
67
80
$ stream = tmpfile ();
@@ -75,6 +88,19 @@ public function testStaticAddWriteStreamCallsAddWriteStreamOnLoopInstance()
75
88
Loop::addWriteStream ($ stream , $ listener );
76
89
}
77
90
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
+
78
104
public function testStaticRemoveReadStreamCallsRemoveReadStreamOnLoopInstance ()
79
105
{
80
106
$ stream = tmpfile ();
@@ -87,6 +113,18 @@ public function testStaticRemoveReadStreamCallsRemoveReadStreamOnLoopInstance()
87
113
Loop::removeReadStream ($ stream );
88
114
}
89
115
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
+
90
128
public function testStaticRemoveWriteStreamCallsRemoveWriteStreamOnLoopInstance ()
91
129
{
92
130
$ stream = tmpfile ();
@@ -99,6 +137,18 @@ public function testStaticRemoveWriteStreamCallsRemoveWriteStreamOnLoopInstance(
99
137
Loop::removeWriteStream ($ stream );
100
138
}
101
139
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
+
102
152
public function testStaticAddTimerCallsAddTimerOnLoopInstanceAndReturnsTimerInstance ()
103
153
{
104
154
$ interval = 1.0 ;
@@ -115,6 +165,20 @@ public function testStaticAddTimerCallsAddTimerOnLoopInstanceAndReturnsTimerInst
115
165
$ this ->assertSame ($ timer , $ ret );
116
166
}
117
167
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
+
118
182
public function testStaticAddPeriodicTimerCallsAddPeriodicTimerOnLoopInstanceAndReturnsTimerInstance ()
119
183
{
120
184
$ interval = 1.0 ;
@@ -131,6 +195,21 @@ public function testStaticAddPeriodicTimerCallsAddPeriodicTimerOnLoopInstanceAnd
131
195
$ this ->assertSame ($ timer , $ ret );
132
196
}
133
197
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
+
134
213
public function testStaticCancelTimerCallsCancelTimerOnLoopInstance ()
135
214
{
136
215
$ timer = $ this ->getMockBuilder ('React\EventLoop\TimerInterface ' )->getMock ();
@@ -143,6 +222,18 @@ public function testStaticCancelTimerCallsCancelTimerOnLoopInstance()
143
222
Loop::cancelTimer ($ timer );
144
223
}
145
224
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
+
146
237
public function testStaticFutureTickCallsFutureTickOnLoopInstance ()
147
238
{
148
239
$ listener = function () { };
@@ -155,6 +246,18 @@ public function testStaticFutureTickCallsFutureTickOnLoopInstance()
155
246
Loop::futureTick ($ listener );
156
247
}
157
248
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
+
158
261
public function testStaticAddSignalCallsAddSignalOnLoopInstance ()
159
262
{
160
263
$ signal = 1 ;
@@ -168,6 +271,27 @@ public function testStaticAddSignalCallsAddSignalOnLoopInstance()
168
271
Loop::addSignal ($ signal , $ listener );
169
272
}
170
273
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
+
171
295
public function testStaticRemoveSignalCallsRemoveSignalOnLoopInstance ()
172
296
{
173
297
$ signal = 1 ;
@@ -181,6 +305,19 @@ public function testStaticRemoveSignalCallsRemoveSignalOnLoopInstance()
181
305
Loop::removeSignal ($ signal , $ listener );
182
306
}
183
307
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
+
184
321
public function testStaticRunCallsRunOnLoopInstance ()
185
322
{
186
323
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
@@ -191,6 +328,17 @@ public function testStaticRunCallsRunOnLoopInstance()
191
328
Loop::run ();
192
329
}
193
330
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
+
194
342
public function testStaticStopCallsStopOnLoopInstance ()
195
343
{
196
344
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
@@ -201,6 +349,17 @@ public function testStaticStopCallsStopOnLoopInstance()
201
349
Loop::stop ();
202
350
}
203
351
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
+
204
363
/**
205
364
* @after
206
365
* @before
0 commit comments