public function testNumberBetween() { $min = 5; $max = 6; $this->assertGreaterThanOrEqual($min, BaseProvider::numberBetween($min, $max)); $this->assertGreaterThanOrEqual(BaseProvider::numberBetween($min, $max), $max); }
/** * @param string|null $type If specified, return the type value. See {@see User::getAllowedTypes()} to see valid * type names; if is invalid will return en empty array. Otherwise return an array with a * random of types. * * @return array Array of user types. */ public function userTypes($type = null) { $allowedTypes = User::getAllowedTypes(); if (null === $type) { return BaseProvider::randomElements($allowedTypes, BaseProvider::numberBetween(1, count($allowedTypes))); } return isset($allowedTypes[$type]) ? [$allowedTypes[$type]] : []; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $imagine = new Imagine(); $width = $input->getOption('width') ?: Faker::numberBetween(200, 1200); $height = $input->getOption('height') ?: Faker::numberBetween(200, 1200); $extension = $input->getOption('extension') ?: Faker::randomElement($this->getAvailableExtensions()); $selector = new Selector($input->getOption('samples')); $images = $selector->select($width, $height, $extension); $filter = array_filter($images, function (Image $image) use($width, $height) { return $width * $height >= $image->getPixels(); }); if (true === empty($filter)) { $image = Faker::randomElement($images); } else { $image = Faker::randomElement($filter); } $transformed = tempnam(sys_get_temp_dir(), uniqid()); $transformation = new Transformation(); $transformation->thumbnail(new Box($width, $height), ImageInterface::THUMBNAIL_OUTBOUND)->save($transformed); $transformation->apply($imagine->open($image->getPath())); $this->getFormatter($input->getOption('formatter'))->output(new Image($transformed), $output); }
/** * From range return a random Integer * Providing the $elements param will limit the returning integer to the total number of elements * * @param array|int $qty The range or integer * @param null|int|array $elements { * @example null Will not limit the Range to a maximum int * @example int Limits the range to this maximum * @example array Counts the elements in array and limit to that * } * @return int */ public function get_qty_from_range($range, $total = null) { if (is_array($range)) { // Remove non-wanted items $range = array_filter($range); // Grabs Min $min = reset($range); // Grabs Max if range has 2 elements if (count($range) > 1) { $max = end($range); } else { // Otherwise just set qty to the Min $qty = $min; } } elseif (is_numeric($range)) { // If we have a numeric we just set it $qty = $range; } else { // All the other cases are a qty 0 return 0; } // Now we treat the Range and select a random number if (!isset($qty)) { $qty = Faker\Provider\Base::numberBetween($min, $max); } // If an array for the total was provided, turn it to a integer if (is_array($total)) { $total = count($total); } // If we have a numeric total, make sure we don't go over that if (is_numeric($total)) { $qty = min($qty, $total); } // We just make sure we are dealing with a absolute number return absint($qty); }
public function testNumberBetweenAcceptsZeroAsMax() { $this->assertEquals(0, BaseProvider::numberBetween(0, 0)); }
public function ttl() { return [[Base::numberBetween(60, 2678400)]]; }