/**
  * @return FixtureGeneratorRule
  */
 private function createTestRule()
 {
     $rule = new FixtureGeneratorRule();
     $rule->setKey('user')->setCountRepeat(5);
     foreach ([['key' => 'referenceName', 'prefix' => 'user', 'strategy' => FixtureGeneratorStrategy::PREFIX_WITH_NUMBER], ['key' => 'name', 'prefix' => 'User', 'strategy' => FixtureGeneratorStrategy::PREFIX_WITH_NUMBER], ['key' => 'token', 'prefix' => 'user-token', 'strategy' => FixtureGeneratorStrategy::PREFIX_WITH_NUMBER], ['key' => 'password', 'prefix' => 'User', 'strategy' => FixtureGeneratorStrategy::PREFIX_WITH_NUMBER]] as $item) {
         $subRule = new FixtureGeneratorRule();
         $subRule->setKey($item['key'])->setPrefix($item['prefix'])->setStrategy($item['strategy']);
         $rule->addRule($subRule);
     }
     return $rule;
 }
Esempio n. 2
0
 /**
  * @param array  $config
  * @param string $configPath
  *
  * @return FixtureGeneratorRule
  *
  * @throws \Exception
  */
 private function createRuleFromConfig(array $config, string $configPath) : FixtureGeneratorRule
 {
     if (empty($config)) {
         throw new \Exception('Config array is empty');
     }
     $rule = new FixtureGeneratorRule();
     if (!empty($key)) {
         $rule->setKey($key);
     }
     if (isset($config['prefix'])) {
         $rule->setPrefix($config['prefix']);
     }
     if (isset($config['strategy'])) {
         $rule->setStrategy($config['strategy']);
     }
     if (isset($config['count_repeat'])) {
         $rule->setCountRepeat($config['count_repeat']);
     }
     if (isset($config['referenceArray'])) {
         $rule->setReferenceArray(json_decode(file_get_contents($configPath . '/' . $config['referenceArray'] . '.json'), true));
     }
     if (isset($config['rules'])) {
         foreach ($config['rules'] as $key => $item) {
             $rule->addRule($this->createRuleFromConfig($item, $configPath));
         }
     }
     /* @var FixtureGeneratorRule $rule */
     return $rule;
 }