Esempio n. 1
0
 public function testGetDefinitionByInstance()
 {
     $options = array('foo' => 'bar');
     $type = $this->getTypeMock();
     $type->expects($this->once())->method('setDefaultOptions')->will($this->returnCallback(function (OptionsResolver $resolver) {
         $resolver->setDefaults(array('foo' => 'baz'));
     }));
     $type->expects($this->once())->method('build')->with($this->isInstanceOf('Bcn\\Component\\Serializer\\Definition\\Builder'), $options)->will($this->returnCallback(function (Builder $builder) {
         $builder->node('test');
     }));
     $resolver = new Resolver();
     $definition = $resolver->getDefinition($type, $options);
     $this->assertTrue($definition->hasProperty('test'));
 }
Esempio n. 2
0
 /**
  * @param  ExtensionInterface $extension
  * @throws \Exception
  */
 public function extend(ExtensionInterface $extension)
 {
     foreach ($extension->getTypes() as $type) {
         $this->resolver->addType($type);
     }
     foreach ($extension->getEncoders() as $encoder) {
         $this->encoder->addFormat($encoder);
     }
 }
Esempio n. 3
0
 /**
  * @param $type
  * @param  array      $options
  * @return Definition
  */
 protected function resolve($type, array $options)
 {
     if ($type instanceof Definition) {
         $definition = $type;
     } elseif ($type === null) {
         $definition = new Definition();
     } else {
         $definition = $this->resolver->getDefinition($type, $options);
     }
     return $definition;
 }