Skip to content

Commit 02f17be

Browse files
committed
Merge pull request fzaninotto#653 from thegobeliners/master
Add RGBA functionality to Color Provider
2 parents bff9c70 + 82566dc commit 02f17be

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Faker/Provider/Color.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ public static function rgbCssColor()
9090
return 'rgb(' . static::rgbColor() . ')';
9191
}
9292

93+
/**
94+
* @example 'rgba(0,255,122,0.8)'
95+
*/
96+
public static function rgbaCssColor()
97+
{
98+
return 'rgba(' . static::rgbColor() . ',' . static::randomFloat(1, 0, 1) . ')';
99+
}
100+
93101
/**
94102
* @example 'blue'
95103
*/

test/Faker/Provider/ColorTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public function testRgbCssColor()
3434
$this->assertRegExp('/^rgb\(' . $regexp . ',' . $regexp . ',' . $regexp . '\)$/i', Color::rgbCssColor());
3535
}
3636

37+
public function testRgbaCssColor()
38+
{
39+
$regexp = '([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])';
40+
$regexpAlpha = '([01]?\.[0-9])';
41+
$this->assertRegExp('/^rgba\(' . $regexp . ',' . $regexp . ',' . $regexp . ',' . $regexpAlpha . '\)$/i', Color::rgbaCssColor());
42+
}
43+
3744
public function testSafeColorName()
3845
{
3946
$this->assertRegExp('/^[\w]+$/', Color::safeColorName());

0 commit comments

Comments
 (0)