1717use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \FirstResource ;
1818use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResource ;
1919use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResourceOdm ;
20+ use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResourceWithRelation ;
21+ use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResourceWithRelationRelated ;
2022use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \SecondResource ;
2123use ApiPlatform \Tests \Fixtures \TestBundle \Document \MappedDocument ;
2224use ApiPlatform \Tests \Fixtures \TestBundle \Entity \MappedEntity ;
25+ use ApiPlatform \Tests \Fixtures \TestBundle \Entity \MappedResourceWithRelationEntity ;
26+ use ApiPlatform \Tests \Fixtures \TestBundle \Entity \MappedResourceWithRelationRelatedEntity ;
2327use ApiPlatform \Tests \Fixtures \TestBundle \Entity \SameEntity ;
2428use ApiPlatform \Tests \RecreateSchemaTrait ;
2529use ApiPlatform \Tests \SetupClassResourcesTrait ;
@@ -36,12 +40,12 @@ final class MappingTest extends ApiTestCase
3640 */
3741 public static function getResources (): array
3842 {
39- return [MappedResource::class, MappedResourceOdm::class, FirstResource::class, SecondResource::class];
43+ return [MappedResource::class, MappedResourceOdm::class, FirstResource::class, SecondResource::class, MappedResourceWithRelation::class, MappedResourceWithRelationRelated::class ];
4044 }
4145
4246 public function testShouldMapBetweenResourceAndEntity (): void
4347 {
44- if (!$ this ->getContainer ()->has ('object_mapper ' )) {
48+ if (!$ this ->getContainer ()->has ('api_platform. object_mapper ' )) {
4549 $ this ->markTestSkipped ('ObjectMapper not installed ' );
4650 }
4751
@@ -77,7 +81,7 @@ public function testShouldMapToTheCorrectResource(): void
7781 $ this ->markTestSkipped ('MongoDB not tested. ' );
7882 }
7983
80- if (!$ this ->getContainer ()->has ('object_mapper ' )) {
84+ if (!$ this ->getContainer ()->has ('api_platform. object_mapper ' )) {
8185 $ this ->markTestSkipped ('ObjectMapper not installed ' );
8286 }
8387
@@ -94,6 +98,44 @@ public function testShouldMapToTheCorrectResource(): void
9498 ]]);
9599 }
96100
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+
97139 private function loadFixtures (): void
98140 {
99141 $ manager = $ this ->getManager ();
0 commit comments