示例#1
0
 /**
  * Generates and adds fake data for an AggregateModuleField on a document.
  *
  * @param IDocument $document an instance of the document to fill with fake data.
  * @param IField $field an instance of the AggregateModuleField to fill with fake data.
  * @param array $options array of options to customize fake data creation.
  *
  * @return void
  */
 protected function addAggregate(IDocument $document, IField $field, array $options = array())
 {
     $options_clone = $options;
     $document_collection = new DocumentCollection();
     $aggregate_modules = $field->getAggregateModules();
     $number_of_aggregate_modules = count($aggregate_modules);
     $number_of_new_aggregate_entries = $this->faker->numberBetween(1, 3);
     // add number of documents to reference depending on number of aggregate modules
     for ($i = 0; $i < $number_of_aggregate_modules; $i++) {
         $number_of_new_aggregate_entries += $this->faker->numberBetween(0, 3);
     }
     // add new documents to collection for aggregate modules
     for ($i = 0; $i < $number_of_new_aggregate_entries; $i++) {
         $aggregate_module = $this->faker->randomElement($aggregate_modules);
         $new_document = $this->createFakeDocument($aggregate_module, $options_clone);
         $document_collection->add($new_document);
     }
     $this->setValue($document, $field, $document_collection, $options);
 }