diff --git a/modules/swagger-codegen/src/main/resources/php/model_generic.mustache b/modules/swagger-codegen/src/main/resources/php/model_generic.mustache index ec90e6e3ab1..c9300084b0f 100644 --- a/modules/swagger-codegen/src/main/resources/php/model_generic.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model_generic.mustache @@ -194,7 +194,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa {{#isEnum}} {{^isContainer}} $allowedValues = $this->{{getter}}AllowableValues(); - if (!is_null($this->container['{{name}}']) && !in_array($this->container['{{name}}'], $allowedValues)) { + if (!is_null($this->container['{{name}}']) && !in_array($this->container['{{name}}'], $allowedValues, true)) { $invalidProperties[] = sprintf( "invalid value for '{{name}}', must be one of '%s'", implode("', '", $allowedValues) @@ -274,7 +274,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa {{#isEnum}} {{^isContainer}} $allowedValues = $this->{{getter}}AllowableValues(); - if (!is_null($this->container['{{name}}']) && !in_array($this->container['{{name}}'], $allowedValues)) { + if (!is_null($this->container['{{name}}']) && !in_array($this->container['{{name}}'], $allowedValues, true)) { return false; } {{/isContainer}} @@ -344,7 +344,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa {{#isEnum}} $allowedValues = $this->{{getter}}AllowableValues(); {{^isContainer}} - if ({{^required}}!is_null(${{name}}) && {{/required}}!in_array(${{{name}}}, $allowedValues)) { + if ({{^required}}!is_null(${{name}}) && {{/required}}!in_array(${{{name}}}, $allowedValues, true)) { throw new \InvalidArgumentException( sprintf( "Invalid value for '{{name}}', must be one of '%s'", diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php index 6720f6bb8c5..667106ab45f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php @@ -226,7 +226,7 @@ class EnumArrays implements ModelInterface, ArrayAccess $invalidProperties = []; $allowedValues = $this->getJustSymbolAllowableValues(); - if (!is_null($this->container['just_symbol']) && !in_array($this->container['just_symbol'], $allowedValues)) { + if (!is_null($this->container['just_symbol']) && !in_array($this->container['just_symbol'], $allowedValues, true)) { $invalidProperties[] = sprintf( "invalid value for 'just_symbol', must be one of '%s'", implode("', '", $allowedValues) @@ -246,7 +246,7 @@ class EnumArrays implements ModelInterface, ArrayAccess { $allowedValues = $this->getJustSymbolAllowableValues(); - if (!is_null($this->container['just_symbol']) && !in_array($this->container['just_symbol'], $allowedValues)) { + if (!is_null($this->container['just_symbol']) && !in_array($this->container['just_symbol'], $allowedValues, true)) { return false; } return true; @@ -273,7 +273,7 @@ class EnumArrays implements ModelInterface, ArrayAccess public function setJustSymbol($just_symbol) { $allowedValues = $this->getJustSymbolAllowableValues(); - if (!is_null($just_symbol) && !in_array($just_symbol, $allowedValues)) { + if (!is_null($just_symbol) && !in_array($just_symbol, $allowedValues, true)) { throw new \InvalidArgumentException( sprintf( "Invalid value for 'just_symbol', must be one of '%s'", diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php index 5c097931fd6..e63084d94a1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php @@ -278,7 +278,7 @@ class EnumTest implements ModelInterface, ArrayAccess $invalidProperties = []; $allowedValues = $this->getEnumStringAllowableValues(); - if (!is_null($this->container['enum_string']) && !in_array($this->container['enum_string'], $allowedValues)) { + if (!is_null($this->container['enum_string']) && !in_array($this->container['enum_string'], $allowedValues, true)) { $invalidProperties[] = sprintf( "invalid value for 'enum_string', must be one of '%s'", implode("', '", $allowedValues) @@ -289,7 +289,7 @@ class EnumTest implements ModelInterface, ArrayAccess $invalidProperties[] = "'enum_string_required' can't be null"; } $allowedValues = $this->getEnumStringRequiredAllowableValues(); - if (!is_null($this->container['enum_string_required']) && !in_array($this->container['enum_string_required'], $allowedValues)) { + if (!is_null($this->container['enum_string_required']) && !in_array($this->container['enum_string_required'], $allowedValues, true)) { $invalidProperties[] = sprintf( "invalid value for 'enum_string_required', must be one of '%s'", implode("', '", $allowedValues) @@ -297,7 +297,7 @@ class EnumTest implements ModelInterface, ArrayAccess } $allowedValues = $this->getEnumIntegerAllowableValues(); - if (!is_null($this->container['enum_integer']) && !in_array($this->container['enum_integer'], $allowedValues)) { + if (!is_null($this->container['enum_integer']) && !in_array($this->container['enum_integer'], $allowedValues, true)) { $invalidProperties[] = sprintf( "invalid value for 'enum_integer', must be one of '%s'", implode("', '", $allowedValues) @@ -305,7 +305,7 @@ class EnumTest implements ModelInterface, ArrayAccess } $allowedValues = $this->getEnumNumberAllowableValues(); - if (!is_null($this->container['enum_number']) && !in_array($this->container['enum_number'], $allowedValues)) { + if (!is_null($this->container['enum_number']) && !in_array($this->container['enum_number'], $allowedValues, true)) { $invalidProperties[] = sprintf( "invalid value for 'enum_number', must be one of '%s'", implode("', '", $allowedValues) @@ -325,22 +325,22 @@ class EnumTest implements ModelInterface, ArrayAccess { $allowedValues = $this->getEnumStringAllowableValues(); - if (!is_null($this->container['enum_string']) && !in_array($this->container['enum_string'], $allowedValues)) { + if (!is_null($this->container['enum_string']) && !in_array($this->container['enum_string'], $allowedValues, true)) { return false; } if ($this->container['enum_string_required'] === null) { return false; } $allowedValues = $this->getEnumStringRequiredAllowableValues(); - if (!is_null($this->container['enum_string_required']) && !in_array($this->container['enum_string_required'], $allowedValues)) { + if (!is_null($this->container['enum_string_required']) && !in_array($this->container['enum_string_required'], $allowedValues, true)) { return false; } $allowedValues = $this->getEnumIntegerAllowableValues(); - if (!is_null($this->container['enum_integer']) && !in_array($this->container['enum_integer'], $allowedValues)) { + if (!is_null($this->container['enum_integer']) && !in_array($this->container['enum_integer'], $allowedValues, true)) { return false; } $allowedValues = $this->getEnumNumberAllowableValues(); - if (!is_null($this->container['enum_number']) && !in_array($this->container['enum_number'], $allowedValues)) { + if (!is_null($this->container['enum_number']) && !in_array($this->container['enum_number'], $allowedValues, true)) { return false; } return true; @@ -367,7 +367,7 @@ class EnumTest implements ModelInterface, ArrayAccess public function setEnumString($enum_string) { $allowedValues = $this->getEnumStringAllowableValues(); - if (!is_null($enum_string) && !in_array($enum_string, $allowedValues)) { + if (!is_null($enum_string) && !in_array($enum_string, $allowedValues, true)) { throw new \InvalidArgumentException( sprintf( "Invalid value for 'enum_string', must be one of '%s'", @@ -400,7 +400,7 @@ class EnumTest implements ModelInterface, ArrayAccess public function setEnumStringRequired($enum_string_required) { $allowedValues = $this->getEnumStringRequiredAllowableValues(); - if (!in_array($enum_string_required, $allowedValues)) { + if (!in_array($enum_string_required, $allowedValues, true)) { throw new \InvalidArgumentException( sprintf( "Invalid value for 'enum_string_required', must be one of '%s'", @@ -433,7 +433,7 @@ class EnumTest implements ModelInterface, ArrayAccess public function setEnumInteger($enum_integer) { $allowedValues = $this->getEnumIntegerAllowableValues(); - if (!is_null($enum_integer) && !in_array($enum_integer, $allowedValues)) { + if (!is_null($enum_integer) && !in_array($enum_integer, $allowedValues, true)) { throw new \InvalidArgumentException( sprintf( "Invalid value for 'enum_integer', must be one of '%s'", @@ -466,7 +466,7 @@ class EnumTest implements ModelInterface, ArrayAccess public function setEnumNumber($enum_number) { $allowedValues = $this->getEnumNumberAllowableValues(); - if (!is_null($enum_number) && !in_array($enum_number, $allowedValues)) { + if (!is_null($enum_number) && !in_array($enum_number, $allowedValues, true)) { throw new \InvalidArgumentException( sprintf( "Invalid value for 'enum_number', must be one of '%s'", diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php index 0089f45bcf7..5d6bd5f222b 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -237,7 +237,7 @@ class Order implements ModelInterface, ArrayAccess $invalidProperties = []; $allowedValues = $this->getStatusAllowableValues(); - if (!is_null($this->container['status']) && !in_array($this->container['status'], $allowedValues)) { + if (!is_null($this->container['status']) && !in_array($this->container['status'], $allowedValues, true)) { $invalidProperties[] = sprintf( "invalid value for 'status', must be one of '%s'", implode("', '", $allowedValues) @@ -257,7 +257,7 @@ class Order implements ModelInterface, ArrayAccess { $allowedValues = $this->getStatusAllowableValues(); - if (!is_null($this->container['status']) && !in_array($this->container['status'], $allowedValues)) { + if (!is_null($this->container['status']) && !in_array($this->container['status'], $allowedValues, true)) { return false; } return true; @@ -380,7 +380,7 @@ class Order implements ModelInterface, ArrayAccess public function setStatus($status) { $allowedValues = $this->getStatusAllowableValues(); - if (!is_null($status) && !in_array($status, $allowedValues)) { + if (!is_null($status) && !in_array($status, $allowedValues, true)) { throw new \InvalidArgumentException( sprintf( "Invalid value for 'status', must be one of '%s'", diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php index 73e73c892fc..8c78b7a553e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -243,7 +243,7 @@ class Pet implements ModelInterface, ArrayAccess $invalidProperties[] = "'photo_urls' can't be null"; } $allowedValues = $this->getStatusAllowableValues(); - if (!is_null($this->container['status']) && !in_array($this->container['status'], $allowedValues)) { + if (!is_null($this->container['status']) && !in_array($this->container['status'], $allowedValues, true)) { $invalidProperties[] = sprintf( "invalid value for 'status', must be one of '%s'", implode("', '", $allowedValues) @@ -269,7 +269,7 @@ class Pet implements ModelInterface, ArrayAccess return false; } $allowedValues = $this->getStatusAllowableValues(); - if (!is_null($this->container['status']) && !in_array($this->container['status'], $allowedValues)) { + if (!is_null($this->container['status']) && !in_array($this->container['status'], $allowedValues, true)) { return false; } return true; @@ -416,7 +416,7 @@ class Pet implements ModelInterface, ArrayAccess public function setStatus($status) { $allowedValues = $this->getStatusAllowableValues(); - if (!is_null($status) && !in_array($status, $allowedValues)) { + if (!is_null($status) && !in_array($status, $allowedValues, true)) { throw new \InvalidArgumentException( sprintf( "Invalid value for 'status', must be one of '%s'", diff --git a/samples/client/petstore/php/SwaggerClient-php/phpunit.xml.dist b/samples/client/petstore/php/SwaggerClient-php/phpunit.xml.dist index cadedbc2469..c12ee148477 100644 --- a/samples/client/petstore/php/SwaggerClient-php/phpunit.xml.dist +++ b/samples/client/petstore/php/SwaggerClient-php/phpunit.xml.dist @@ -14,8 +14,8 @@ - ./lib\Api - ./lib\Model + ./lib/Api + ./lib/Model diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Model/EnumTestTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Model/EnumTestTest.php index 1a2350c6f22..a5a71a14970 100644 --- a/samples/client/petstore/php/SwaggerClient-php/test/Model/EnumTestTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/test/Model/EnumTestTest.php @@ -83,6 +83,13 @@ class EnumTestTest extends \PHPUnit_Framework_TestCase { } + /** + * Test attribute "enum_string_required" + */ + public function testPropertyEnumStringRequired() + { + } + /** * Test attribute "enum_integer" */ diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/EnumTestTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/EnumTestTest.php index 9e4ea589251..834c4703104 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/EnumTestTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/EnumTestTest.php @@ -16,6 +16,30 @@ class EnumTestTest extends \PHPUnit_Framework_TestCase $this->assertSame(EnumTest::ENUM_NUMBER_MINUS_1_DOT_2, -1.2); } + public function testStrictValidation() + { + $enum = new EnumTest([ + 'enum_string' => 0, + ]); + + $this->assertFalse($enum->valid()); + + $expected = [ + "invalid value for 'enum_string', must be one of 'UPPER', 'lower', ''", + "'enum_string_required' can't be null", + ]; + $this->assertSame($expected, $enum->listInvalidProperties()); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testThrowExceptionWhenInvalidAmbiguousValueHasPassed() + { + $enum = new EnumTest(); + $enum->setEnumString(0); + } + public function testNonRequiredPropertyIsOptional() { $enum = new EnumTest([