Пример #1
0
 /**
  * @test
  */
 public function shouldReturnNullValue()
 {
     $datetime = Type::getType('datetime');
     $this->assertNull($datetime->convertToDatabaseValue(''));
     $this->assertNull($datetime->convertToDatabaseValue(null));
     $this->assertNull($datetime->convertToPHPValue(''));
     $this->assertNull($datetime->convertToPHPValue(null));
 }
Пример #2
0
 /**
  * @param EmbeddedMetadataInterface $embeddedMetadata
  * @param array                     $data
  *
  * @return object
  */
 private function getEmbeddedObject(EmbeddedMetadataInterface $embeddedMetadata, array $data)
 {
     $embedded = $this->instantiator->instantiate($embeddedMetadata->getClassAttribute());
     foreach ($embeddedMetadata->getEmbeddableClasses() as $embeddableMetadata) {
         if ($embeddableMetadata instanceof IndexMetadataInterface) {
             $name = $embeddableMetadata->getNameAttribute();
             $type = $embeddableMetadata->getTypeAttribute();
             $value = Type::getType($type)->convertToPHPValue($this->get($data, $name));
             $embeddableMetadata->setValue($embedded, $value);
         }
         if ($embeddableMetadata instanceof EmbeddedMetadataInterface) {
             $object = $this->getEmbeddedObject($embeddableMetadata, $this->get($data, $embeddableMetadata->getPropertyName(), []));
             $embeddableMetadata->setValue($embedded, $object);
         }
     }
     return $embedded;
 }
Пример #3
0
 /**
  * @param array  $embeddableList
  * @param object $object
  *
  * @return array
  */
 private function getEmbeddableValue(array $embeddableList, $object)
 {
     if (!is_object($object)) {
         throw new \UnexpectedValueException();
     }
     $embeddableValue = [];
     foreach ($embeddableList as $embeddableMetadata) {
         if (!$embeddableMetadata->getValue($object)) {
             continue;
         }
         if ($embeddableMetadata instanceof IndexMetadataInterface) {
             $indexName = $embeddableMetadata->getNameAttribute();
             $indexType = $embeddableMetadata->getTypeAttribute();
             $indexValue = $embeddableMetadata->getValue($object);
             $embeddableValue[$indexName] = Type::getType($indexType)->convertToDatabaseValue($indexValue);
         }
         if ($embeddableMetadata instanceof EmbeddedMetadataInterface) {
             $embeddableValue[$embeddableMetadata->getPropertyName()] = $this->getEmbeddableValue($embeddableMetadata->getEmbeddableClasses(), $embeddableMetadata->getValue($object));
         }
     }
     return $embeddableValue;
 }
Пример #4
0
 /**
  * @test
  * @expectedException \InvalidArgumentException
  */
 public function shouldReturnInvalidArgumentException()
 {
     Type::getType('tests');
 }