Beispiel #1
0
 /**
  * {@inheritdoc}
  * @see BaseAdapter::toData()
  */
 public function toData($entity)
 {
     $result = parent::toData($entity);
     $converterRules = $this->getRules();
     if (!empty($converterRules[static::RULE_TYPE_SETTINGS])) {
         $collection = $this->getSettingsCollection($entity);
         foreach ($converterRules[static::RULE_TYPE_SETTINGS] as $key => $property) {
             //Some properties only for writing we can't include them in the response
             if ($property[0] == '!') {
                 continue;
             }
             //This is necessary when result data key does not match the property name of the entity
             $key = is_int($key) ? $property : $key;
             $result->{$property} = $collection[$key];
         }
     }
     return $result;
 }
 /**
  * @test
  * @dataProvider providerToData()
  */
 public function testToData($rules, $entity, $result)
 {
     $adapter = new BaseAdapter();
     $adapter->setEntityClass(self::OS_CLASS_NAME);
     $adapter->setRules($rules);
     $data = $adapter->toData($entity);
     $this->assertEquals($result, (array) $data);
 }