1
0
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:
Andreas Frömer 2019-08-26 22:17:40 +02:00
parent 1af085ffb1
commit cd7422041d
2 changed files with 34 additions and 0 deletions

View File

@ -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)
);
}
}

View File

@ -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());
}
}