Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1776 from icanhazstring/feature/hsl
Browse files Browse the repository at this point in the history
Add hslColor to ColorProvider
  • Loading branch information
localheinz authored Aug 27, 2019
2 parents 3f74f49 + 3871f90 commit 0c53182
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
27 changes: 27 additions & 0 deletions src/Faker/Provider/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,31 @@ public static function colorName()
{
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)
);
}
}
12 changes: 12 additions & 0 deletions test/Faker/Provider/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ public function testColorName()
{
$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());
}
}

0 comments on commit 0c53182

Please sign in to comment.