Пример #1
0
 public function initialize(Config $config, $directory, $filenameWithDate = false)
 {
     $this->setFilename($config, $directory, $filenameWithDate);
     $this->csvWriter = new CsvWriter($config->getCsvDialect() ?: Dialect::createExcelDialect());
     $this->csvWriter->open($this->filename);
     $this->hasHeader = false;
 }
Пример #2
0
 /**
  * 
  * @param FakerConfig $fakerConfig
  */
 public function __construct(FakerConfig $fakerConfig = null)
 {
     parent::__construct([]);
     $this->setLocale(FakerConfig::DEFAULT_LOCALE);
     $this->generateSeed();
     $this->setMaxTimestamp('now');
     $this->csvDialect = Dialect::createExcelDialect();
     if ($fakerConfig) {
         $this->setFakerConfig($fakerConfig);
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->getApplication()->getSilex();
     $outputDir = realpath(is_dir($input->getArgument('output-dir')) ? $input->getArgument('output-dir') : '.');
     $format = $input->getOption('format');
     if (!in_array($format, array('json', 'xml'))) {
         throw new \InvalidArgumentException('The format ' . $format . ' is not allowed.');
     }
     $config = new Config();
     $config->setClassName('Entity\\User')->setFakeNumber(100)->setFormats(array_keys(DumpManager::getAvailableFormats()))->setLocale('en_US')->setSeed(17846134)->setCsvDialect(Dialect::createExcelDialect())->setVariables([new Variable('firstname', 'firstName'), new Variable('lastname', 'lastName'), new Variable('emailDomain', 'freeEmailDomain'), new Variable('birthday', 'dateTimeBetween', ['Y-m-d', '1970-01-01', '2014-01-01']), new Variable('phonehome', 'phoneNumber'), new Variable('phonework', 'phoneNumber'), new Variable('phonemobile', 'phoneNumber'), new Variable('street1', 'streetAddress'), new Variable('city1', 'city'), new Variable('postalcode1', 'postcode'), new Variable('country1', 'country'), new Variable('street2', 'streetAddress'), new Variable('city2', 'city'), new Variable('postalcode2', 'postcode'), new Variable('country2', 'country')])->setColumns([new Column('firstname', '%firstname%', 'capitalize'), new Column('lastname', '%lastname%', 'capitalize'), new Column('email', '%firstname%.%lastname%@%emailDomain%', 'lowercase'), new Column('birthday', '%birthday%'), new Column('address', null, null, [new Column('home', null, null, [new Column('street', '%street1%', 'capitalize'), new Column('city', '%city1%', 'capitalize'), new Column('postalcode', '%postalcode1%'), new Column('country', '%country1%', 'capitalize')]), new Column('work', null, null, [new Column('street', '%street2%', 'capitalize'), new Column('city', '%city2%', 'capitalize'), new Column('postalcode', '%postalcode2%'), new Column('country', '%country2%', 'capitalize')])]), new Column('phone', null, null, [new Column('home', '%phonehome%'), new Column('mobile', '%phonemobile%')])]);
     $serializer = $app['fakery.config_serializer'];
     $configFile = $serializer->dump($config, $outputDir, $format);
     $output->writeln('Example Config file dumped to <info>' . $configFile) . '</info>';
 }
Пример #4
0
 public function providerDump()
 {
     $config1 = new Config();
     $config1->setClassName('Entity\\User')->setFakeNumber(3)->setFormats(['ruby'])->setLocale('en_US')->setSeed(17846134)->setCsvDialect(Dialect::createUnixDialect())->setVariables([new Variable('firstname', 'firstName'), new Variable('lastname', 'lastName'), new Variable('emailDomain', 'freeEmailDomain'), new Variable('birthday', 'dateTimeThisCentury', ['Y-m-d'])])->setColumns([new Column('person', null, null, [new Column('name', null, null, [new Column('firstname', '%firstname%', 'capitalize'), new Column('lastname', '%lastname%', 'capitalize')]), new Column('email', '%firstname%.%lastname%@%emailDomain%', 'lowercase')]), new Column('birthday', '%birthday%')]);
     return [[$config1, true, [['person' => ['name' => ['firstname' => 'Adolph', 'lastname' => 'McCullough'], 'email' => '*****@*****.**'], 'birthday' => '1994-05-30'], ['person' => ['name' => ['firstname' => 'Sebastian', 'lastname' => 'Harvey'], 'email' => '*****@*****.**'], 'birthday' => '1927-10-02'], ['person' => ['name' => ['firstname' => 'Norris', 'lastname' => 'Douglas'], 'email' => '*****@*****.**'], 'birthday' => '1994-08-12']], 'RubyDumper/expected/Entity_User.rb']];
 }
Пример #5
0
 /**
  *
  * @param  string $str
  * @param  string $from
  * @param  string $to
  * @return string
  */
 protected function convertEncoding($str, $from, $to)
 {
     return $str !== false ? Converter::convertEncoding($str, $from, $to, $this->dialect->getTranslit()) : $str;
 }
Пример #6
0
 /**
  * @dataProvider providerGetSetSkipEmptyLines
  */
 public function testGetSetSkipEmptyLines($input, $expected)
 {
     $this->assertInstanceOf('CSanquer\\ColibriCsv\\Dialect', $this->dialect->setSkipEmptyLines($input));
     $this->assertEquals($expected, $this->dialect->getSkipEmptyLines());
 }