@@ -52,7 +52,17 @@ public function testConnectWillRejectWhenGivenInvalidScheme()
52
52
53
53
$ promise = $ factory ->createConnection ('foo://127.0.0.1 ' );
54
54
55
- $ promise ->then (null , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('InvalidArgumentException ' )));
55
+ $ promise ->then (null , $ this ->expectCallableOnceWith (
56
+ $ this ->logicalAnd (
57
+ $ this ->isInstanceOf ('InvalidArgumentException ' ),
58
+ $ this ->callback (function (\InvalidArgumentException $ e ) {
59
+ return $ e ->getMessage () === 'Invalid MySQL URI given (EINVAL) ' ;
60
+ }),
61
+ $ this ->callback (function (\InvalidArgumentException $ e ) {
62
+ return $ e ->getCode () === (defined ('SOCKET_EINVAL ' ) ? SOCKET_EINVAL : 22 );
63
+ })
64
+ )
65
+ ));
56
66
}
57
67
58
68
public function testConnectWillUseGivenHostAndGivenPort ()
@@ -113,7 +123,10 @@ public function testConnectWithInvalidUriWillRejectWithoutConnecting()
113
123
$ this ->logicalAnd (
114
124
$ this ->isInstanceOf ('InvalidArgumentException ' ),
115
125
$ this ->callback (function (\InvalidArgumentException $ e ) {
116
- return $ e ->getMessage () === 'Invalid MySQL URI given ' ;
126
+ return $ e ->getMessage () === 'Invalid MySQL URI given (EINVAL) ' ;
127
+ }),
128
+ $ this ->callback (function (\InvalidArgumentException $ e ) {
129
+ return $ e ->getCode () === (defined ('SOCKET_EINVAL ' ) ? SOCKET_EINVAL : 22 );
117
130
})
118
131
)
119
132
));
@@ -153,9 +166,15 @@ public function testConnectWithInvalidPassRejectsWithAuthenticationError()
153
166
154
167
$ promise ->then (null , $ this ->expectCallableOnceWith (
155
168
$ this ->logicalAnd (
156
- $ this ->isInstanceOf ('Exception ' ),
157
- $ this ->callback (function (\Exception $ e ) {
158
- return !!preg_match ("/^Connection to mysql:\/\/[^ ]* failed during authentication: Access denied for user '.*?'@'.*?' \(using password: YES\)$/ " , $ e ->getMessage ());
169
+ $ this ->isInstanceOf ('RuntimeException ' ),
170
+ $ this ->callback (function (\RuntimeException $ e ) {
171
+ return !!preg_match ("/^Connection to mysql:\/\/[^ ]* failed during authentication: Access denied for user '.*?'@'.*?' \(using password: YES\) \(EACCES\)$/ " , $ e ->getMessage ());
172
+ }),
173
+ $ this ->callback (function (\RuntimeException $ e ) {
174
+ return $ e ->getCode () === (defined ('SOCKET_EACCES ' ) ? SOCKET_EACCES : 13 );
175
+ }),
176
+ $ this ->callback (function (\RuntimeException $ e ) {
177
+ return !!preg_match ("/^Access denied for user '.*?'@'.*?' \(using password: YES\)$/ " , $ e ->getPrevious ()->getMessage ());
159
178
})
160
179
)
161
180
));
@@ -177,7 +196,20 @@ public function testConnectWillRejectWhenServerClosesConnection()
177
196
$ uri = $ this ->getConnectionString (['host ' => $ parts ['host ' ], 'port ' => $ parts ['port ' ]]);
178
197
179
198
$ promise = $ factory ->createConnection ($ uri );
180
- $ promise ->then (null , $ this ->expectCallableOnce ());
199
+
200
+ $ uri = preg_replace ('/:[^:]*@/ ' , ':***@ ' , $ uri );
201
+
202
+ $ promise ->then (null , $ this ->expectCallableOnceWith (
203
+ $ this ->logicalAnd (
204
+ $ this ->isInstanceOf ('RuntimeException ' ),
205
+ $ this ->callback (function (\RuntimeException $ e ) use ($ uri ) {
206
+ return $ e ->getMessage () === 'Connection to mysql:// ' . $ uri . ' failed during authentication: Connection closed by peer (ECONNRESET) ' ;
207
+ }),
208
+ $ this ->callback (function (\RuntimeException $ e ) {
209
+ return $ e ->getCode () === (defined ('SOCKET_ECONNRESET ' ) ? SOCKET_ECONNRESET : 104 );
210
+ })
211
+ )
212
+ ));
181
213
182
214
Loop::run ();
183
215
}
@@ -194,9 +226,12 @@ public function testConnectWillRejectOnExplicitTimeoutDespiteValidAuth()
194
226
195
227
$ promise ->then (null , $ this ->expectCallableOnceWith (
196
228
$ this ->logicalAnd (
197
- $ this ->isInstanceOf ('Exception ' ),
198
- $ this ->callback (function (\Exception $ e ) use ($ uri ) {
199
- return $ e ->getMessage () === 'Connection to ' . $ uri . ' timed out after 0 seconds ' ;
229
+ $ this ->isInstanceOf ('RuntimeException ' ),
230
+ $ this ->callback (function (\RuntimeException $ e ) use ($ uri ) {
231
+ return $ e ->getMessage () === 'Connection to ' . $ uri . ' timed out after 0 seconds (ETIMEDOUT) ' ;
232
+ }),
233
+ $ this ->callback (function (\RuntimeException $ e ) {
234
+ return $ e ->getCode () === (defined ('SOCKET_ETIMEDOUT ' ) ? SOCKET_ETIMEDOUT : 110 );
200
235
})
201
236
)
202
237
));
@@ -219,9 +254,12 @@ public function testConnectWillRejectOnDefaultTimeoutFromIniDespiteValidAuth()
219
254
220
255
$ promise ->then (null , $ this ->expectCallableOnceWith (
221
256
$ this ->logicalAnd (
222
- $ this ->isInstanceOf ('Exception ' ),
223
- $ this ->callback (function (\Exception $ e ) use ($ uri ) {
224
- return $ e ->getMessage () === 'Connection to ' . $ uri . ' timed out after 0 seconds ' ;
257
+ $ this ->isInstanceOf ('RuntimeException ' ),
258
+ $ this ->callback (function (\RuntimeException $ e ) use ($ uri ) {
259
+ return $ e ->getMessage () === 'Connection to ' . $ uri . ' timed out after 0 seconds (ETIMEDOUT) ' ;
260
+ }),
261
+ $ this ->callback (function (\RuntimeException $ e ) {
262
+ return $ e ->getCode () === (defined ('SOCKET_ETIMEDOUT ' ) ? SOCKET_ETIMEDOUT : 110 );
225
263
})
226
264
)
227
265
));
@@ -366,7 +404,7 @@ public function testConnectWithValidAuthCanCloseOnlyOnce()
366
404
367
405
public function testConnectWithValidAuthCanCloseAndAbortPing ()
368
406
{
369
- $ this ->expectOutputString ('connected.aborted pending (Connection lost) .aborted queued (Connection lost ).closed. ' );
407
+ $ this ->expectOutputString ('connected.aborted pending (Connection closing (ECONNABORTED)) .aborted queued (Connection closing (ECONNABORTED) ).closed. ' );
370
408
371
409
$ factory = new Factory ();
372
410
@@ -401,13 +439,17 @@ public function testlConnectWillRejectWhenUnderlyingConnectorRejects()
401
439
$ factory = new Factory ($ loop , $ connector );
402
440
$ promise =
$ factory->
createConnection (
'user:[email protected] ' );
403
441
404
- $ promise ->then (null , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('RuntimeException ' )));
405
- $ promise ->then (null , $ this ->expectCallableOnceWith ($ this ->callback (function ($ e ) {
406
- return ($ e ->getMessage () === 'Connection to mysql://user:***@127.0.0.1 failed: Failed ' );
407
- })));
408
- $ promise ->then (null , $ this ->expectCallableOnceWith ($ this ->callback (function ($ e ) {
409
- return ($ e ->getCode () === 123 );
410
- })));
442
+ $ promise ->then (null , $ this ->expectCallableOnceWith (
443
+ $ this ->logicalAnd (
444
+ $ this ->isInstanceOf ('RuntimeException ' ),
445
+ $ this ->callback (function (\RuntimeException $ e ) {
446
+ return $ e ->getMessage () === 'Connection to mysql://user:***@127.0.0.1 failed: Failed ' ;
447
+ }),
448
+ $ this ->callback (function (\RuntimeException $ e ) {
449
+ return $ e ->getCode () === 123 ;
450
+ })
451
+ )
452
+ ));
411
453
}
412
454
413
455
public function provideUris ()
@@ -457,7 +499,10 @@ public function testCancelConnectWillCancelPendingConnection($uri, $safe)
457
499
$ this ->logicalAnd (
458
500
$ this ->isInstanceOf ('RuntimeException ' ),
459
501
$ this ->callback (function (\RuntimeException $ e ) use ($ safe ) {
460
- return $ e ->getMessage () === 'Connection to ' . $ safe . ' cancelled ' ;
502
+ return $ e ->getMessage () === 'Connection to ' . $ safe . ' cancelled (ECONNABORTED) ' ;
503
+ }),
504
+ $ this ->callback (function (\RuntimeException $ e ) {
505
+ return $ e ->getCode () === (defined ('SOCKET_ECONNABORTED ' ) ? SOCKET_ECONNABORTED : 103 );
461
506
})
462
507
)
463
508
));
@@ -477,10 +522,17 @@ public function testCancelConnectWillCancelPendingConnectionWithRuntimeException
477
522
478
523
$ promise ->cancel ();
479
524
480
- $ promise ->then (null , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('RuntimeException ' )));
481
- $ promise ->then (null , $ this ->expectCallableOnceWith ($ this ->callback (function ($ e ) {
482
- return ($ e ->getMessage () === 'Connection to mysql://127.0.0.1 cancelled ' );
483
- })));
525
+ $ promise ->then (null , $ this ->expectCallableOnceWith (
526
+ $ this ->logicalAnd (
527
+ $ this ->isInstanceOf ('RuntimeException ' ),
528
+ $ this ->callback (function (\RuntimeException $ e ) {
529
+ return $ e ->getMessage () === 'Connection to mysql://127.0.0.1 cancelled (ECONNABORTED) ' ;
530
+ }),
531
+ $ this ->callback (function (\RuntimeException $ e ) {
532
+ return $ e ->getCode () === (defined ('SOCKET_ECONNABORTED ' ) ? SOCKET_ECONNABORTED : 103 );
533
+ })
534
+ )
535
+ ));
484
536
}
485
537
486
538
public function testCancelConnectDuringAuthenticationWillCloseConnection ()
@@ -497,10 +549,17 @@ public function testCancelConnectDuringAuthenticationWillCloseConnection()
497
549
498
550
$ promise ->cancel ();
499
551
500
- $ promise ->then (null , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('RuntimeException ' )));
501
- $ promise ->then (null , $ this ->expectCallableOnceWith ($ this ->callback (function ($ e ) {
502
- return ($ e ->getMessage () === 'Connection to mysql://127.0.0.1 cancelled ' );
503
- })));
552
+ $ promise ->then (null , $ this ->expectCallableOnceWith (
553
+ $ this ->logicalAnd (
554
+ $ this ->isInstanceOf ('RuntimeException ' ),
555
+ $ this ->callback (function (\RuntimeException $ e ) {
556
+ return $ e ->getMessage () === 'Connection to mysql://127.0.0.1 cancelled (ECONNABORTED) ' ;
557
+ }),
558
+ $ this ->callback (function (\RuntimeException $ e ) {
559
+ return $ e ->getCode () === (defined ('SOCKET_ECONNABORTED ' ) ? SOCKET_ECONNABORTED : 103 );
560
+ })
561
+ )
562
+ ));
504
563
}
505
564
506
565
public function testConnectLazyWithAnyAuthWillQuitWithoutRunning ()
0 commit comments