Example #1
0
 /**
  * Hydrates the given set of values into the current IDocument instance.
  *
  * @param array $values
  */
 protected function hydrate(array $values = array(), $apply_defaults = false)
 {
     $non_hydrated_fields = array();
     if (!empty($values)) {
         foreach ($this->module->getFields() as $fieldname => $field) {
             if (array_key_exists($fieldname, $values)) {
                 $this->setValue($field->getName(), $values[$fieldname]);
             } else {
                 $non_hydrated_fields[] = $field;
             }
         }
     } else {
         foreach ($this->module->getFields() as $fieldname => $field) {
             $non_hydrated_fields[] = $field;
         }
     }
     if ($apply_defaults) {
         foreach ($non_hydrated_fields as $field) {
             $this->setValue($field->getName(), $field->getDefaultValue());
         }
     }
 }
Example #2
0
 /**
  * @dataProvider provideModuleInstances
  * @expectedException Dat0r\Core\Module\InvalidFieldException
  */
 public function testInvalidFieldException(IModule $module)
 {
     $module->getField('foobar-field-does-not-exist');
     // @codeCoverageIgnoreStart
 }
Example #3
0
 /**
  * Creates a document with fake data for the given module.
  *
  * @param IModule $module module to create documents for
  * @param array $options For valid options see fake() method
  *
  * @return document newly created with fake data
  *
  * @throws \Dat0r\Core\Document\InvalidValueException in case of fake data being invalid for the given field
  * @throws \InvalidArgumentException in case of invalid locale option string
  * @throws \Dat0r\Core\Error\LogicException on AggregateField misconfiguration
  * @throws \Dat0r\Core\Error\InvalidImplementorException on various misconfigurations
  * @throws \Dat0r\Core\Error\ObjectImmutableException if an instance is frozen (closed to modifications)
  */
 public function createFakeDocument(IModule $module, array $options = array())
 {
     $options[self::OPTION_MARK_CLEAN] = true;
     $document = $module->createDocument();
     $this->fake($document, $options);
     return $document;
 }