Skip to content
This repository has been archived by the owner on Dec 14, 2020. It is now read-only.

Commit

Permalink
Merge 9bb545a into 6ce8419
Browse files Browse the repository at this point in the history
  • Loading branch information
nervo committed Sep 5, 2017
2 parents 6ce8419 + 9bb545a commit 5edee1a
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 10 deletions.
Expand Up @@ -83,7 +83,9 @@ private function doParse($class)

private function resolveActualType(ResourceAttributeMetadata $attributeMetadata)
{
if (\DateTime::class === ltrim($attributeMetadata->getOriginalType(), '\\')) {
$originalTypeClass = ltrim($attributeMetadata->getOriginalType(), '\\');

if (in_array($originalTypeClass, [\DateTime::class, \DateTimeImmutable::class, \DateTimeInterface::class])) {
return [DataTypes::DATETIME, null];
}

Expand Down
26 changes: 23 additions & 3 deletions tests/Fixtures/Resource/NewsResource.php
Expand Up @@ -35,9 +35,15 @@ class NewsResource
*/
private $content;

/** @var \DateTime */
/** @var \DateTimeImmutable */
private $createdAt;

/** @var \DateTime */
private $updatedAt;

/** @var \DateTimeInterface */
private $deletedAt;

/** @var string|null */
private $image;

Expand All @@ -59,7 +65,9 @@ public function __construct(
int $identifier,
string $title,
string $content,
\DateTime $createdAt,
\DateTimeImmutable $createdAt,
\DateTime $updatedAt,
\DateTimeInterface $deletedAt,
string $image = null,
bool $urgent = false,
array $references = []
Expand All @@ -68,6 +76,8 @@ public function __construct(
$this->title = $title;
$this->content = $content;
$this->createdAt = $createdAt;
$this->updatedAt = $updatedAt;
$this->deletedAt = $deletedAt;
$this->image = $image;
$this->urgent = $urgent;
$this->references = $references;
Expand All @@ -88,11 +98,21 @@ public function getContent(): string
return $this->content;
}

public function getCreatedAt(): \DateTime
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}

public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}

public function getDeletedAt(): \DateTimeInterface
{
return $this->deletedAt;
}

public function getImage(): string
{
return $this->image;
Expand Down
10 changes: 9 additions & 1 deletion tests/Fixtures/res/resources.yml
Expand Up @@ -6,8 +6,16 @@ resources:
attributes:
createdAt:
type: string
originalType: \DateTime
originalType: \DateTimeImmutable
description: The news creation date formatted to ISO 8601
updatedAt:
type: string
originalType: \DateTime
description: The news modification date formatted to ISO 8601
deletedAt:
type: string
originalType: \DateTimeInterface
description: The news deletion date formatted to ISO 8601
image:
type: file
Elao.ArticleReference: Elao\ApiResourcesMetadata\Tests\Fixtures\Resource\ArticleReferenceResource
Expand Up @@ -76,14 +76,28 @@ public function testParse(array $toParse, $expected)
}

const NEWS_RESOURCE_DUMP = <<<'DUMP'
array:7 [
array:9 [
"createdAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news creation date formatted to ISO 8601"
"readonly" => null
]
"updatedAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news modification date formatted to ISO 8601"
"readonly" => null
]
"deletedAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news deletion date formatted to ISO 8601"
"readonly" => null
]
"image" => array:5 [
"dataType" => "file"
"actualType" => "file"
Expand Down Expand Up @@ -162,14 +176,28 @@ public function testParse(array $toParse, $expected)
"description" => "News for the localized feed"
"readonly" => null
"subType" => "Elao.Newsfeed.News"
"children" => array:7 [
"children" => array:9 [
"createdAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news creation date formatted to ISO 8601"
"readonly" => null
]
"updatedAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news modification date formatted to ISO 8601"
"readonly" => null
]
"deletedAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news deletion date formatted to ISO 8601"
"readonly" => null
]
"image" => array:5 [
"dataType" => "file"
"actualType" => "file"
Expand Down
16 changes: 15 additions & 1 deletion tests/Functional/ResourceMetadataFactoryTest.php
Expand Up @@ -138,14 +138,28 @@ public function testGetMetadataFor($class, $dump)
+class: "Elao\ApiResourcesMetadata\Tests\Fixtures\Resource\NewsResource"
+shortName: "Elao.Newsfeed.News"
+description: "A single news from a newsfeed"
+attributes: array:7 [
+attributes: array:9 [
"createdAt" => Elao\ApiResourcesMetadata\Attribute\ResourceAttributeMetadata {
+name: "createdAt"
+description: "The news creation date formatted to ISO 8601"
+required: true
+type: "string"
+originalType: "\DateTimeImmutable"
}
"updatedAt" => Elao\ApiResourcesMetadata\Attribute\ResourceAttributeMetadata {
+name: "updatedAt"
+description: "The news modification date formatted to ISO 8601"
+required: true
+type: "string"
+originalType: "\DateTime"
}
"deletedAt" => Elao\ApiResourcesMetadata\Attribute\ResourceAttributeMetadata {
+name: "deletedAt"
+description: "The news deletion date formatted to ISO 8601"
+required: true
+type: "string"
+originalType: "\DateTimeInterface"
}
"image" => Elao\ApiResourcesMetadata\Attribute\ResourceAttributeMetadata {
+name: "image"
+description: null
Expand Down
Expand Up @@ -55,14 +55,28 @@ public function testExtractedAnnotations()
"description" => "News for the localized feed"
"readonly" => null
"subType" => "Elao.Newsfeed.News"
"children" => array:7 [
"children" => array:9 [
"createdAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news creation date formatted to ISO 8601"
"readonly" => null
]
"updatedAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news modification date formatted to ISO 8601"
"readonly" => null
]
"deletedAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news deletion date formatted to ISO 8601"
"readonly" => null
]
"image" => array:5 [
"dataType" => "file"
"actualType" => "file"
Expand Down Expand Up @@ -195,14 +209,28 @@ public function testExtractedAnnotations()
"description" => "News for the localized feed"
"readonly" => null
"subType" => "Elao.Newsfeed.News"
"children" => array:7 [
"children" => array:9 [
"createdAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news creation date formatted to ISO 8601"
"readonly" => null
]
"updatedAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news modification date formatted to ISO 8601"
"readonly" => null
]
"deletedAt" => array:5 [
"dataType" => "string"
"actualType" => "datetime"
"required" => true
"description" => "The news deletion date formatted to ISO 8601"
"readonly" => null
]
"image" => array:5 [
"dataType" => "file"
"actualType" => "file"
Expand Down
Expand Up @@ -98,6 +98,16 @@ public function testSwaggerDump()
"description":"The news creation date formatted to ISO 8601",
"format":"date-time"
},
"updatedAt":{
"type":"string",
"description":"The news modification date formatted to ISO 8601",
"format":"date-time"
},
"deletedAt":{
"type":"string",
"description":"The news deletion date formatted to ISO 8601",
"format":"date-time"
},
"identifier":{
"type":"integer",
"description":"Unique identifier",
Expand Down Expand Up @@ -130,6 +140,8 @@ public function testSwaggerDump()
},
"required":[
"createdAt",
"updatedAt",
"deletedAt",
"identifier",
"title",
"content",
Expand Down

0 comments on commit 5edee1a

Please sign in to comment.