/** * @param string $locale e.g. 'fr_FR', 'en_US' * * @return FakerGenerator */ public function createOrReturnExistingInstance(string $locale) : FakerGenerator { if (array_key_exists($locale, $this->generators)) { return $this->generators[$locale]; } $instance = FakerFactory::create($locale); $generatorProviders = $this->generator->getProviders(); foreach ($generatorProviders as $provider) { if (1 !== preg_match('/^Faker\\\\Provider.*/', get_class($provider))) { $instance->addProvider($provider); } } return $this->generators[$locale] = $instance; }
private function assertGeneratorLocaleIs(string $locale, FakerGenerator $generator) { $providers = $generator->getProviders(); $regex = sprintf('/^Faker\\\\Provider\\\\%s\\\\.*/', $locale); foreach ($providers as $provider) { if (preg_match($regex, get_class($provider))) { return; } } throw new \Exception(sprintf('Generator has not been initialised with the locale "%s".', $locale)); }
private function assertHasAliceProvider(FakerGenerator $generator) { $providers = $generator->getProviders(); foreach ($providers as $provider) { if ($provider instanceof AliceProvider) { return; } } throw new \Exception(sprintf('Generator does not have the provider "%s".', AliceProvider::class)); }
public function testGenerator() { $this->assertSame('Hautelook\\AliceBundle\\Tests\\SymfonyApp\\TestBundle\\DataFixtures\\Faker\\Provider\\FooProvider', get_class($this->faker->getProviders()[0]), 'Expected custom Faker provider to be registered.'); }