@@ -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,23 @@ public function testStaticAddSignalCallsAddSignalOnLoopInstance()
168
271
Loop::addSignal ($ signal , $ listener );
169
272
}
170
273
274
+ public function testStaticAddSignalWithNoDefaultLoopCallsAddSignalOnNewLoopInstance ()
275
+ {
276
+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
277
+ $ ref ->setAccessible (true );
278
+ $ ref ->setValue (null );
279
+
280
+ $ signal = 1 ;
281
+ $ listener = function () { };
282
+ try {
283
+ Loop::addSignal ($ signal , $ listener );
284
+ } catch (\BadMethodCallException $ e ) {
285
+ $ this ->markTestSkipped ('Skipped: ' . $ e ->getMessage ());
286
+ }
287
+
288
+ $ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ ref ->getValue ());
289
+ }
290
+
171
291
public function testStaticRemoveSignalCallsRemoveSignalOnLoopInstance ()
172
292
{
173
293
$ signal = 1 ;
@@ -181,6 +301,19 @@ public function testStaticRemoveSignalCallsRemoveSignalOnLoopInstance()
181
301
Loop::removeSignal ($ signal , $ listener );
182
302
}
183
303
304
+ public function testStaticRemoveSignalWithNoDefaultLoopIsNoOp ()
305
+ {
306
+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
307
+ $ ref ->setAccessible (true );
308
+ $ ref ->setValue (null );
309
+
310
+ $ signal = 1 ;
311
+ $ listener = function () { };
312
+ Loop::removeSignal ($ signal , $ listener );
313
+
314
+ $ this ->assertNull ($ ref ->getValue ());
315
+ }
316
+
184
317
public function testStaticRunCallsRunOnLoopInstance ()
185
318
{
186
319
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
@@ -191,6 +324,17 @@ public function testStaticRunCallsRunOnLoopInstance()
191
324
Loop::run ();
192
325
}
193
326
327
+ public function testStaticRunWithNoDefaultLoopCallsRunsOnNewLoopInstance ()
328
+ {
329
+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
330
+ $ ref ->setAccessible (true );
331
+ $ ref ->setValue (null );
332
+
333
+ Loop::run ();
334
+
335
+ $ this ->assertInstanceOf ('React\EventLoop\LoopInterface ' , $ ref ->getValue ());
336
+ }
337
+
194
338
public function testStaticStopCallsStopOnLoopInstance ()
195
339
{
196
340
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
@@ -201,6 +345,17 @@ public function testStaticStopCallsStopOnLoopInstance()
201
345
Loop::stop ();
202
346
}
203
347
348
+ public function testStaticStopCallWithNoDefaultLoopIsNoOp ()
349
+ {
350
+ $ ref = new \ReflectionProperty ('React\EventLoop\Loop ' , 'instance ' );
351
+ $ ref ->setAccessible (true );
352
+ $ ref ->setValue (null );
353
+
354
+ Loop::stop ();
355
+
356
+ $ this ->assertNull ($ ref ->getValue ());
357
+ }
358
+
204
359
/**
205
360
* @after
206
361
* @before
0 commit comments