Skip to content

Commit

Permalink
Use Number Codes if Error Constants are undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Oct 14, 2020
1 parent 1889b0e commit 69b9bf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
21 changes: 4 additions & 17 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testNonListeningSocketRejectsConnection()
$this->setExpectedException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
SOCKET_ECONNREFUSED
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
);
Block\await($promise, $this->loop, 3.0);
}
Expand All @@ -54,7 +54,7 @@ public function testPlainGoogleDoesNotAcceptConnectMethod()
$this->setExpectedException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because proxy refused connection with HTTP error code 405 (Method Not Allowed) (ECONNREFUSED)',
SOCKET_ECONNREFUSED
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
);
Block\await($promise, $this->loop, 3.0);
}
Expand All @@ -73,7 +73,7 @@ public function testSecureGoogleDoesNotAcceptConnectMethod()
$this->setExpectedException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because proxy refused connection with HTTP error code 405 (Method Not Allowed) (ECONNREFUSED)',
SOCKET_ECONNREFUSED
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
);
Block\await($promise, $this->loop, 3.0);
}
Expand All @@ -87,7 +87,7 @@ public function testSecureGoogleDoesNotAcceptPlainStream()
$this->setExpectedException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because connection to proxy was lost while waiting for response (ECONNRESET)',
SOCKET_ECONNRESET
defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 104
);
Block\await($promise, $this->loop, 3.0);
}
Expand All @@ -108,17 +108,4 @@ public function testCancelWhileConnectingShouldNotCreateGarbageCycles()

$this->assertEquals(0, gc_collect_cycles());
}

public function setExpectedException($exception, $message = '', $code = 0)
{
if (method_exists($this, 'expectException')) {
$this->expectException($exception);
if ($message !== null) {
$this->expectExceptionMessage($message);
}
$this->expectExceptionCode($code);
} else {
parent::setExpectedException($exception, $message, $code);
}
}
}
14 changes: 7 additions & 7 deletions tests/ProxyConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function testRejectsWithPreviousIfConnectorRejects()
$promise->then(null, $this->expectCallableOnceWithException(
'RuntimeException',
'Connection to tcp://google.com:80 failed because connection to proxy failed (ECONNREFUSED)',
SOCKET_ECONNREFUSED
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
));

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

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

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

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

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

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

Expand Down

0 comments on commit 69b9bf2

Please sign in to comment.