forked from loafle/openapi-generator-original
* php-nextgen first commit * [php] Set minimal PHP version to ^8.0 (#14500) * Set minimal PHP version to ^8.0 * Fix php-nextgen config * Change stability to BETA * Add phplint package (#15054) * [php-nextgen] Rename folders to follow PDS skeleton (#15102) * Change lib -> src, test -> tests folder This will make build compliant to PHP-PDS skeleton. Ref: https://github.com/php-pds/skeleton * Refresh samples * Exclude composer.lock from codebase (#15105) Since client generator is library and not a project it makes sense to exclude composer.lock from codebase by default. Ref: http://getcomposer.org/doc/02-libraries.md#lock-file * Add @generated tag to DocBlocks (#15106) This tag in draft status right now(PSR-19), but I think we can leverage from it already. Ref: https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc-tags.md#55-generated * update samples, doc * update samples --------- Co-authored-by: Yuriy Belenko <yura-bely@mail.ru>
96 lines
2.4 KiB
PHP
96 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace OpenAPI\Client;
|
|
|
|
use OpenAPI\Client\Model\EnumTest;
|
|
use OpenAPI\Client\Model\OuterEnum;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class OuterEnumTest extends TestCase
|
|
{
|
|
public function testDeserialize()
|
|
{
|
|
$result = ObjectSerializer::deserialize(
|
|
"placed",
|
|
OuterEnum::class
|
|
);
|
|
|
|
$this->assertIsString($result);
|
|
$this->assertEquals('placed', $result);
|
|
}
|
|
|
|
public function testDeserializeInvalidValue()
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('Invalid value for enum');
|
|
ObjectSerializer::deserialize(
|
|
"lkjfalgkdfjg",
|
|
OuterEnum::class
|
|
);
|
|
}
|
|
|
|
public function testDeserializeNested()
|
|
{
|
|
$json = '{
|
|
"enum_string": "UPPER",
|
|
"enum_integer": -1,
|
|
"enum_number": -1.2,
|
|
"outerEnum": "approved"
|
|
}';
|
|
|
|
/** * @var EnumTest $result */
|
|
$result = ObjectSerializer::deserialize(
|
|
json_decode($json),
|
|
EnumTest::class
|
|
);
|
|
|
|
$this->assertInstanceOf(EnumTest::class, $result);
|
|
$this->assertEquals('approved', $result->getOuterEnum());
|
|
}
|
|
|
|
public function testSanitize()
|
|
{
|
|
$json = "placed";
|
|
|
|
$result = ObjectSerializer::sanitizeForSerialization(
|
|
$json
|
|
);
|
|
|
|
$this->assertIsString($result);
|
|
}
|
|
|
|
public function testSanitizeNested()
|
|
{
|
|
$input = new EnumTest([
|
|
'enum_string' => 'UPPER',
|
|
'enum_integer' => -1,
|
|
'enum_number' => -1.2,
|
|
'outer_enum' => 'approved'
|
|
]);
|
|
|
|
$result = ObjectSerializer::sanitizeForSerialization(
|
|
$input
|
|
);
|
|
|
|
$this->assertIsObject($result);
|
|
$this->assertInstanceOf(\stdClass::class, $result);
|
|
|
|
$this->assertIsString($result->outerEnum);
|
|
$this->assertEquals('approved', $result->outerEnum);
|
|
}
|
|
|
|
public function testSanitizeNestedInvalidValue()
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('Invalid value for enum');
|
|
$input = new EnumTest([
|
|
'enum_string' => 'UPPER',
|
|
'enum_integer' => -1,
|
|
'enum_number' => -1.2,
|
|
'outer_enum' => 'invalid_value'
|
|
]);
|
|
|
|
ObjectSerializer::sanitizeForSerialization($input);
|
|
}
|
|
}
|