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; }
public function testCreateDataFor() { $data = DataGenerator::createDataFor($this->type, array(DataGenerator::OPTION_FIELD_VALUES => array('missing' => 'trololo'))); $this->assertTrue(is_array($data), 'Returned data should be an array.'); $this->assertTrue(!empty($data), 'Returned data array should not be empty.'); $this->assertArrayHasKey('author', $data); $this->assertInternalType('string', $data['author']); $this->assertNotEmpty($data['author']); $this->assertArrayHasKey('email', $data); $this->assertNotFalse(filter_var($data['email'], FILTER_VALIDATE_EMAIL)); $this->assertArrayHasKey('website', $data); $this->assertNotFalse(filter_var($data['website'], FILTER_VALIDATE_URL)); $this->assertArrayHasKey('headline', $data); $this->assertInternalType('string', $data['headline']); $this->assertNotEmpty($data['headline']); $this->assertArrayHasKey('click_count', $data); $this->assertInternalType('integer', $data['click_count']); $this->assertArrayHasKey('float', $data); $this->assertInternalType('float', $data['float']); $this->assertArrayHasKey('content', $data); $this->assertInternalType('string', $data['content']); $this->assertNotEmpty($data['content']); $this->assertNotEmpty($data['meta']); $this->assertArrayNotHasKey('missing', $data, 'Returned data should not have missing key.'); $this->markTestIncomplete('Need more tests for nested arrays of data'); }