create() public static method

Bootstrap function for Fakerino, setups the global configuration.
public static create ( null | array | string $conf = null ) : FakeDataFactory
$conf null | array | string
return Fakerino\Core\FakeDataFactory
Beispiel #1
0
 /**
  * Runs the command.
  *
  * @return mixed
  */
 public function run()
 {
     if ($this->help) {
         return $this->showHelp();
     }
     if ($this->confFile) {
         $fakerino = Fakerino::create($this->confFile);
     } else {
         $fakerino = Fakerino::create();
         if ($this->locale) {
             $conf = array();
             $conf['locale'] = $this->locale;
             $fakerino = Fakerino::create($conf);
         }
     }
     if (!$this->num) {
         $this->num = 1;
     }
     if ($this->table) {
         $fakerino->num($this->num)->fakeTable($this->table);
         return;
     }
     if ($this->templateSource) {
         return $fakerino->num($this->num)->fakeTemplate($this->templateSource) . PHP_EOL;
     }
     $fakerino = $fakerino->fake($this->input)->num($this->num);
     if ($this->json) {
         $result = $fakerino->toJson();
     } else {
         $result = (string) $fakerino;
     }
     return $result . PHP_EOL;
 }
Beispiel #2
0
 /**
  * @group important
  */
 public function testMultipleNestedFakes()
 {
     $fakerino = Fakerino::create(array('fake' => array('fakeSurname' => array('surname'))));
     $fakerino->fake('fakeSurname')->toArray();
     $fakerino = Fakerino::create($this->fileDir . '/file.yml');
     $result = $fakerino->fake('fakeFamily')->toArray();
     $this->assertEquals(3, count($result[0][0]));
     $this->assertEquals(3, count($result[0][1]));
 }
 static function create(Container $container)
 {
     $fakerinoConf = array();
     $configuration = $container->getParameters();
     if (array_key_exists(self::FAKERINO_TAG, $configuration)) {
         $fakerinoConf = $configuration[self::FAKERINO_TAG];
     }
     return Fakerino::create($fakerinoConf);
 }
Beispiel #4
0
 /**
  * @dataProvider provider
  */
 public function testFakeWithSeed($conf, $element)
 {
     $fakerino = Fakerino::create($conf);
     mt_srand(2);
     $result1 = $fakerino->fake($element)->__toString();
     mt_srand(2);
     $result2 = $fakerino->fake($element)->__toString();
     $this->assertEquals($result1, $result2, sprintf("The first result '%s' and the second '%s'", $result1, $result2));
 }
Beispiel #5
0
 private function generateCustomer($count = 20)
 {
     $conf['locale'] = "cs-CZ";
     //@todo change me
     $fakerino = Fakerino::create($conf);
     $country = new \App\Model\Customer\Country();
     $country->code = "cz";
     $country->name = "Czech republic";
     $country->status_id = self::DEFAULT_STATUS_ID;
     $country->save();
     for ($i = 0; $i < $count; $i++) {
         $customer = new Customer();
         $fakerino = Fakerino::create($conf);
         $data = $fakerino->fake(['namemale', 'surnamemale', 'city', 'postcode', 'street'])->toArray();
         $customer->credentials_id = 22;
         $customer->last_name = $data[1];
         $customer->first_name = $data[0];
         $customer->status_id = self::DEFAULT_STATUS_ID;
         $customer->save();
         $deliveryAddress = new CustomerAddress();
         $deliveryAddress->customer = $customer->id;
         $deliveryAddress->first_name = $data[0];
         $deliveryAddress->last_name = $data[1];
         $deliveryAddress->city = $data[2];
         $deliveryAddress->street = $data[4];
         $deliveryAddress->zip = $data[3];
         $deliveryAddress->type = 'delivery';
         $deliveryAddress->country = $country->id;
         $deliveryAddress->status_id = self::DEFAULT_STATUS_ID;
         $deliveryAddress->save();
         $localAddress = new CustomerAddress();
         $localAddress->customer = $customer->id;
         $localAddress->first_name = $data[0];
         $localAddress->last_name = $data[1];
         $localAddress->city = $data[2];
         $localAddress->street = $data[4];
         $localAddress->zip = $data[3];
         $localAddress->type = 'invoice';
         $localAddress->country = $country->id;
         $localAddress->status_id = self::DEFAULT_STATUS_ID;
         $localAddress->save();
     }
 }
 /**
  * Register bindings in the container.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('Fakerino\\Fakerino', function ($app) {
         return Fakerino::create($app['config']['fakerino']);
     });
 }