17
17
use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \FirstResource ;
18
18
use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResource ;
19
19
use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResourceOdm ;
20
+ use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResourceWithRelation ;
21
+ use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResourceWithRelationRelated ;
20
22
use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \SecondResource ;
21
23
use ApiPlatform \Tests \Fixtures \TestBundle \Document \MappedDocument ;
22
24
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \MappedEntity ;
25
+ use ApiPlatform \Tests \Fixtures \TestBundle \Entity \MappedResourceWithRelationEntity ;
26
+ use ApiPlatform \Tests \Fixtures \TestBundle \Entity \MappedResourceWithRelationRelatedEntity ;
23
27
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \SameEntity ;
24
28
use ApiPlatform \Tests \RecreateSchemaTrait ;
25
29
use ApiPlatform \Tests \SetupClassResourcesTrait ;
@@ -36,12 +40,12 @@ final class MappingTest extends ApiTestCase
36
40
*/
37
41
public static function getResources (): array
38
42
{
39
- return [MappedResource::class, MappedResourceOdm::class, FirstResource::class, SecondResource::class];
43
+ return [MappedResource::class, MappedResourceOdm::class, FirstResource::class, SecondResource::class, MappedResourceWithRelation::class, MappedResourceWithRelationRelated::class ];
40
44
}
41
45
42
46
public function testShouldMapBetweenResourceAndEntity (): void
43
47
{
44
- if (!$ this ->getContainer ()->has ('object_mapper ' )) {
48
+ if (!$ this ->getContainer ()->has ('api_platform. object_mapper ' )) {
45
49
$ this ->markTestSkipped ('ObjectMapper not installed ' );
46
50
}
47
51
@@ -77,7 +81,7 @@ public function testShouldMapToTheCorrectResource(): void
77
81
$ this ->markTestSkipped ('MongoDB not tested. ' );
78
82
}
79
83
80
- if (!$ this ->getContainer ()->has ('object_mapper ' )) {
84
+ if (!$ this ->getContainer ()->has ('api_platform. object_mapper ' )) {
81
85
$ this ->markTestSkipped ('ObjectMapper not installed ' );
82
86
}
83
87
@@ -94,6 +98,44 @@ public function testShouldMapToTheCorrectResource(): void
94
98
]]);
95
99
}
96
100
101
+ public function testMapPutAllowCreate (): void
102
+ {
103
+ if (!$ this ->getContainer ()->has ('api_platform.object_mapper ' )) {
104
+ $ this ->markTestSkipped ('ObjectMapper not installed ' );
105
+ }
106
+
107
+ if ($ this ->isMongoDB ()) {
108
+ $ this ->markTestSkipped ('MongoDB is not tested ' );
109
+ }
110
+
111
+ $ this ->recreateSchema ([MappedResourceWithRelationEntity::class, MappedResourceWithRelationRelatedEntity::class]);
112
+ $ manager = $ this ->getManager ();
113
+
114
+ $ e = new MappedResourceWithRelationRelatedEntity ();
115
+ $ e ->name = 'test ' ;
116
+ $ manager ->persist ($ e );
117
+ $ manager ->flush ();
118
+
119
+ self ::createClient ()->request ('PUT ' , '/mapped_resource_with_relations/4 ' , [
120
+ 'json ' => [
121
+ '@id ' => '/mapped_resource_with_relations/4 ' ,
122
+ 'relation ' => '/mapped_resource_with_relation_relateds/ ' .$ e ->getId (),
123
+ ],
124
+ 'headers ' => [
125
+ 'content-type ' => 'application/ld+json ' ,
126
+ ],
127
+ ]);
128
+
129
+ $ this ->assertJsonContains ([
130
+ '@context ' => '/contexts/MappedResourceWithRelation ' ,
131
+ '@id ' => '/mapped_resource_with_relations/4 ' ,
132
+ '@type ' => 'MappedResourceWithRelation ' ,
133
+ 'id ' => '4 ' ,
134
+ 'relationName ' => 'test ' ,
135
+ 'relation ' => '/mapped_resource_with_relation_relateds/1 ' ,
136
+ ]);
137
+ }
138
+
97
139
private function loadFixtures (): void
98
140
{
99
141
$ manager = $ this ->getManager ();
0 commit comments