fix index, add test case in php client (#1994)

This commit is contained in:
William Cheng 2019-01-27 19:29:59 +08:00 committed by Akihito Nakano
parent 4f8164e713
commit c438f67b66
4 changed files with 14 additions and 3 deletions

View File

@ -474,7 +474,7 @@ class Configuration
$hosts = $this->getHostSettings();
// check array index out of bound
if ($index < 0 || $index > sizeof($hosts)) {
if ($index < 0 || $index >= sizeof($hosts)) {
throw new \InvalidArgumentException("Invalid index $index when selecting the host. Must be less than ".sizeof($hosts));
}

View File

@ -458,7 +458,7 @@ class Configuration
$hosts = $this->getHostSettings();
// check array index out of bound
if ($index < 0 || $index > sizeof($hosts)) {
if ($index < 0 || $index >= sizeof($hosts)) {
throw new \InvalidArgumentException("Invalid index $index when selecting the host. Must be less than ".sizeof($hosts));
}

View File

@ -491,7 +491,7 @@ class Configuration
$hosts = $this->getHostSettings();
// check array index out of bound
if ($index < 0 || $index > sizeof($hosts)) {
if ($index < 0 || $index >= sizeof($hosts)) {
throw new \InvalidArgumentException("Invalid index $index when selecting the host. Must be less than ".sizeof($hosts));
}

View File

@ -41,6 +41,17 @@ class ConfigurationTest extends TestCase
$this->assertSame("http://dev-petstore.swagger.io:8080/v2", $url);
}
/**
* Test invalid index
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid index 2 when selecting the host. Must be less than 2
*/
public function testInvalidIndex()
{
$config = new Configuration();
$url = $config->getHostFromSettings(2);
}
/**
* Test host settings with invalid vaues
* @expectedException InvalidArgumentException