Ejemplo n.º 1
0
 /**
  * @param array       $record
  * @param null|Entity $entity
  * @param array       $exclude List of keys to exclude from adding to Entity
  *
  * @return Entity
  */
 protected static function parseRecordToEntity($record = [], $entity = null, $exclude = [])
 {
     if (empty($entity)) {
         $entity = new Entity();
     }
     foreach ($record as $key => $value) {
         if (false === array_search($key, $exclude)) {
             // valid types
             //				const DATETIME = 'Edm.DateTime';
             //				const BINARY   = 'Edm.Binary';
             //				const GUID     = 'Edm.Guid';
             $edmType = EdmType::STRING;
             switch (gettype($value)) {
                 case 'boolean':
                     $edmType = EdmType::BOOLEAN;
                     break;
                 case 'double':
                 case 'float':
                     $edmType = EdmType::DOUBLE;
                     break;
                 case 'integer':
                     $edmType = $value > 2147483647 ? EdmType::INT64 : EdmType::INT32;
                     break;
             }
             if ($entity->getProperty($key)) {
                 $prop = new Property();
                 $prop->setEdmType($edmType);
                 $prop->setValue($value);
                 $entity->setProperty($key, $prop);
             } else {
                 $entity->addProperty($key, $edmType, $value);
             }
         }
     }
     return $entity;
 }
 /**
  * @covers WindowsAzure\Table\Models\Entity::getProperty
  * @covers WindowsAzure\Table\Models\Entity::setProperty
  */
 public function testSetProperty()
 {
     // Setup
     $entity = new Entity();
     $expected = new Property();
     $name = 'test';
     // Test
     $entity->setProperty($name, $expected);
     // Assert
     $this->assertEquals($expected, $entity->getProperty($name));
 }