|
16 | 16 | use Undabot\SymfonyJsonApi\Service\Resource\Builder\ResourceAttributesBuilder; |
17 | 17 | use Undabot\SymfonyJsonApi\Service\Resource\Builder\ResourceRelationshipsBuilder; |
18 | 18 | use Undabot\SymfonyJsonApi\Service\Resource\Denormalizer\Exception\MissingDataValueResourceDenormalizationException; |
19 | | -use Undabot\SymfonyJsonApi\Service\Resource\Denormalizer\Exception\ResourceDenormalizationException; |
20 | 19 | use Undabot\SymfonyJsonApi\Service\Resource\Denormalizer\ResourceDenormalizer; |
21 | 20 | use Undabot\SymfonyJsonApi\Service\Resource\Factory\ResourceMetadataFactory; |
22 | 21 | use Undabot\SymfonyJsonApi\Service\Resource\Validation\Constraint\ResourceType; |
|
26 | 25 | */ |
27 | 26 | class AliasedResourceDto implements ApiModel |
28 | 27 | { |
29 | | - /** |
30 | | - * @var string |
31 | | - */ |
32 | | - private $id; |
33 | | - |
34 | | - /** |
35 | | - * @var string |
36 | | - * @JsonApi\Attribute(name="name") |
37 | | - */ |
38 | | - private $title; |
39 | | - |
40 | | - /** |
41 | | - * @var null|string |
42 | | - * @JsonApi\Attribute(name="description") |
43 | | - */ |
44 | | - private $summary; |
45 | | - |
46 | | - /** |
47 | | - * @var array |
48 | | - * @JsonApi\ToMany(name="tags", type="tag") |
49 | | - */ |
50 | | - private $tagIds; |
51 | | - |
52 | | - /** |
53 | | - * @var null|string |
54 | | - * @JsonApi\ToOne(name="owner", type="person") |
55 | | - */ |
56 | | - private $ownerId; |
57 | | - |
58 | | - public function __construct(string $id, string $title, ?string $summary, array $tagIds, ?string $ownerId) |
59 | | - { |
60 | | - $this->id = $id; |
61 | | - $this->title = $title; |
62 | | - $this->summary = $summary; |
63 | | - $this->tagIds = $tagIds; |
64 | | - $this->ownerId = $ownerId; |
65 | | - } |
66 | | - |
67 | | - public function getId(): string |
68 | | - { |
69 | | - return $this->id; |
70 | | - } |
71 | | - |
72 | | - public function getTitle(): string |
73 | | - { |
74 | | - return $this->title; |
75 | | - } |
76 | | - |
77 | | - public function getSummary(): ?string |
78 | | - { |
79 | | - return $this->summary; |
80 | | - } |
81 | | - |
82 | | - public function getTagIds(): array |
83 | | - { |
84 | | - return $this->tagIds; |
85 | | - } |
86 | | - |
87 | | - public function getOwnerId(): ?string |
88 | | - { |
89 | | - return $this->ownerId; |
| 28 | + public function __construct( |
| 29 | + public string $id, |
| 30 | + /** @JsonApi\Attribute(name="name") */ |
| 31 | + public string $title, |
| 32 | + /** @JsonApi\Attribute(name="description") */ |
| 33 | + public ?string $summary, |
| 34 | + /** @JsonApi\ToMany(name="tags", type="tag") */ |
| 35 | + public array $tagIds, |
| 36 | + /** @JsonApi\ToOne(name="owner", type="person") */ |
| 37 | + public ?string $ownerId |
| 38 | + ) { |
90 | 39 | } |
91 | 40 | } |
92 | 41 |
|
93 | 42 | /** |
94 | 43 | * @internal |
95 | | - * @coversNothing |
| 44 | + * @covers \Undabot\SymfonyJsonApi\Service\Resource\Denormalizer\ResourceDenormalizer |
96 | 45 | * |
97 | 46 | * @small |
98 | 47 | */ |
99 | 48 | final class ResourceWithAliasesDenormalizerTest extends TestCase |
100 | 49 | { |
101 | | - /** @var ResourceDenormalizer */ |
102 | | - private $serializer; |
| 50 | + private ResourceDenormalizer $serializer; |
103 | 51 |
|
104 | 52 | protected function setUp(): void |
105 | 53 | { |
@@ -133,10 +81,10 @@ public function testSimpleResourceCanBeDenormalized(): void |
133 | 81 | $dto = $this->serializer->denormalize($resource, AliasedResourceDto::class); |
134 | 82 | static::assertInstanceOf(AliasedResourceDto::class, $dto); |
135 | 83 |
|
136 | | - static::assertSame('This is my title', $dto->getTitle()); |
137 | | - static::assertSame('This is my summary', $dto->getSummary()); |
138 | | - static::assertSame('p1', $dto->getOwnerId()); |
139 | | - static::assertSame(['t1', 't2', 't3'], $dto->getTagIds()); |
| 84 | + static::assertSame('This is my title', $dto->title); |
| 85 | + static::assertSame('This is my summary', $dto->summary); |
| 86 | + static::assertSame('p1', $dto->ownerId); |
| 87 | + static::assertSame(['t1', 't2', 't3'], $dto->tagIds); |
140 | 88 | } |
141 | 89 |
|
142 | 90 | public function testDenormalizationOfInvalidResourceResultsWithException(): void |
@@ -218,6 +166,6 @@ public function testResourceWithAliasedOptionalToOneRelationshipCanBeDenormalize |
218 | 166 | /** @var AliasedResourceDto $dto */ |
219 | 167 | $dto = $this->serializer->denormalize($resource, AliasedResourceDto::class); |
220 | 168 | static::assertInstanceOf(AliasedResourceDto::class, $dto); |
221 | | - static::assertNull($dto->getOwnerId()); |
| 169 | + static::assertNull($dto->ownerId); |
222 | 170 | } |
223 | 171 | } |
0 commit comments