Exemplo n.º 1
0
 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));
 }
Exemplo n.º 2
0
 /**
  * Prepares data providers defined in specification file
  *
  * @param $spec
  * @param string $locale
  * @return \Faker\Generator
  */
 public static function createFromSpec($spec, $locale = self::DEFAULT_LOCALE)
 {
     $faker = self::create($locale);
     foreach ($spec as $key => $providerConfig) {
         $provider = self::extractProvider($providerConfig);
         $faker->addProvider($provider->instantiateProvider($faker));
         ProviderProxyMap::add($key, $provider);
     }
     return $faker;
 }