forked from loafle/openapi-generator-original
* [PHP] Honor Swagger/OpenAPI 'date' format Per spec (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types), DateTime instances defined as 'date' datatype need to be serialized as defined by full-date - RFC3339, which has the format: full-date = date-fullyear "-" date-month "-" date-mday ref: https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14 see #5531 fixes #5607 * [PHP] Add `date` and `date-time` serializer tests See #5531 See #5607 * [PHP] Improve codestyle of generated code * [PHP] Regenerate PHP Petstore sample * [PHP] Regenerate PHP Security sample
35 lines
816 B
PHP
35 lines
816 B
PHP
<?php
|
|
|
|
namespace Swagger\Client;
|
|
|
|
use Swagger\Client\Model\FormatTest;
|
|
|
|
class DateTimeSerializerTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testDateTimeSanitazion()
|
|
{
|
|
$dateTime = new \DateTime('April 30, 1973 17:05 CEST');
|
|
|
|
$input = new FormatTest([
|
|
'date_time' => $dateTime,
|
|
]);
|
|
|
|
$data = ObjectSerializer::sanitizeForSerialization($input);
|
|
|
|
$this->assertEquals($data->dateTime, '1973-04-30T17:05:00+02:00');
|
|
}
|
|
|
|
public function testDateSanitazion()
|
|
{
|
|
$dateTime = new \DateTime('April 30, 1973 17:05 CEST');
|
|
|
|
$input = new FormatTest([
|
|
'date' => $dateTime,
|
|
]);
|
|
|
|
$data = ObjectSerializer::sanitizeForSerialization($input);
|
|
|
|
$this->assertEquals($data->date, '1973-04-30');
|
|
}
|
|
}
|