Skip to content

Commit d9da3a5

Browse files
committed
Use Number Codes if Error Constants are undefined
1 parent 364f75b commit d9da3a5

3 files changed

Lines changed: 32 additions & 32 deletions

File tree

tests/ClientTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function testConnectorRejectsWillRejectConnection()
168168
$promise->then(null, $this->expectCallableOnceWithException(
169169
'RuntimeException',
170170
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
171-
SOCKET_ECONNREFUSED
171+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
172172
));
173173
}
174174

@@ -186,7 +186,7 @@ public function testCancelConnectionDuringConnectionWillCancelConnection()
186186
$promise->then(null, $this->expectCallableOnceWithException(
187187
'RuntimeException',
188188
'Connection to tcp://google.com:80 cancelled while waiting for proxy (ECONNABORTED)',
189-
SOCKET_ECONNABORTED
189+
defined('SOCKET_ECONNABORTED') ? SOCKET_ECONNABORTED : 103
190190
));
191191
}
192192

@@ -205,7 +205,7 @@ public function testCancelConnectionDuringSessionWillCloseStream()
205205
$promise->then(null, $this->expectCallableOnceWithException(
206206
'RuntimeException',
207207
'Connection to tcp://google.com:80 cancelled while waiting for proxy (ECONNABORTED)',
208-
SOCKET_ECONNABORTED
208+
defined('SOCKET_ECONNABORTED') ? SOCKET_ECONNABORTED : 103
209209
));
210210
}
211211

@@ -225,7 +225,7 @@ public function testCancelConnectionDuringDeferredSessionWillCloseStream()
225225
$promise->then(null, $this->expectCallableOnceWithException(
226226
'RuntimeException',
227227
'Connection to tcp://google.com:80 cancelled while waiting for proxy (ECONNABORTED)',
228-
SOCKET_ECONNABORTED
228+
defined('SOCKET_ECONNABORTED') ? SOCKET_ECONNABORTED : 103
229229
));
230230
}
231231

@@ -244,7 +244,7 @@ public function testEmitConnectionCloseDuringSessionWillRejectConnection()
244244
$promise->then(null, $this->expectCallableOnceWithException(
245245
'RuntimeException',
246246
'Connection to tcp://google.com:80 failed because connection to proxy was lost while waiting for response from proxy (ECONNRESET)',
247-
SOCKET_ECONNRESET
247+
defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 104
248248
));
249249
}
250250

@@ -263,7 +263,7 @@ public function testEmitConnectionErrorDuringSessionWillRejectConnection()
263263
$promise->then(null, $this->expectCallableOnceWithException(
264264
'RuntimeException',
265265
'Connection to tcp://google.com:80 failed because connection to proxy caused a stream error (EIO)',
266-
SOCKET_EIO
266+
defined('SOCKET_EIO') ? SOCKET_EIO : 5
267267
));
268268
}
269269

@@ -283,7 +283,7 @@ public function testEmitInvalidSocks4DataDuringSessionWillRejectConnection()
283283
$promise->then(null, $this->expectCallableOnceWithException(
284284
'RuntimeException',
285285
'Connection to tcp://google.com:80 failed because proxy returned invalid response (EBADMSG)',
286-
SOCKET_EBADMSG
286+
defined('SOCKET_EBADMSG') ? SOCKET_EBADMSG: 71
287287
));
288288
}
289289

@@ -305,7 +305,7 @@ public function testEmitInvalidSocks5DataDuringSessionWillRejectConnection()
305305
$promise->then(null, $this->expectCallableOnceWithException(
306306
'RuntimeException',
307307
'Connection to tcp://google.com:80 failed because proxy returned invalid response (EBADMSG)',
308-
SOCKET_EBADMSG
308+
defined('SOCKET_EBADMSG') ? SOCKET_EBADMSG: 71
309309
));
310310
}
311311

@@ -327,7 +327,7 @@ public function testEmitSocks5DataErrorDuringSessionWillRejectConnection()
327327
$promise->then(null, $this->expectCallableOnceWithException(
328328
'RuntimeException',
329329
'Connection to tcp://google.com:80 failed because proxy refused connection with general server failure (ECONNREFUSED)',
330-
SOCKET_ECONNREFUSED
330+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
331331
));
332332
}
333333

