mirror of
https://github.com/predis/predis.git
synced 2026-08-21 00:21:50 +00:00
Fix incorrect usage of instance method in static method.
We also added a test to check that the socket-based connection backend throws an exception when unable to resolve hostnames.
This commit is contained in:
@@ -229,7 +229,7 @@ class PhpiredisSocketConnection extends AbstractConnection
|
||||
* @param ParametersInterface $parameters Parameters used to initialize the connection.
|
||||
* @return string
|
||||
*/
|
||||
private static function getAddress(ParametersInterface $parameters)
|
||||
protected static function getAddress(ParametersInterface $parameters)
|
||||
{
|
||||
if ($parameters->scheme === 'unix') {
|
||||
return $parameters->path;
|
||||
@@ -238,8 +238,8 @@ class PhpiredisSocketConnection extends AbstractConnection
|
||||
$host = $parameters->host;
|
||||
|
||||
if (ip2long($host) === false) {
|
||||
if (($addresses = gethostbynamel($host)) === false) {
|
||||
$this->onConnectionError("Cannot resolve the address of '$host'.");
|
||||
if (false === $addresses = gethostbynamel($host)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $addresses[array_rand($addresses)];
|
||||
@@ -256,7 +256,10 @@ class PhpiredisSocketConnection extends AbstractConnection
|
||||
*/
|
||||
private function connectWithTimeout(ParametersInterface $parameters)
|
||||
{
|
||||
$host = self::getAddress($parameters);
|
||||
if (false === $host = self::getAddress($parameters)) {
|
||||
$this->onConnectionError("Cannot resolve the address of '$parameters->host'.");
|
||||
}
|
||||
|
||||
$socket = $this->getResource();
|
||||
|
||||
socket_set_nonblock($socket);
|
||||
|
||||
@@ -86,6 +86,18 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase
|
||||
$this->assertSame(array('foo', 'hoge', 'lol'), $connection->executeCommand($cmdLrange));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @expectedException Predis\Connection\ConnectionException
|
||||
* @expectedExceptionMessage Cannot resolve the address of 'bogus.tld'.
|
||||
*/
|
||||
public function testThrowsExceptionOnUnresolvableHostname()
|
||||
{
|
||||
$parameters = $this->getParameters(array('host' => 'bogus.tld'));
|
||||
$connection = new PhpiredisSocketConnection($parameters);
|
||||
$connection->connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group connected
|
||||
* @expectedException Predis\Protocol\ProtocolException
|
||||
|
||||
Reference in New Issue
Block a user