/** * @expectedException \InvalidArgumentException */ public function testTextMinLength() { $generator = new Generator(); $generator->addProvider(new Text($generator)); $generator->seed(0); $generator->realText(9); }
/** * Generate products. * * ## Options * * [--file=<file>] * : Specify which files to used. By default pulls random zips from DB. * * [--count=<count>] * : How many products to generate. Default: 15 * * @param $args * @param $assoc_args */ public function generate($args, $assoc_args) { $count = \WP_CLI\Utils\get_flag_value($assoc_args, 'count', 15); if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'file')) { /** * @var \wpdb $wpdb */ global $wpdb; $results = $wpdb->get_results($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment'\n\t\t\t\t AND post_mime_type = 'application/zip' LIMIT %d", $count)); $files = array(); foreach ($results as $result) { $files[] = $result->ID; } } else { if (get_post_type($assoc_args['file']) != 'attachment') { WP_CLI::error("Invalid file post type."); } $files = array($assoc_args['file']); } if (empty($files)) { WP_CLI::error('No files exist.'); } $notify = \WP_CLI\Utils\make_progress_bar('Generating products.', $count); $limits = array('-', '2', '2', '5', '5', '10'); for ($i = 0; $i < $count; $i++) { $title = $this->faker->catchPhrase . ' software'; $price = itelic_purebell(44, 199, 45); $price = floatval(intval($price)); $index = array_rand($files); $file = get_post($files[$index]); try { $file = itelic_rename_file($file, $title . '-1.0.zip'); } catch (InvalidArgumentException $e) { WP_CLI::error($e->getMessage()); } $params = array('description' => $this->faker->realText(), 'limit' => $limits[array_rand($limits)], 'file' => $file->ID); $recurring = array(array('interval' => 'month', 'count' => 1, 'frequency' => 10), array('interval' => 'month', 'count' => 6, 'frequency' => 20), array('interval' => 'none', 'frequency' => 30), array('interval' => 'year', 'count' => 1, 'frequency' => 100)); $rand = rand(0, 100); foreach ($recurring as $option) { if ($rand <= $option['frequency']) { if ($option['interval'] != 'none') { $params['interval'] = $option['interval']; $params['interval-count'] = $option['count']; } break; } } $result = $this->create_product($title, $price, $params); if (is_wp_error($result)) { WP_CLI::error($result); } $notify->tick(); } $notify->finish(); }
/** * @param int $count * @param Video[] $videos * @param User[] $users * @param Repository $repo * @throws \Exception */ protected function createComments($count, $videos, $users, Repository $repo) { $this->out->writeln(Comment::class); /** @var ProgressHelper $progress */ $progress = $this->getHelperSet()->get('progress'); $progress->start($this->out, count($videos) * $count); foreach ($videos as $video) { $comments = []; for ($i = 0; $i < $count; ++$i) { $comment = new Comment(); $comment->author = $this->faker->randomElement($users); $comment->text = $this->faker->realText(100); $comment->inReplyTo = $this->faker->optional(0.25)->randomElement($comments); $video->comments->add($comment); $comments[] = $comment; $progress->advance(); } $repo->persist($video); } $progress->finish(); }
public function load(ObjectManager $manager) { $faker = new Faker\Generator(); $faker->addProvider(new Faker\Provider\en_US\Text($faker)); $faker->addProvider(new Faker\Provider\Lorem($faker)); for ($i = 1; $i <= 100; $i++) { $post = new Post(); $post->setTitle($faker->sentence(4)); $post->setBody($faker->realText(500)); $manager->persist($post); } $manager->flush(); }