@@ -349,7 +349,7 @@ public function testEmitSocks5DataInvalidAuthenticationMethodWillRejectConnectio
349349
$promise->then(null, $this->expectCallableOnceWithException(
350350
'RuntimeException',
351351
'Connection to tcp://google.com:80 failed because proxy denied access due to unsupported authentication method (EACCES)',
352-
SOCKET_EACCES
352+
defined('SOCKET_EACCES') ? SOCKET_EACCES : 13
353353
));
354354
}
355355

@@ -371,7 +371,7 @@ public function testEmitSocks5DataInvalidAuthenticationDetailsWillRejectConnecti
371371
$promise->then(null, $this->expectCallableOnceWithException(
372372
'RuntimeException',
373373
'Connection to tcp://google.com:80 failed because proxy denied access with given authentication details (EACCES)',
374-
SOCKET_EACCES
374+
defined('SOCKET_EACCES') ? SOCKET_EACCES : 13
375375
));
376376
}
377377

@@ -393,7 +393,7 @@ public function testEmitSocks5DataInvalidAddressTypeWillRejectConnection()
393393
$promise->then(null, $this->expectCallableOnceWithException(
394394
'RuntimeException',
395395
'Connection to tcp://google.com:80 failed because proxy returned invalid response (EBADMSG)',
396-
SOCKET_EBADMSG
396+
defined('SOCKET_EBADMSG') ? SOCKET_EBADMSG: 71
397397
));
398398
}
399399

@@ -415,7 +415,7 @@ public function testEmitSocks4DataInvalidResponseWillRejectConnection()
415415
$promise->then(null, $this->expectCallableOnceWithException(
416416
'RuntimeException',
417417
'Connection to tcp://google.com:80 failed because proxy refused connection with error code 0x55 (ECONNREFUSED)',
418-
SOCKET_ECONNREFUSED
418+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
419419
));
420420
}
421421

@@ -460,47 +460,47 @@ public function provideConnectionErrors()
460460
return array(
461461
array(
462462
Server::ERROR_GENERAL,
463-
SOCKET_ECONNREFUSED,
463+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111,
464464
'failed because proxy refused connection with general server failure (ECONNREFUSED)'
465465
),
466466
array(
467467
Server::ERROR_NOT_ALLOWED_BY_RULESET,
468-
SOCKET_EACCES,
468+
defined('SOCKET_EACCES') ? SOCKET_EACCES : 13,
469469
'failed because proxy denied access due to ruleset (EACCES)'
470470
),
471471
array(
472472
Server::ERROR_NETWORK_UNREACHABLE,
473-
SOCKET_ENETUNREACH,
473+
defined('SOCKET_ENETUNREACH') ? SOCKET_ENETUNREACH : 101,
474474
'failed because proxy reported network unreachable (ENETUNREACH)'
475475
),
476476
array(
477477
Server::ERROR_HOST_UNREACHABLE,
478-
SOCKET_EHOSTUNREACH,
478+
defined('SOCKET_EHOSTUNREACH') ? SOCKET_EHOSTUNREACH : 113,
479479
'failed because proxy reported host unreachable (EHOSTUNREACH)'
480480
),
481481
array(
482482
Server::ERROR_CONNECTION_REFUSED,
483-
SOCKET_ECONNREFUSED,
483+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111,
484484
'failed because proxy reported connection refused (ECONNREFUSED)'
485485
),
486486
array(
487487
Server::ERROR_TTL,
488-
SOCKET_ETIMEDOUT,
488+
defined('SOCKET_ETIMEDOUT') ? SOCKET_ETIMEDOUT : 110,
489489
'failed because proxy reported TTL/timeout expired (ETIMEDOUT)'
490490
),
491491
array(
492492
Server::ERROR_COMMAND_UNSUPPORTED,
493-
SOCKET_EPROTO,
493+
defined('SOCKET_EPROTO') ? SOCKET_EPROTO : 71,
494494
'failed because proxy does not support the CONNECT command (EPROTO)'
495495
),
496496
array(
497497
Server::ERROR_ADDRESS_UNSUPPORTED,
498-
SOCKET_EPROTO,
498+
defined('SOCKET_EPROTO') ? SOCKET_EPROTO : 71,
499499
'failed because proxy does not support this address type (EPROTO)'
500500
),
501501
array(
502502
200,
503-
SOCKET_ECONNREFUSED,
503+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111,
504504
'failed because proxy server refused connection with unknown error code 0xC8 (ECONNREFUSED)'
505505
)
506506
);

