コード例 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     //$faker->addProvider(new Faker\Provider\DateTime($faker));
     $data = CombatRound::where('challenge_id', '=', 5)->get();
     foreach ($data as $d) {
         $time1 = DateTime::time($format = 'H:i:s', $max = '00:02:00');
         $time2 = DateTime::time($format = 'H:i:s', $max = '00:02:00');
         $zonaRoja1 = $faker->numberBetween($min = 2, $max = 5);
         $nZonaRojo1 = $zonaRoja1 + 1;
         $zonaVerde1 = $faker->numberBetween($min = 1, $max = 5);
         $nZonaVerde1 = $zonaVerde1 + 1;
         $zonaAzul1 = $faker->numberBetween($min = 2, $max = 5);
         $nZonaAzul1 = $zonaAzul1 + 1;
         $zonaRoja2 = $faker->numberBetween($min = 2, $max = 5);
         $nZonaRojo2 = $zonaRoja2 + 1;
         $zonaVerde2 = $faker->numberBetween($min = 1, $max = 5);
         $nZonaVerde2 = $zonaVerde2 + 1;
         $zonaAzul2 = $faker->numberBetween($min = 2, $max = 5);
         $nZonaAzul2 = $zonaAzul2 + 1;
         BlockRise::create(['combat_id' => $d['id'], 'team_id_1' => $d['versus_one'], 'time_team_1' => $time1, 'zon_pun_roj_1' => $zonaRoja1, 'num_api_roj_1' => $nZonaRojo1, 'zon_pun_ver_1' => $zonaVerde1, 'num_api_ver_1' => $nZonaVerde1, 'zon_pun_azu_1' => $zonaAzul1, 'num_api_azu_1' => $nZonaAzul1, 'team_id_2' => $d['versus_two'], 'time_team_2' => $time2, 'zon_pun_roj_2' => $zonaRoja2, 'num_api_roj_2' => $nZonaRojo2, 'zon_pun_ver_2' => $zonaVerde2, 'num_api_ver_2' => $nZonaVerde2, 'zon_pun_azu_2' => $zonaAzul2, 'num_api_azu_2' => $nZonaAzul2]);
     }
 }
