mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-04-21 16:01:56 +02:00
Add hslcolor
This will add hslColor and hslColorAsArray for ColorProvider Should solve #1720
This commit is contained in:
parent
1af085ffb1
commit
cd7422041d
@ -113,4 +113,26 @@ class Color extends Base
|
||||
{
|
||||
return static::randomElement(static::$allColorNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example '340,50,20'
|
||||
*/
|
||||
public static function hslColor()
|
||||
{
|
||||
return sprintf(
|
||||
'%s,%s,%s',
|
||||
static::numberBetween(0, 360),
|
||||
static::numberBetween(0, 100),
|
||||
static::numberBetween(0, 100)
|
||||
);
|
||||
}
|
||||
|
||||
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