Ejemplo n.º 1
0
 public function testSerializeWithNullValue()
 {
     $city = new City();
     $city->setName('Palaiseau');
     $city->countryIs(null);
     $configuration = new Configuration();
     $configurationObject = new Configuration\Object(new ClassName(City::class));
     $configurationObject->attributeUseMethod('name', 'setName', 'getName')->attributeUseObject('country', new ClassName(Country::class), 'countryIs', 'getCountry')->registerToConfiguration($configuration);
     $configurationObject = new Configuration\Object(new ClassName(Country::class));
     $configurationObject->attributeUseMethod('name', 'setName', 'getName')->registerToConfiguration($configuration);
     $this->given($this->newTestedInstance($configuration))->string($this->testedInstance->serialize($city))->isIdenticalTo('{"name":"Palaiseau"}');
 }
Ejemplo n.º 2
0
 /**
  * @param City $object
  * @return mixed
  */
 public function serialize($object)
 {
     $country = $object->getCountry();
     return ['name' => $country->getName()];
 }
Ejemplo n.º 3
0
 public function testDeserializeWithTypeHandler()
 {
     $city = new City();
     $city->setName('Palaiseau');
     $country = new Country();
     $country->setName('France');
     $city->countryIs($country);
     $configuration = new Configuration();
     $configurationObject = new Configuration\Object(new ClassName(City::class));
     $configurationObject->attributeUseMethod('name', 'setName', 'getName')->attributeUseHandler('country', new class implements Configuration\Type\HandlerDeserializerInterface
     {
         public function deserialize($object, $value)
         {
             $country = new Country();
             $country->setName(str_replace(' (Handler please remove me)', '', $value['name']));
             $object->countryIs($country);
             $object->setName(str_replace(' (Handler please remove me if i have a country)', '', $object->getName()));
         }
     }, new class implements Configuration\Type\HandlerSerializerInterface
     {
         public function serialize($object)
         {
             $country = $object->getCountry();
             return ['name' => $country->getName() . ' (with Handler)'];
         }
     })->registerToConfiguration($configuration);
     $configurationObject = new Configuration\Object(new ClassName(Country::class));
     $configurationObject->attributeUseMethod('name', 'setName', 'getName')->registerToConfiguration($configuration);
     $this->given($this->newTestedInstance($configuration))->object($this->testedInstance->deserialize('{"name":"Palaiseau (Handler please remove me if i have a country)","country":{"name":"France (Handler please remove me)"}}', new ClassName(City::class)))->isCloneOf($city);
 }