Exemple #1
0
 public function testShouldThrowExceptionForInvalidProvider()
 {
     $faker = FakerFactory::create();
     $proxy = new ProviderProxy('Faker\\Provider\\en_US\\Fake', 'fake', []);
     try {
         $proxy->instantiateProvider($faker);
         throw new \Exception();
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Vegas\\Tool\\Faker\\Exception\\UnableProviderInstantiateException', $e);
     }
 }
Exemple #2
0
 /**
  * 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();
 }