コード例 #2
0
 /**
  * Generate the admin form type entity.
  */
 private function generateBehatTest()
 {
     $configDir = $this->bundle->getPath() . '/Resources/config';
     // Get the context names for each section config file
     $sectionInfo = array();
     $dir = $configDir . '/pageparts/';
     foreach ($this->sections as $section) {
         $data = Yaml::parse($dir . $section);
         $sectionInfo[basename($section, '.yml')] = array('context' => $data['context'], 'pagetempates' => array());
     }
     /*
         Example $sectionInfo contents:
         Array
         (
             [main] => Array
                 (
                     [context] => main
                     [pagetempates] => Array
                         (
                         )
                 )
         )
     */
     // Get a list of page templates that use this context
     $allTemplates = glob($configDir . '/pagetemplates/*.yml');
     $contextTemplates = array();
     foreach ($allTemplates as $templatePath) {
         $parts = explode("/", $templatePath);
         $fileName = basename($parts[count($parts) - 1], '.yml');
         $data = Yaml::parse($templatePath);
         $templateName = $data['name'];
         if (array_key_exists('rows', $data) && is_array($data['rows'])) {
             foreach ($data['rows'] as $row) {
                 if (is_array($row) && array_key_exists('regions', $row) && is_array($row['regions'])) {
                     foreach ($row['regions'] as $region) {
                         $contextTemplates[$region['name']][$fileName] = $templateName;
                     }
                 }
             }
         }
     }
     /*
         Example $contextTemplates contents:
         Array
         (
             [main] => Array
                 (
                     [full-width-page] => Full width page
                     [homepage] => Home page
                     [sidebar-page] => Page with left sidebar
                 )
             [top] => Array
                 (
                     [homepage] => Home page
                 )
             [sidebar] => Array
                 (
                     [homepage] => Home page
                     [sidebar-page] => Page with left sidebar
                 )
         )
     */
     // Link the page templates to the sections
     foreach ($sectionInfo as $fileName => $info) {
         $context = $info['context'];
         if (array_key_exists($context, $contextTemplates)) {
             $sectionInfo[$fileName]['pagetempates'] = $contextTemplates[$context];
         }
     }
     /*
         Example $sectionInfo contents:
         Array
         (
             [main] => Array
                 (
                     [context] => main
                     [pagetempates] => Array
                         (
                             [full-width-page] => Full width page
                             [homepage] => Home page
                             [sidebar-page] => Page with left sidebar
                         )
     
                 )
     
         )
     */
     $folder = $this->registry->getRepository('KunstmaanMediaBundle:Folder')->findOneBy(array('rel' => 'image'));
     $images = $this->registry->getRepository('KunstmaanMediaBundle:Media')->findBy(array('folder' => $folder, 'deleted' => false), array(), 2);
     // Get all the available pages
     $allPages = glob($this->bundle->getPath() . '/Entity/Pages/*.php');
     $pages = array();
     foreach ($allPages as $pageFile) {
         $parts = explode("/", $pageFile);
         $className = basename($parts[count($parts) - 1], '.php');
         $contents = file_get_contents($pageFile);
         if (strpos($contents, 'abstract class') === false && strpos($contents, 'interface ') === false) {
             $classNamespace = '\\' . $this->bundle->getNamespace() . '\\Entity\\Pages\\' . $className;
             $entity = new $classNamespace();
             if (!method_exists($entity, 'getPagePartAdminConfigurations') || !method_exists($entity, 'getPageTemplates')) {
                 continue;
             }
             $ppConfigs = $entity->getPagePartAdminConfigurations();
             $ptConfigs = $entity->getPageTemplates();
             foreach ($ppConfigs as $ppConfig) {
                 $parts = explode(":", $ppConfig);
                 $ppConfigFilename = $parts[count($parts) - 1];
                 // Context found in this Page class
                 if (array_key_exists($ppConfigFilename, $sectionInfo)) {
                     // Search for templates
                     foreach ($ptConfigs as $ptConfig) {
                         $parts = explode(":", $ptConfig);
                         $ptConfigFilename = $parts[count($parts) - 1];
                         // Page template found
                         if (array_key_exists($ptConfigFilename, $sectionInfo[$ppConfigFilename]['pagetempates'])) {
                             $formType = $entity->getDefaultAdminType();
                             if (!is_object($formType)) {
                                 $formType = $this->container->get($formType);
                             }
                             // Get all page properties
                             $form = $this->container->get('form.factory')->create($formType);
                             $children = $form->createView()->children;
                             $pageFields = array();
                             foreach ($children as $field) {
                                 $name = $field->vars['name'];
                                 $attr = $field->vars['attr'];
                                 $blocks = $field->vars['block_prefixes'];
                                 if ($name == 'title' || $name == 'pageTitle') {
                                     continue;
                                 }
                                 if ($blocks[1] == 'hidden') {
                                     // do nothing
                                 } elseif ($blocks[1] == 'choice' && $blocks[1] == 'entity') {
                                     // do nothing
                                 } elseif ($blocks[1] == 'datetime') {
                                     $pageFields[]['datetime'] = array('label' => $this->labelCase($name), 'date_random' => DateTime::date('d/m/Y'), 'time_random' => DateTime::time('H:i'));
                                 } elseif ($blocks[1] == 'number') {
                                     $pageFields[]['decimal'] = array('label' => $this->labelCase($name), 'random' => Base::randomFloat(2, 0, 99999));
                                 } elseif ($blocks[1] == 'integer') {
                                     $pageFields[]['integer'] = array('label' => $this->labelCase($name), 'random' => Base::randomNumber(3000, 99999));
                                 } elseif ($blocks[1] == 'checkbox') {
                                     $pageFields[]['boolean'] = array('label' => $this->labelCase($name));
                                 } elseif ($blocks[1] == 'media') {
                                     $id = count($images) > 0 ? $images[0]->getId() : 1;
                                     $pageFields[]['media'] = array('label' => $this->labelCase($name), 'random' => $id);
                                 } elseif ($blocks[2] == 'urlchooser') {
                                     $pageFields[]['link'] = array('label' => $this->labelCase($name), 'random' => 'http://www.' . strtolower(Lorem::word()) . '.com');
                                 } elseif ($blocks[2] == 'textarea' && array_key_exists('class', $attr) && $attr['class'] == 'rich_editor') {
                                     $pageFields[]['rich_text'] = array('label' => $this->labelCase($name), 'random' => Lorem::sentence());
                                 } elseif ($blocks[2] == 'textarea' || $blocks[1] == 'text') {
                                     $pageFields[]['text'] = array('label' => $this->labelCase($name), 'random' => Lorem::word());
                                 }
                             }
                             $pages[] = array('name' => $className, 'section' => $sectionInfo[$ppConfigFilename]['context'], 'template' => $sectionInfo[$ppConfigFilename]['pagetempates'][$ptConfigFilename], 'fields' => $pageFields);
                         }
                     }
                 }
             }
         }
     }
     /*
         Example $pages contents:
         Array
         (
             [0] => Array
                 (
                     [name] => ContentPage
                     [section] => main
                     [template] => Page with left sidebar
                     [fields] => Array
                         (
                             ...
                         )
                 )
             [1] => Array
                 (
                     [name] => ContentPage
                     [section] => main
                     [template] => Full width page
                     [fields] => Array
                         (
                             ...
                         )
                 )
             [2] => Array
                 (
                     [name] => HomePage
                     [section] => main
                     [template] => Home page
                     [fields] => Array
                         (
                             ...
                         )
                 )
         )
     */
     // Add some random values in the field array, so that this values can be uses as test values
     foreach ($this->fields as $fkey => $fieldSet) {
         foreach ($fieldSet as $key => $values) {
             switch ($key) {
                 case 'multi_line':
                 case 'single_line':
                     $values[0]['random1'] = Lorem::word();
                     $values[0]['random2'] = Lorem::word();
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'rich_text':
                     $values[0]['random1'] = Lorem::sentence();
                     $values[0]['random2'] = Lorem::sentence();
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'link':
                     $values['url']['random1'] = 'http://www.' . strtolower(Lorem::word()) . '.com';
                     $values['url']['random2'] = 'http://www.' . strtolower(Lorem::word()) . '.com';
                     $values['url']['lName'] = $this->labelCase($values['url']['fieldName']);
                     $values['text']['random1'] = Lorem::word();
                     $values['text']['random2'] = Lorem::word();
                     $values['text']['lName'] = $this->labelCase($values['text']['fieldName']);
                     $values['new_window']['lName'] = $this->labelCase($values['new_window']['fieldName']);
                     break;
                 case 'image':
                     if (count($images) > 0) {
                         if (count($images) > 1) {
                             $values['image']['id_random1'] = $images[0]->getId();
                             $values['image']['url_random1'] = $images[0]->getUrl();
                             $values['image']['id_random2'] = $images[1]->getId();
                             $values['image']['url_random2'] = $images[1]->getUrl();
                         } else {
                             $values['image']['id_random1'] = $values['image']['id_random2'] = $images[0]->getId();
                             $values['image']['url_random1'] = $values['image']['url_random2'] = $images[0]->getUrl();
                         }
                     } else {
                         $values['image']['id_random1'] = $values['image']['id_random2'] = '1';
                         $values['image']['url_random1'] = $values['image']['url_random2'] = 'XXX';
                     }
                     $values['image']['lName'] = $this->labelCase($values['image']['fieldName']);
                     $values['alt_text']['random1'] = Lorem::word();
                     $values['alt_text']['random2'] = Lorem::word();
                     $values['alt_text']['lName'] = $this->labelCase($values['alt_text']['fieldName']);
                     break;
                 case 'boolean':
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'integer':
                     $values[0]['random1'] = Base::randomNumber(3000, 99999);
                     $values[0]['random2'] = Base::randomNumber(3000, 99999);
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'decimal':
                     $values[0]['random1'] = Base::randomFloat(2, 0, 99999);
                     $values[0]['random2'] = Base::randomFloat(2, 0, 99999);
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
                 case 'datetime':
                     $values[0]['date_random1'] = DateTime::date('d/m/Y');
                     $values[0]['date_random2'] = DateTime::date('d/m/Y');
                     $values[0]['time_random1'] = DateTime::time('H:i');
                     $values[0]['time_random2'] = DateTime::time('H:i');
                     $dparts = explode('/', $values[0]['date_random1']);
                     $values[0]['datetime_random1'] = $dparts[2] . '-' . $dparts[1] . '-' . $dparts[0] . ' ' . $values[0]['time_random1'] . ':00';
                     $dparts = explode('/', $values[0]['date_random2']);
                     $values[0]['datetime_random2'] = $dparts[2] . '-' . $dparts[1] . '-' . $dparts[0] . ' ' . $values[0]['time_random2'] . ':00';
                     $values[0]['lName'] = $this->labelCase($values[0]['fieldName']);
                     break;
             }
             $this->fields[$fkey][$key] = $values;
         }
     }
     $params = array('name' => $this->entity, 'pages' => $pages, 'fields' => $this->fields);
     $this->renderFile('/Features/PagePart.feature', $this->bundle->getPath() . '/Features/Admin' . $this->entity . '.feature', $params);
     $this->assistant->writeLine('Generating behat test : <info>OK</info>');
 }
