mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-04-21 16:01:56 +02:00
Merge pull request #1776 from icanhazstring/feature/hsl
Add hslColor to ColorProvider
This commit is contained in:
commit
0c53182cf3
@ -250,6 +250,8 @@ Methods accepting a `$timezone` argument default to `date_default_timezone_get()
|
||||
rgbCssColor // 'rgb(0,255,122)'
|
||||
safeColorName // 'fuchsia'
|
||||
colorName // 'Gainsbor'
|
||||
hslColor // '340,50,20'
|
||||
hslColorAsArray // array(340,50,20)
|
||||
|
||||
### `Faker\Provider\File`
|
||||
|
||||
|
@ -113,4 +113,31 @@ class Color extends Base
|
||||
{
|
||||
return static::randomElement(static::$allColorNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example '340,50,20'
|
||||
* @return string
|
||||
*/
|
||||
public static function hslColor()
|
||||
{
|
||||
return sprintf(
|
||||
'%s,%s,%s',
|
||||
static::numberBetween(0, 360),
|
||||
static::numberBetween(0, 100),
|
||||
static::numberBetween(0, 100)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example array(340, 50, 20)
|
||||
* @return array
|
||||
*/
|
||||
public static function hslColorAsArray()
|
||||
{
|
||||
return array(
|
||||
static::numberBetween(0, 360),
|
||||
static::numberBetween(0, 100),
|
||||
static::numberBetween(0, 100)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -51,4 +51,16 @@ class ColorTest extends TestCase
|
||||
{
|
||||
$this->assertRegExp('/^[\w]+$/', Color::colorName());
|
||||
}
|
||||
|
||||
public function testHslColor()
|
||||
{
|
||||
$regexp360 = '(?:36[0]|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9])';
|
||||
$regexp100 = '(?:100|[1-9]?[0-9])';
|
||||
$this->assertRegExp('/^' . $regexp360 . ',' . $regexp100 . ',' . $regexp100 . '$/', Color::hslColor());
|
||||
}
|
||||
|
||||
public function testHslColorArray()
|
||||
{
|
||||
$this->assertCount(3, Color::hslColorAsArray());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user