diff --git a/test/phpunit/DataObjectBuilderTest.php b/test/phpunit/DataObjectBuilderTest.php index f78be70..5a279b5 100644 --- a/test/phpunit/DataObjectBuilderTest.php +++ b/test/phpunit/DataObjectBuilderTest.php @@ -3,9 +3,6 @@ use Gt\DataObject\AssociativeArrayWithinObjectException; use Gt\DataObject\DataObjectBuilder; -use Gt\DataObject\DataObject; -use Gt\DataObject\Json\JsonArrayData; -use Gt\DataObject\Json\JsonPrimitiveData; use Gt\DataObject\ObjectWithinAssociativeArrayException; use PHPUnit\Framework\TestCase; use stdClass; @@ -42,6 +39,28 @@ public function testFromObjectNested() { self::assertEquals("value4", $nestedOutput->getString("key4")); } + public function fromObjectNestedWithCustomClass() { + $obj = new StdClass(); + $obj->key1 = "value1"; + $obj->key2 = "value2"; + $obj->nested = new StdClass(); + $obj->nested->deepNested = new StdClass(); + $obj->nested->key3 = "value3"; + $obj->nested->key4 = "value4"; + + $myClass = new class extends StdClass { + }; + + $sut = new DataObjectBuilder(); + $output = $sut->fromObject($obj, $myClass); + + $nestedOutput = $output->get("nested"); + $deepNestedOutput = $nestedOutput->getObject("deepNested"); + self::assertIsObject($nestedOutput); + self::assertInstanceOf($myClass, $nestedOutput); + self::assertInstanceOf($myClass, $deepNestedOutput); + } + public function testFromObjectNestedArray() { $obj = new StdClass(); $obj->key1 = "value1"; @@ -163,4 +182,4 @@ public function testMixingObjectInAssociativeArrayThrowsError() { self::expectException(ObjectWithinAssociativeArrayException::class); $sut->fromAssociativeArray($array); } -} \ No newline at end of file +}