diff --git a/src/Hydrator.php b/src/Hydrator.php index 6b367ff..fd712a6 100644 --- a/src/Hydrator.php +++ b/src/Hydrator.php @@ -9,6 +9,7 @@ namespace PowerLinks\OpenRtb; +use PowerLinks\OpenRtb\BidRequest\Banner; use PowerLinks\OpenRtb\Tools\ObjectAnalyzer\ObjectDescriberFactory; use PowerLinks\OpenRtb\Tools\ObjectAnalyzer\ObjectDescriber; @@ -111,6 +112,10 @@ protected static function getDependencyClassName(ObjectDescriber $objectDescribe if ($key == 'ArrayCollection') { return 'PowerLinks\OpenRtb\Tools\Classes\ArrayCollection'; } + if ($key == 'Companionad') { + return Banner::class; + } + return $objectDescriber->getNamespace().'\\'.$key; } diff --git a/tests/HydratorTest.php b/tests/HydratorTest.php index cf2b19d..445a017 100644 --- a/tests/HydratorTest.php +++ b/tests/HydratorTest.php @@ -10,6 +10,7 @@ namespace PowerLinks\OpenRtb\Tests; use PHPUnit_Framework_TestCase; +use PowerLinks\OpenRtb\BidRequest\Banner; use PowerLinks\OpenRtb\BidRequest\BidRequest; use PowerLinks\OpenRtb\BidRequest\Native; use PowerLinks\OpenRtb\Hydrator; @@ -95,6 +96,40 @@ public function testHydrateRecursive($json) Hydrator::hydrate(json_decode($json, true), new BidRequest()); } + public function testHydrateWithCompanionad() + { + $json = <<< JSON +{ + "id": "foo", + "imp": [ + { + "id": "1", + "video": { + "companionad": [ + { + "w": 0, + "h": 0, + "mimes": [ + "image/gif", + "image/jpeg", + "image/png", + "video/x-flv" + ] + } + ] + } + } + ] +} +JSON; + + $object = new BidRequest(); + + Hydrator::hydrate(json_decode($json, true), $object); + + $this->assertInstanceOf(Banner::class, $object->getImp()->current()->getVideo()->getCompanionad()->current()); + } + public function jsonProvider() { return [