@@ -185,13 +185,38 @@ public function it_hydrates_items_with_morphto_relationship()
185185 $ this ->assertEquals ($ data ['testattribute1 ' ], $ item ->getAttribute ('testattribute1 ' ));
186186 $ this ->assertEquals ($ data ['testattribute2 ' ], $ item ->getAttribute ('testattribute2 ' ));
187187 $ this ->assertEquals ('related-item ' , $ morphTo ->getType ());
188+ $ this ->assertEquals ('related-item ' , $ morphTo ->getIncluded ()->getType ());
188189 $ this ->assertEquals (
189190 $ data ['morphto_relation ' ]['test_related_attribute1 ' ],
190191 $ morphTo ->getIncluded ()->getAttribute ('test_related_attribute1 ' )
191192 );
192193 $ this ->assertArrayHasKey ('morphto_relation ' , $ item ->toJsonApiArray ()['relationships ' ]);
193194 }
194195
196+ /**
197+ * @test
198+ */
199+ public function it_hydrates_unmapped_items_with_morphto_relationship ()
200+ {
201+ $ data = [
202+ 'morphto_relation ' => [
203+ 'id ' => 1 ,
204+ 'type ' => 'unmapped-item ' ,
205+ 'test_related_attribute1 ' => 'test ' ,
206+ ],
207+ ];
208+
209+ $ item = new WithRelationshipItem ();
210+ $ item = $ this ->getItemHydrator ()->hydrate ($ item , $ data );
211+
212+ /** @var \Swis\JsonApi\Client\Relations\MorphToRelation $morphTo */
213+ $ morphTo = $ item ->getRelationship ('morphto_relation ' );
214+
215+ $ this ->assertEquals ('unmapped-item ' , $ morphTo ->getType ());
216+ $ this ->assertEquals ('unmapped-item ' , $ morphTo ->getIncluded ()->getType ());
217+ $ this ->assertArrayNotHasKey ('type ' , $ morphTo ->getIncluded ()->getAttributes ());
218+ }
219+
195220 /**
196221 * @test
197222 */
@@ -265,6 +290,38 @@ public function it_hydrates_items_with_morphtomany_relationship()
265290 $ this ->assertArrayHasKey ('morphtomany_relation ' , $ item ->toJsonApiArray ()['relationships ' ]);
266291 }
267292
293+ /**
294+ * @test
295+ */
296+ public function it_hydrates_unmapped_items_with_morphtomany_relationship ()
297+ {
298+ $ data = [
299+ 'morphtomany_relation ' => [
300+ [
301+ 'id ' => 1 ,
302+ 'type ' => 'unmapped-item ' ,
303+ 'test_related_attribute1 ' => 'test1 ' ,
304+ ],
305+ [
306+ 'id ' => 2 ,
307+ 'type ' => 'unmapped-item ' ,
308+ 'test_related_attribute1 ' => 'test2 ' ,
309+ ],
310+ ],
311+ ];
312+
313+ $ item = new WithRelationshipItem ();
314+ $ item = $ this ->getItemHydrator ()->hydrate ($ item , $ data );
315+
316+ /** @var \Swis\JsonApi\Client\Relations\MorphToManyRelation $morphToMany */
317+ $ morphToMany = $ item ->getRelationship ('morphtomany_relation ' );
318+
319+ $ this ->assertEquals ('unmapped-item ' , $ morphToMany ->getIncluded ()[0 ]->getType ());
320+ $ this ->assertEquals ('unmapped-item ' , $ morphToMany ->getIncluded ()[1 ]->getType ());
321+ $ this ->assertArrayNotHasKey ('type ' , $ morphToMany ->getIncluded ()[0 ]->getAttributes ());
322+ $ this ->assertArrayNotHasKey ('type ' , $ morphToMany ->getIncluded ()[1 ]->getAttributes ());
323+ }
324+
268325 /**
269326 * @test
270327 */
0 commit comments