1414namespace ApiPlatform \Tests \Functional ;
1515
1616use ApiPlatform \Symfony \Bundle \Test \ApiTestCase ;
17+ use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \FirstResource ;
1718use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResource ;
1819use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \MappedResourceOdm ;
20+ use ApiPlatform \Tests \Fixtures \TestBundle \ApiResource \SecondResource ;
1921use ApiPlatform \Tests \Fixtures \TestBundle \Document \MappedDocument ;
2022use ApiPlatform \Tests \Fixtures \TestBundle \Entity \MappedEntity ;
23+ use ApiPlatform \Tests \Fixtures \TestBundle \Entity \SameEntity ;
2124use ApiPlatform \Tests \RecreateSchemaTrait ;
2225use ApiPlatform \Tests \SetupClassResourcesTrait ;
2326use Doctrine \ODM \MongoDB \DocumentManager ;
@@ -33,7 +36,7 @@ final class MappingTest extends ApiTestCase
3336 */
3437 public static function getResources (): array
3538 {
36- return [MappedResource::class, MappedResourceOdm::class];
39+ return [MappedResource::class, MappedResourceOdm::class, FirstResource::class, SecondResource::class ];
3740 }
3841
3942 public function testShouldMapBetweenResourceAndEntity (): void
@@ -68,6 +71,29 @@ public function testShouldMapBetweenResourceAndEntity(): void
6871 $ this ->assertJsonContains (['username ' => 'ba zar ' ]);
6972 }
7073
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+
7197 private function loadFixtures (): void
7298 {
7399 $ manager = $ this ->getManager ();
0 commit comments