|
15 | 15 | use SergiX44\Hydrator\Tests\Fixtures\DI\Tree; |
16 | 16 | use SergiX44\Hydrator\Tests\Fixtures\DI\Wood; |
17 | 17 | use SergiX44\Hydrator\Tests\Fixtures\ObjectWithAbstract; |
| 18 | +use SergiX44\Hydrator\Tests\Fixtures\ObjectWithArrayOfAbstracts; |
18 | 19 | use SergiX44\Hydrator\Tests\Fixtures\ObjectWithInvalidAbstract; |
19 | 20 | use SergiX44\Hydrator\Tests\Fixtures\Resolver\AppleResolver; |
20 | 21 | use SergiX44\Hydrator\Tests\Fixtures\Store\Apple; |
@@ -751,6 +752,46 @@ public function testHydrateAbstractProperty(): void |
751 | 752 | $this->assertSame('brandy', $o->value->category); |
752 | 753 | } |
753 | 754 |
|
| 755 | + public function testHydrateArrayAbstractProperty(): void |
| 756 | + { |
| 757 | + $o = (new Hydrator())->hydrate(new ObjectWithArrayOfAbstracts(), [ |
| 758 | + 'value' => [[ |
| 759 | + 'type' => 'jack', |
| 760 | + 'sweetness' => null, |
| 761 | + 'category' => 'brandy', |
| 762 | + ]], |
| 763 | + ]); |
| 764 | + |
| 765 | + $this->assertInstanceOf(ObjectWithArrayOfAbstracts::class, $o); |
| 766 | + $this->assertIsArray($o->value); |
| 767 | + |
| 768 | + $value = $o->value[0]; |
| 769 | + |
| 770 | + $this->assertInstanceOf(AppleJack::class, $value); |
| 771 | + $this->assertSame('jack', $value->type); |
| 772 | + $this->assertSame('brandy', $value->category); |
| 773 | + } |
| 774 | + |
| 775 | + public function testHydrateArrayAbstractPropertyWithObject(): void |
| 776 | + { |
| 777 | + $o = (new Hydrator())->hydrate(new ObjectWithArrayOfAbstracts(), [ |
| 778 | + 'value' => [(object) [ |
| 779 | + 'type' => 'jack', |
| 780 | + 'sweetness' => null, |
| 781 | + 'category' => 'brandy', |
| 782 | + ]], |
| 783 | + ]); |
| 784 | + |
| 785 | + $this->assertInstanceOf(ObjectWithArrayOfAbstracts::class, $o); |
| 786 | + $this->assertIsArray($o->value); |
| 787 | + |
| 788 | + $value = $o->value[0]; |
| 789 | + |
| 790 | + $this->assertInstanceOf(AppleJack::class, $value); |
| 791 | + $this->assertSame('jack', $value->type); |
| 792 | + $this->assertSame('brandy', $value->category); |
| 793 | + } |
| 794 | + |
754 | 795 | public function testHydrateInvalidAbstractObject(): void |
755 | 796 | { |
756 | 797 | $this->expectException(InvalidObjectException::class); |
|
0 commit comments