forked from loafle/openapi-generator-original
* Set PHP 7.2 as minimum version * Update PHPUnit to 8 || 9 * Set Bionic environment in Travis config * PHPUnit 8 requires void return in static methods * PHPUnit 8 requires void return in static methods * Fix curl exception message test When I run "curl http://wrong_host.zxc" output is: curl: (6) Could not resolve host: wrong_host.zxc Maybe this message is different across versions. Tested curl version: curl 7.54.0 (x86_64-apple-darwin18.0) libcurl/7.54.0 LibreSSL/2.6.5 zlib/1.2.11 nghttp2/1.24.1 * Update assertions of deprecated assertInternalType * Migrate to expectException method of PHPUnit 8 * Fix PHPCS Fixer errors * Replace deprecated 'assertRegExp' assertion * Exclude PHPUnit and php-cs-fixer cache * Refresh samples * Set root Travis CI environment to PHP 7.2.5 * Change to 7.3 as 7.2.27 is highest preinstalled * Fix testWrongHost test
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);
|
|
}
|
|
}
|