Skip to content

Commit afc2f40

Browse files
committed
Use Number Codes if Error Constants are undefined
1 parent 1889b0e commit afc2f40

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

tests/FunctionalTest.php

+4-17
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testNonListeningSocketRejectsConnection()
4040
$this->setExpectedException(
4141
'RuntimeException',
4242
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
43-
SOCKET_ECONNREFUSED
43+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
4444
);
4545
Block\await($promise, $this->loop, 3.0);
4646
}
@@ -54,7 +54,7 @@ public function testPlainGoogleDoesNotAcceptConnectMethod()
5454
$this->setExpectedException(
5555
'RuntimeException',
5656
'Connection to tcp://google.com:80 failed because proxy refused connection with HTTP error code 405 (Method Not Allowed) (ECONNREFUSED)',
57-
SOCKET_ECONNREFUSED
57+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
5858
);
5959
Block\await($promise, $this->loop, 3.0);
6060
}
@@ -73,7 +73,7 @@ public function testSecureGoogleDoesNotAcceptConnectMethod()
7373
$this->setExpectedException(
7474
'RuntimeException',
7575
'Connection to tcp://google.com:80 failed because proxy refused connection with HTTP error code 405 (Method Not Allowed) (ECONNREFUSED)',
76-
SOCKET_ECONNREFUSED
76+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
7777
);
7878
Block\await($promise, $this->loop, 3.0);
7979
}
@@ -87,7 +87,7 @@ public function testSecureGoogleDoesNotAcceptPlainStream()
8787
$this->setExpectedException(
8888
'RuntimeException',
8989
'Connection to tcp://google.com:80 failed because connection to proxy was lost while waiting for response (ECONNRESET)',
90-
SOCKET_ECONNRESET
90+
defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 104
9191
);
9292
Block\await($promise, $this->loop, 3.0);
9393
}
@@ -108,17 +108,4 @@ public function testCancelWhileConnectingShouldNotCreateGarbageCycles()
108108

109109
$this->assertEquals(0, gc_collect_cycles());
110110
}
111-
112-
public function setExpectedException($exception, $message = '', $code = 0)
113-
{
114-
if (method_exists($this, 'expectException')) {
115-
$this->expectException($exception);
116-
if ($message !== null) {
117-
$this->expectExceptionMessage($message);
118-
}
119-
$this->expectExceptionCode($code);
120-
} else {
121-
parent::setExpectedException($exception, $message, $code);
122-
}
123-
}
124111
}

tests/ProxyConnectorTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public function testRejectsWithPreviousIfConnectorRejects()
294294
$promise->then(null, $this->expectCallableOnceWithException(
295295
'RuntimeException',
296296
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
297-
SOCKET_ECONNREFUSED
297+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
298298
));
299299

300300
$promise->then(null, $this->expectCallableOnceWith($this->callback(function (\Exception $e) use ($previous) {
@@ -319,7 +319,7 @@ public function testRejectsAndClosesIfStreamWritesNonHttp()
319319
$promise->then(null, $this->expectCallableOnceWithException(
320320
'RuntimeException',
321321
'Connection to tcp://google.com:80 failed because proxy returned invalid response (EBADMSG)',
322-
SOCKET_EBADMSG
322+
defined('SOCKET_EBADMSG') ? SOCKET_EBADMSG: 71
323323
));
324324
}
325325

@@ -340,7 +340,7 @@ public function testRejectsAndClosesIfStreamWritesTooMuchData()
340340
$promise->then(null, $this->expectCallableOnceWithException(
341341
'RuntimeException',
342342
'Connection to tcp://google.com:80 failed because proxy response headers exceed maximum of 8 KiB (EMSGSIZE)',
343-
SOCKET_EMSGSIZE
343+
defined('SOCKET_EMSGSIZE') ? SOCKET_EMSGSIZE : 90
344344
));
345345
}
346346

@@ -361,7 +361,7 @@ public function testRejectsAndClosesIfStreamReturnsProyAuthenticationRequired()
361361
$promise->then(null, $this->expectCallableOnceWithException(
362362
'RuntimeException',
363363
'Connection to tcp://google.com:80 failed because proxy denied access with HTTP error code 407 (Proxy Authentication Required) (EACCES)',
364-
SOCKET_EACCES
364+
defined('SOCKET_EACCES') ? SOCKET_EACCES : 13
365365
));
366366
}
367367

@@ -382,7 +382,7 @@ public function testRejectsAndClosesIfStreamReturnsNonSuccess()
382382
$promise->then(null, $this->expectCallableOnceWithException(
383383
'RuntimeException',
384384
'Connection to tcp://google.com:80 failed because proxy refused connection with HTTP error code 403 (Not allowed) (ECONNREFUSED)',
385-
SOCKET_ECONNREFUSED
385+
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
386386
));
387387
}
388388

@@ -402,7 +402,7 @@ public function testRejectsWithPreviousExceptionIfStreamEmitsError()
402402
$promise->then(null, $this->expectCallableOnceWithException(
403403
'RuntimeException',
404404
'Connection to tcp://google.com:80 failed because connection to proxy caused a stream error (EIO)',
405-
SOCKET_EIO
405+
defined('SOCKET_EIO') ? SOCKET_EIO : 5
406406
));
407407

408408
$promise->then(null, $this->expectCallableOnceWith($this->callback(function (\Exception $e) use ($previous) {
@@ -471,7 +471,7 @@ public function testCancelPromiseWhileConnectionIsReadyWillCloseOpenConnectionAn
471471
$promise->then(null, $this->expectCallableOnceWithException(
472472
'RuntimeException',
473473
'Connection to tcp://google.com:80 cancelled while waiting for proxy (ECONNABORTED)',
474-
SOCKET_ECONNABORTED
474+
defined('SOCKET_ECONNABORTED') ? SOCKET_ECONNABORTED : 103
475475
));
476476
}
477477

0 commit comments

Comments
 (0)