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

Add hslColor to ColorProvider #1776

Merged
merged 3 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding a @return annotation with array as type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its more like string. But I added it :)

* @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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding a @return annotation with array as type here?

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