2
2
3
3
namespace React \Tests \MySQL ;
4
4
5
+ use React \EventLoop \Loop ;
5
6
use React \MySQL \ConnectionInterface ;
6
7
use React \MySQL \Factory ;
7
- use React \Socket \Server ;
8
+ use React \Socket \SocketServer ;
8
9
use React \Promise \Promise ;
9
10
10
11
class FactoryTest extends BaseTestCase
@@ -104,21 +105,19 @@ public function testConnectWithInvalidCharsetWillRejectWithoutConnecting()
104
105
105
106
public function testConnectWithInvalidHostRejectsWithConnectionError ()
106
107
{
107
- $ loop = \React \EventLoop \Factory::create ();
108
- $ factory = new Factory ($ loop );
108
+ $ factory = new Factory ();
109
109
110
110
$ uri = $ this ->getConnectionString (array ('host ' => 'example.invalid ' ));
111
111
$ promise = $ factory ->createConnection ($ uri );
112
112
113
113
$ promise ->then (null , $ this ->expectCallableOnce ());
114
114
115
- $ loop -> run ();
115
+ Loop:: run ();
116
116
}
117
117
118
118
public function testConnectWithInvalidPassRejectsWithAuthenticationError ()
119
119
{
120
- $ loop = \React \EventLoop \Factory::create ();
121
- $ factory = new Factory ($ loop );
120
+ $ factory = new Factory ();
122
121
123
122
$ uri = $ this ->getConnectionString (array ('passwd ' => 'invalidpass ' ));
124
123
$ promise = $ factory ->createConnection ($ uri );
@@ -132,33 +131,31 @@ public function testConnectWithInvalidPassRejectsWithAuthenticationError()
132
131
)
133
132
));
134
133
135
- $ loop -> run ();
134
+ Loop:: run ();
136
135
}
137
136
138
137
public function testConnectWillRejectWhenServerClosesConnection ()
139
138
{
140
- $ loop = \React \EventLoop \Factory::create ();
141
- $ factory = new Factory ($ loop );
139
+ $ factory = new Factory ();
142
140
143
- $ server = new Server ( 0 , $ loop );
144
- $ server ->on ('connection ' , function ($ connection ) use ($ server ) {
145
- $ server ->close ();
141
+ $ socket = new SocketServer ( ' 127.0.0.1:0 ' , array () );
142
+ $ socket ->on ('connection ' , function ($ connection ) use ($ socket ) {
143
+ $ socket ->close ();
146
144
$ connection ->close ();
147
145
});
148
146
149
- $ parts = parse_url ($ server ->getAddress ());
147
+ $ parts = parse_url ($ socket ->getAddress ());
150
148
$ uri = $ this ->getConnectionString (array ('host ' => $ parts ['host ' ], 'port ' => $ parts ['port ' ]));
151
149
152
150
$ promise = $ factory ->createConnection ($ uri );
153
151
$ promise ->then (null , $ this ->expectCallableOnce ());
154
152
155
- $ loop -> run ();
153
+ Loop:: run ();
156
154
}
157
155
158
156
public function testConnectWillRejectOnExplicitTimeoutDespiteValidAuth ()
159
157
{
160
- $ loop = \React \EventLoop \Factory::create ();
161
- $ factory = new Factory ($ loop );
158
+ $ factory = new Factory ();
162
159
163
160
$ uri = $ this ->getConnectionString () . '?timeout=0 ' ;
164
161
@@ -173,13 +170,12 @@ public function testConnectWillRejectOnExplicitTimeoutDespiteValidAuth()
173
170
)
174
171
));
175
172
176
- $ loop -> run ();
173
+ Loop:: run ();
177
174
}
178
175
179
176
public function testConnectWillRejectOnDefaultTimeoutFromIniDespiteValidAuth ()
180
177
{
181
- $ loop = \React \EventLoop \Factory::create ();
182
- $ factory = new Factory ($ loop );
178
+ $ factory = new Factory ();
183
179
184
180
$ uri = $ this ->getConnectionString ();
185
181
@@ -197,15 +193,14 @@ public function testConnectWillRejectOnDefaultTimeoutFromIniDespiteValidAuth()
197
193
)
198
194
));
199
195
200
- $ loop -> run ();
196
+ Loop:: run ();
201
197
}
202
198
203
199
public function testConnectWithValidAuthWillRunUntilQuit ()
204
200
{
205
201
$ this ->expectOutputString ('connected.closed. ' );
206
202
207
- $ loop = \React \EventLoop \Factory::create ();
208
- $ factory = new Factory ($ loop );
203
+ $ factory = new Factory ();
209
204
210
205
$ uri = $ this ->getConnectionString ();
211
206
$ factory ->createConnection ($ uri )->then (function (ConnectionInterface $ connection ) {
@@ -215,15 +210,14 @@ public function testConnectWithValidAuthWillRunUntilQuit()
215
210
});
216
211
}, 'printf ' )->then (null , 'printf ' );
217
212
218
- $ loop -> run ();
213
+ Loop:: run ();
219
214
}
220
215
221
216
public function testConnectWithValidAuthAndWithoutDbNameWillRunUntilQuit ()
222
217
{
223
218
$ this ->expectOutputString ('connected.closed. ' );
224
219
225
- $ loop = \React \EventLoop \Factory::create ();
226
- $ factory = new Factory ($ loop );
220
+ $ factory = new Factory ();
227
221
228
222
$ uri = $ this ->getConnectionString (array ('dbname ' => '' ));
229
223
$ factory ->createConnection ($ uri )->then (function (ConnectionInterface $ connection ) {
@@ -233,15 +227,14 @@ public function testConnectWithValidAuthAndWithoutDbNameWillRunUntilQuit()
233
227
});
234
228
}, 'printf ' )->then (null , 'printf ' );
235
229
236
- $ loop -> run ();
230
+ Loop:: run ();
237
231
}
238
232
239
233
public function testConnectWithValidAuthWillIgnoreNegativeTimeoutAndRunUntilQuit ()
240
234
{
241
235
$ this ->expectOutputString ('connected.closed. ' );
242
236
243
- $ loop = \React \EventLoop \Factory::create ();
244
- $ factory = new Factory ($ loop );
237
+ $ factory = new Factory ();
245
238
246
239
$ uri = $ this ->getConnectionString () . '?timeout=-1 ' ;
247
240
$ factory ->createConnection ($ uri )->then (function (ConnectionInterface $ connection ) {
@@ -251,15 +244,14 @@ public function testConnectWithValidAuthWillIgnoreNegativeTimeoutAndRunUntilQuit
251
244
});
252
245
}, 'printf ' )->then (null , 'printf ' );
253
246
254
- $ loop -> run ();
247
+ Loop:: run ();
255
248
}
256
249
257
250
public function testConnectWithValidAuthCanPingAndThenQuit ()
258
251
{
259
252
$ this ->expectOutputString ('connected.ping.closed. ' );
260
253
261
- $ loop = \React \EventLoop \Factory::create ();
262
- $ factory = new Factory ($ loop );
254
+ $ factory = new Factory ();
263
255
264
256
$ uri = $ this ->getConnectionString ();
265
257
$ factory ->createConnection ($ uri )->then (function (ConnectionInterface $ connection ) {
@@ -273,15 +265,14 @@ public function testConnectWithValidAuthCanPingAndThenQuit()
273
265
274
266
}, 'printf ' )->then (null , 'printf ' );
275
267
276
- $ loop -> run ();
268
+ Loop:: run ();
277
269
}
278
270
279
271
public function testConnectWithValidAuthCanQueuePingAndQuit ()
280
272
{
281
273
$ this ->expectOutputString ('connected.ping.closed. ' );
282
274
283
- $ loop = \React \EventLoop \Factory::create ();
284
- $ factory = new Factory ($ loop );
275
+ $ factory = new Factory ();
285
276
286
277
$ uri = $ this ->getConnectionString ();
287
278
$ factory ->createConnection ($ uri )->then (function (ConnectionInterface $ connection ) {
@@ -294,15 +285,14 @@ public function testConnectWithValidAuthCanQueuePingAndQuit()
294
285
});
295
286
}, 'printf ' )->then (null , 'printf ' );
296
287
297
- $ loop -> run ();
288
+ Loop:: run ();
298
289
}
299
290
300
291
public function testConnectWithValidAuthQuitOnlyOnce ()
301
292
{
302
293
$ this ->expectOutputString ('connected.closed. ' );
303
294
304
- $ loop = \React \EventLoop \Factory::create ();
305
- $ factory = new Factory ($ loop );
295
+ $ factory = new Factory ();
306
296
307
297
$ uri = $ this ->getConnectionString ();
308
298
$ factory ->createConnection ($ uri )->then (function (ConnectionInterface $ connection ) {
@@ -315,15 +305,14 @@ public function testConnectWithValidAuthQuitOnlyOnce()
315
305
});
316
306
}, 'printf ' )->then (null , 'printf ' );
317
307
318
- $ loop -> run ();
308
+ Loop:: run ();
319
309
}
320
310
321
311
public function testConnectWithValidAuthCanCloseOnlyOnce ()
322
312
{
323
313
$ this ->expectOutputString ('connected.closed. ' );
324
314
325
- $ loop = \React \EventLoop \Factory::create ();
326
- $ factory = new Factory ($ loop );
315
+ $ factory = new Factory ();
327
316
328
317
$ uri = $ this ->getConnectionString ();
329
318
$ factory ->createConnection ($ uri )->then (function (ConnectionInterface $ connection ) {
@@ -339,15 +328,14 @@ public function testConnectWithValidAuthCanCloseOnlyOnce()
339
328
$ connection ->close ();
340
329
}, 'printf ' )->then (null , 'printf ' );
341
330
342
- $ loop -> run ();
331
+ Loop:: run ();
343
332
}
344
333
345
334
public function testConnectWithValidAuthCanCloseAndAbortPing ()
346
335
{
347
336
$ this ->expectOutputString ('connected.aborted pending (Connection lost).aborted queued (Connection lost).closed. ' );
348
337
349
- $ loop = \React \EventLoop \Factory::create ();
350
- $ factory = new Factory ($ loop );
338
+ $ factory = new Factory ();
351
339
352
340
$ uri = $ this ->getConnectionString ();
353
341
$ factory ->createConnection ($ uri )->then (function (ConnectionInterface $ connection ) {
@@ -368,7 +356,7 @@ public function testConnectWithValidAuthCanCloseAndAbortPing()
368
356
$ connection ->close ();
369
357
}, 'printf ' )->then (null , 'printf ' );
370
358
371
- $ loop -> run ();
359
+ Loop:: run ();
372
360
}
373
361
374
362
public function testCancelConnectWillCancelPendingConnection ()
@@ -433,8 +421,7 @@ public function testConnectLazyWithAnyAuthWillQuitWithoutRunning()
433
421
{
434
422
$ this ->expectOutputString ('closed. ' );
435
423
436
- $ loop = \React \EventLoop \Factory::create ();
437
- $ factory = new Factory ($ loop );
424
+ $ factory = new Factory ();
438
425
439
426
$ uri = 'mysql://random:pass@host ' ;
440
427
$ connection = $ factory ->createLazyConnection ($ uri );
@@ -448,8 +435,7 @@ public function testConnectLazyWithValidAuthWillRunUntilQuitAfterPing()
448
435
{
449
436
$ this ->expectOutputString ('closed. ' );
450
437
451
- $ loop = \React \EventLoop \Factory::create ();
452
- $ factory = new Factory ($ loop );
438
+ $ factory = new Factory ();
453
439
454
440
$ uri = $ this ->getConnectionString ();
455
441
$ connection = $ factory ->createLazyConnection ($ uri );
@@ -460,29 +446,27 @@ public function testConnectLazyWithValidAuthWillRunUntilQuitAfterPing()
460
446
echo 'closed. ' ;
461
447
});
462
448
463
- $ loop -> run ();
449
+ Loop:: run ();
464
450
}
465
451
466
452
/**
467
453
* @doesNotPerformAssertions
468
454
*/
469
455
public function testConnectLazyWithValidAuthWillRunUntilIdleTimerAfterPingEvenWithoutQuit ()
470
456
{
471
- $ loop = \React \EventLoop \Factory::create ();
472
- $ factory = new Factory ($ loop );
457
+ $ factory = new Factory ();
473
458
474
459
$ uri = $ this ->getConnectionString () . '?idle=0 ' ;
475
460
$ connection = $ factory ->createLazyConnection ($ uri );
476
461
477
462
$ connection ->ping ();
478
463
479
- $ loop -> run ();
464
+ Loop:: run ();
480
465
}
481
466
482
467
public function testConnectLazyWithInvalidAuthWillRejectPingButWillNotEmitErrorOrClose ()
483
468
{
484
- $ loop = \React \EventLoop \Factory::create ();
485
- $ factory = new Factory ($ loop );
469
+ $ factory = new Factory ();
486
470
487
471
$ uri = $ this ->getConnectionString (array ('passwd ' => 'invalidpass ' ));
488
472
$ connection = $ factory ->createLazyConnection ($ uri );
@@ -492,15 +476,14 @@ public function testConnectLazyWithInvalidAuthWillRejectPingButWillNotEmitErrorO
492
476
493
477
$ connection ->ping ()->then (null , $ this ->expectCallableOnce ());
494
478
495
- $ loop -> run ();
479
+ Loop:: run ();
496
480
}
497
481
498
482
public function testConnectLazyWithValidAuthWillPingBeforeQuitButNotAfter ()
499
483
{
500
484
$ this ->expectOutputString ('ping.closed. ' );
501
485
502
- $ loop = \React \EventLoop \Factory::create ();
503
- $ factory = new Factory ($ loop );
486
+ $ factory = new Factory ();
504
487
505
488
$ uri = $ this ->getConnectionString ();
506
489
$ connection = $ factory ->createLazyConnection ($ uri );
@@ -517,6 +500,6 @@ public function testConnectLazyWithValidAuthWillPingBeforeQuitButNotAfter()
517
500
echo 'never reached ' ;
518
501
});
519
502
520
- $ loop -> run ();
503
+ Loop:: run ();
521
504
}
522
505
}
0 commit comments