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

Commit 0c53182

Browse files
authored
Merge pull request #1776 from icanhazstring/feature/hsl
Add hslColor to ColorProvider
2 parents 3f74f49 + 3871f90 commit 0c53182

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ Methods accepting a `$timezone` argument default to `date_default_timezone_get()
250250
rgbCssColor // 'rgb(0,255,122)'
251251
safeColorName // 'fuchsia'
252252
colorName // 'Gainsbor'
253+
hslColor // '340,50,20'
254+
hslColorAsArray // array(340,50,20)
253255

254256
### `Faker\Provider\File`
255257

src/Faker/Provider/Color.php

+27
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,31 @@ public static function colorName()
113113
{
114114
return static::randomElement(static::$allColorNames);
115115
}
116+
117+
/**
118+
* @example '340,50,20'
119+
* @return string
120+
*/
121+
public static function hslColor()
122+
{
123+
return sprintf(
124+
'%s,%s,%s',
125+
static::numberBetween(0, 360),
126+
static::numberBetween(0, 100),
127+
static::numberBetween(0, 100)
128+
);
129+
}
130+
131+
/**
132+
* @example array(340, 50, 20)
133+
* @return array
134+
*/
135+
public static function hslColorAsArray()
136+
{
137+
return array(
138+
static::numberBetween(0, 360),
139+
static::numberBetween(0, 100),
140+
static::numberBetween(0, 100)
141+
);
142+
}
116143
}

test/Faker/Provider/ColorTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,16 @@ public function testColorName()
5151
{
5252
$this->assertRegExp('/^[\w]+$/', Color::colorName());
5353
}
54+
55+
public function testHslColor()
56+
{
57+
$regexp360 = '(?:36[0]|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9])';
58+
$regexp100 = '(?:100|[1-9]?[0-9])';
59+
$this->assertRegExp('/^' . $regexp360 . ',' . $regexp100 . ',' . $regexp100 . '$/', Color::hslColor());
60+
}
61+
62+
public function testHslColorArray()
63+
{
64+
$this->assertCount(3, Color::hslColorAsArray());
65+
}
5466
}

0 commit comments

Comments
 (0)