Example #1
0
 public function generate($type_prefix, $size = 1, $locale = 'de_DE')
 {
     $aggregate_root_type = $this->aggregate_root_type_map->getItem($type_prefix);
     if (!$aggregate_root_type instanceof AggregateRootType) {
         throw new RuntimeError(sprintf('No aggregate root found with prefix %s', $type_prefix));
     }
     $documents = [];
     $options = [DataGenerator::OPTION_LOCALE => $locale, DataGenerator::OPTION_EXCLUDED_FIELDS => self::$excluded_attributes, DataGenerator::OPTION_FIELD_VALUES => ['language' => $locale, 'referenced_identifier' => '**REFERENCE ID REQUIRED**']];
     for ($cnt = 0; $cnt < $size; $cnt++) {
         $document = DataGenerator::createDataFor($aggregate_root_type, $options);
         $this->excludeAttributes($document);
         // Add identifier for convenient related entity referencing purposes
         $identifier = sprintf('%s-%s-%s-%s', $aggregate_root_type->getPrefix(), $document['uuid'], $document['language'], $document['version']);
         $documents[] = ['identifier' => $identifier] + $document;
     }
     return $documents;
 }
Example #2
0
 /**
  * Creates `count` number of entities with fake data for the given type.
  *
  * @param EntityTypeInterface $type type to create entities for
  * @param array $options use `count` for number of entities to create. For other options see fill() method.
  *
  * @return array of new entities with fake data
  *
  * @throws \Trellis\Runtime\Entity\InvalidValueException in case of fake data being invalid for the given attribute
  * @throws \Trellis\Runtime\Entity\BadValueException in case of invalid locale option string
  * @throws \Trellis\Common\Error\RuntimeException on EmbeddedEntityListAttribute misconfiguration
  */
 public static function createEntities(EntityTypeInterface $type, array $options = array())
 {
     $data_generator = new DataGenerator();
     return $data_generator->createFakeEntities($type, $options);
 }
Example #3
0
 public function testCreateEntities()
 {
     $num_entities = 30;
     $entities = DataGenerator::createEntities($this->type, array(DataGenerator::OPTION_COUNT => $num_entities, DataGenerator::OPTION_LOCALE => 'fr_FR'));
     $this->assertTrue($num_entities === count($entities));
     for ($i = 0; $i < $num_entities; $i++) {
         $entity = $entities[$i];
         $this->assertTrue($entity->isClean(), "New entity {$i} should have no changes.");
         $this->assertTrue(0 === count($entity->getChanges()), "New entity {$i} should have no changes.");
     }
 }