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

Add RGBA functionality to Color Provider #653

Merged
merged 2 commits into from
Aug 24, 2015
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
8 changes: 8 additions & 0 deletions src/Faker/Provider/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public static function rgbCssColor()
return 'rgb(' . static::rgbColor() . ')';
}

/**
* @example 'rgba(0,255,122,0.8)'
*/
public static function rgbaCssColor()
Copy link
Owner

Choose a reason for hiding this comment

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

I'd name it rgbaColor()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to respect the naming convention of the function "rgbCssColor". That's why I think this is the most appropriate. Don't you think so ?

Copy link
Owner

Choose a reason for hiding this comment

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

right!

{
return 'rgba(' . static::rgbColor() . ',' . static::randomFloat(1, 0, 1) . ')';
}

/**
* @example 'blue'
*/
Expand Down
7 changes: 7 additions & 0 deletions test/Faker/Provider/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public function testRgbCssColor()
$this->assertRegExp('/^rgb\(' . $regexp . ',' . $regexp . ',' . $regexp . '\)$/i', Color::rgbCssColor());
}

public function testRgbaCssColor()
{
$regexp = '([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])';
$regexpAlpha = '([01]?\.[0-9])';
$this->assertRegExp('/^rgba\(' . $regexp . ',' . $regexp . ',' . $regexp . ',' . $regexpAlpha . '\)$/i', Color::rgbaCssColor());
}

public function testSafeColorName()
{
$this->assertRegExp('/^[\w]+$/', Color::safeColorName());
Expand Down