public function testInvalidHandler()
 {
     $handlers = new FallbackHydratorContainer();
     $this->setExpectedException('RuntimeException');
     $handlers->add('stdClass', 'name', 'invalid');
 }
Exemplo n.º 2
0
 public function addHydrator($class, $root, $handler)
 {
     $this->hydrators->add($class, $root, $handler);
 }
Exemplo n.º 3
0
 private function getSerializard()
 {
     $userClass = 'Thunder\\Serializard\\Tests\\Fake\\FakeUser';
     $tagClass = 'Thunder\\Serializard\\Tests\\Fake\\FakeTag';
     $normalizers = new FallbackNormalizerContainer();
     $normalizers->add($userClass, 'user', new ReflectionNormalizer());
     $normalizers->add($tagClass, 'tag', function (FakeTag $tag) {
         return array('id' => $tag->getId(), 'name' => $tag->getName());
     });
     $hydrators = new FallbackHydratorContainer();
     $hydrators->add($userClass, 'user', function (array $data, Hydrators $handlers) use($tagClass) {
         $tagHandler = $handlers->getHandler($tagClass);
         $user = new FakeUser($data['id'], $data['name'], $tagHandler($data['tag'], $handlers));
         foreach ($data['tags'] as $tag) {
             $user->addTag($tagHandler($tag, $handlers));
         }
         return $user;
     });
     $hydrators->add($tagClass, 'tag', function (array $data, Hydrators $handlers) {
         return new FakeTag($data['id'], $data['name']);
     });
     $formats = new FormatContainer();
     $formats->add('xml', new XmlFormat());
     $formats->add('yaml', new YamlFormat());
     $formats->add('json', new JsonFormat());
     $formats->add('array', new ArrayFormat());
     return new Serializard($formats, $normalizers, $hydrators);
 }