14
14
namespace ApiPlatform \Tests \Functional ;
15
15
16
16
use ApiPlatform \Symfony \Bundle \Test \ApiTestCase ;
17
+ use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \FirstResource ;
17
18
use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResource ;
18
19
use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResourceOdm ;
20
+ use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \SecondResource ;
19
21
use ApiPlatform \Tests \Fixtures \TestBundle \Document \MappedDocument ;
20
22
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \MappedEntity ;
23
+ use ApiPlatform \Tests \Fixtures \TestBundle \Entity \SameEntity ;
21
24
use ApiPlatform \Tests \RecreateSchemaTrait ;
22
25
use ApiPlatform \Tests \SetupClassResourcesTrait ;
23
26
use Doctrine \ODM \MongoDB \DocumentManager ;
@@ -33,7 +36,7 @@ final class MappingTest extends ApiTestCase
33
36
*/
34
37
public static function getResources (): array
35
38
{
36
- return [MappedResource::class, MappedResourceOdm::class];
39
+ return [MappedResource::class, MappedResourceOdm::class, FirstResource::class, SecondResource::class ];
37
40
}
38
41
39
42
public function testShouldMapBetweenResourceAndEntity (): void
@@ -68,6 +71,29 @@ public function testShouldMapBetweenResourceAndEntity(): void
68
71
$ this ->assertJsonContains (['username ' => 'ba zar ' ]);
69
72
}
70
73
74
+ public function testShouldMapToTheCorrectResource (): void
75
+ {
76
+ if ($ this ->isMongoDB ()) {
77
+ $ this ->markTestSkipped ('MongoDB not tested. ' );
78
+ }
79
+
80
+ if (!$ this ->getContainer ()->has ('object_mapper ' )) {
81
+ $ this ->markTestSkipped ('ObjectMapper not installed ' );
82
+ }
83
+
84
+ $ this ->recreateSchema ([SameEntity::class]);
85
+ $ manager = $ this ->getManager ();
86
+ $ e = new SameEntity ();
87
+ $ e ->setName ('foo ' );
88
+ $ manager ->persist ($ e );
89
+ $ manager ->flush ();
90
+
91
+ self ::createClient ()->request ('GET ' , '/seconds ' );
92
+ $ this ->assertJsonContains (['hydra:member ' => [
93
+ ['name ' => 'foo ' , 'extra ' => 'field ' ],
94
+ ]]);
95
+ }
96
+
71
97
private function loadFixtures (): void
72
98
{
73
99
$ manager = $ this ->getManager ();
0 commit comments