コード例 #3
0
 public function testFixedSeedWithMaximumTimestamp()
 {
     $max = '2018-03-01 12:00:00';
     mt_srand(1);
     $unixTime = DateTimeProvider::unixTime($max);
     $datetimeAD = DateTimeProvider::dateTimeAD($max);
     $dateTime1 = DateTimeProvider::dateTime($max);
     $dateTimeBetween = DateTimeProvider::dateTimeBetween('2014-03-01 06:00:00', $max);
     $date = DateTimeProvider::date('Y-m-d', $max);
     $time = DateTimeProvider::time('H:i:s', $max);
     $iso8601 = DateTimeProvider::iso8601($max);
     $dateTimeThisCentury = DateTimeProvider::dateTimeThisCentury($max);
     $dateTimeThisDecade = DateTimeProvider::dateTimeThisDecade($max);
     $dateTimeThisMonth = DateTimeProvider::dateTimeThisMonth($max);
     $amPm = DateTimeProvider::amPm($max);
     $dayOfMonth = DateTimeProvider::dayOfMonth($max);
     $dayOfWeek = DateTimeProvider::dayOfWeek($max);
     $month = DateTimeProvider::month($max);
     $monthName = DateTimeProvider::monthName($max);
     $year = DateTimeProvider::year($max);
     $dateTimeThisYear = DateTimeProvider::dateTimeThisYear($max);
     mt_srand();
     //regenerate Random Date with same seed and same maximum end timestamp
     mt_srand(1);
     $this->assertEquals($unixTime, DateTimeProvider::unixTime($max));
     $this->assertEquals($datetimeAD, DateTimeProvider::dateTimeAD($max));
     $this->assertEquals($dateTime1, DateTimeProvider::dateTime($max));
     $this->assertEquals($dateTimeBetween, DateTimeProvider::dateTimeBetween('2014-03-01 06:00:00', $max));
     $this->assertEquals($date, DateTimeProvider::date('Y-m-d', $max));
     $this->assertEquals($time, DateTimeProvider::time('H:i:s', $max));
     $this->assertEquals($iso8601, DateTimeProvider::iso8601($max));
     $this->assertEquals($dateTimeThisCentury, DateTimeProvider::dateTimeThisCentury($max));
     $this->assertEquals($dateTimeThisDecade, DateTimeProvider::dateTimeThisDecade($max));
     $this->assertEquals($dateTimeThisMonth, DateTimeProvider::dateTimeThisMonth($max));
     $this->assertEquals($amPm, DateTimeProvider::amPm($max));
     $this->assertEquals($dayOfMonth, DateTimeProvider::dayOfMonth($max));
     $this->assertEquals($dayOfWeek, DateTimeProvider::dayOfWeek($max));
     $this->assertEquals($month, DateTimeProvider::month($max));
     $this->assertEquals($monthName, DateTimeProvider::monthName($max));
     $this->assertEquals($year, DateTimeProvider::year($max));
     $this->assertEquals($dateTimeThisYear, DateTimeProvider::dateTimeThisYear($max));
     mt_srand();
 }