/** * @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::addProperty */ public function testAddProperty() { // Setup $entity = new Entity(); $name = 'test'; $expected = new Property(); $edmType = EdmType::STRING; $value = '01231232290234210'; $expected->setEdmType($edmType); $expected->setValue($value); // Test $entity->addProperty($name, $edmType, $value); // Assert $this->assertEquals($expected, $entity->getProperty($name)); }