public function testShouldAddProviderForGivenKey() { $faker = FakerFactory::create(); $proxy = new ProviderProxy('Faker\\Provider\\en_US\\Person', 'firstName', []); ProviderProxyMap::add('firstName', $proxy); $this->assertNotNull(ProviderProxyMap::get('firstName')); $this->assertInstanceOf('\\Vegas\\Tool\\Faker\\ProviderProxy', ProviderProxyMap::get('firstName')); $this->assertInstanceOf('Faker\\Provider\\en_US\\Person', ProviderProxyMap::get('firstName')->instantiateProvider($faker)); $this->assertInternalType('string', ProviderProxyMap::get('firstName')->invoke($faker)); }
/** * Generates fake data * * @throws Exception\MissingDestinationException * @throws Exception\MissingAdapterTypeException * @throws Exception\MissingAdapterException */ public function generate() { //fetches specification $spec = $this->fetchDataSpec($this->specFilePath); if (!$this->adapterName) { throw new MissingAdapterException(); } if (!$this->adapterType) { throw new MissingAdapterTypeException(); } if (!$this->destination) { throw new MissingDestinationException(); } //prepares output adapter $outputAdapter = $this->obtainOutputAdapter($this->adapterName, $this->adapterType); $outputAdapter->setDestination($this->destination); $outputAdapter->init(); //prepares fake data generator $faker = FakerFactory::createFromSpec($spec); foreach ($this->customProviders as $provider) { $reflectionClass = new \ReflectionClass($provider); $faker->addProvider($reflectionClass->newInstance($faker)); } //generates data` for ($i = 0; $i < $this->count; $i++) { $data = []; foreach ($spec as $key => $providerConfig) { $providerProxy = ProviderProxyMap::get($key); $data[$key] = $providerProxy->invoke($faker); } $outputAdapter->store($data); } //release, clean up... $outputAdapter->finalize(); }