tests/FunctionalTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public function testConnectionInvalidNoAuthentication()
327327

328328
$this->client = new Client('socks5://127.0.0.1:' . $this->port, $this->connector);
329329

330-
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
330+
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);
331331
}
332332

333333
public function testConnectionInvalidAuthenticationMismatch()
@@ -340,7 +340,7 @@ public function testConnectionInvalidAuthenticationMismatch()
340340

341341
$this->client = new Client('user:pass@127.0.0.1:' . $this->port, $this->connector);
342342

343-
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
343+
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);
344344
}
345345

346346
public function testConnectionInvalidAuthenticatorReturnsFalse()
@@ -355,7 +355,7 @@ public function testConnectionInvalidAuthenticatorReturnsFalse()
355355

356356
$this->client = new Client('user:pass@127.0.0.1:' . $this->port, $this->connector);
357357

358-
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
358+
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);
359359
}
360360

361361
public function testConnectionInvalidAuthenticatorReturnsPromiseFulfilledWithFalse()
@@ -370,7 +370,7 @@ public function testConnectionInvalidAuthenticatorReturnsPromiseFulfilledWithFal
370370

371371
$this->client = new Client('user:pass@127.0.0.1:' . $this->port, $this->connector);
372372

373-
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
373+
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);
374374
}
375375

376376
public function testConnectionInvalidAuthenticatorReturnsPromiseRejected()
@@ -385,7 +385,7 @@ public function testConnectionInvalidAuthenticatorReturnsPromiseRejected()
385385

386386
$this->client = new Client('user:pass@127.0.0.1:' . $this->port, $this->connector);
387387

388-
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
388+
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, defined('SOCKET_EACCES') ? SOCKET_EACCES : 13);
389389
}
390390

391391
/** @group internet */

tests/ServerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,27 @@ public function provideConnectionErrors()
141141
{
142142
return array(
143143
array(
144-
new \RuntimeException('', SOCKET_EACCES),
144+
new \RuntimeException('', defined('SOCKET_EACCES') ? SOCKET_EACCES : 13),
145145
Server::ERROR_NOT_ALLOWED_BY_RULESET
146146
),
147147
array(
148-
new \RuntimeException('', SOCKET_ENETUNREACH),
148+
new \RuntimeException('', defined('SOCKET_ENETUNREACH') ? SOCKET_ENETUNREACH : 101),
149149
Server::ERROR_NETWORK_UNREACHABLE
150150
),
151151
array(
152-
new \RuntimeException('', SOCKET_EHOSTUNREACH),
152+
new \RuntimeException('', defined('SOCKET_EHOSTUNREACH') ? SOCKET_EHOSTUNREACH : 113),
153153
Server::ERROR_HOST_UNREACHABLE,
154154
),
155155
array(
156-
new \RuntimeException('', SOCKET_ECONNREFUSED),
156+
new \RuntimeException('', defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111),
157157
Server::ERROR_CONNECTION_REFUSED
158158
),
159159
array(
160160
new \RuntimeException('Connection refused'),
161161
Server::ERROR_CONNECTION_REFUSED
162162
),
163163
array(
164-
new \RuntimeException('', SOCKET_ETIMEDOUT),
164+
new \RuntimeException('', defined('SOCKET_ETIMEDOUT') ? SOCKET_ETIMEDOUT : 110),
165165
Server::ERROR_TTL
166166
),
167167
array(

0 commit comments

Comments
 (0)