From e088a2e625dc97ab7437dcf4e879d1cc1155f0ea Mon Sep 17 00:00:00 2001 From: lsv Date: Mon, 17 Jun 2013 01:35:10 +0200 Subject: [PATCH] added rgbCssColor method --- readme.md | 1 + src/Faker/Provider/Color.php | 8 ++++++++ test/Faker/Provider/ColorTest.php | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/readme.md b/readme.md index d95a07b8..257b35a2 100644 --- a/readme.md +++ b/readme.md @@ -191,6 +191,7 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle hexcolor // '#fa3cc2' rgbcolor // '0,255,122' rgbColorAsArray // array(0,255,122) + rgbCssColor // 'rgb(0,255,122)' safeColorName // 'fuchsia' colorName // 'Gainsbor' diff --git a/src/Faker/Provider/Color.php b/src/Faker/Provider/Color.php index 1b852383..ac0fad7b 100644 --- a/src/Faker/Provider/Color.php +++ b/src/Faker/Provider/Color.php @@ -105,6 +105,14 @@ class Color extends Base return implode(',', static::rgbColorAsArray()); } + /** + * @example 'rgb(0,255,122)' + */ + public static function rgbCssColor() + { + return 'rgb(' . static::rgbColor() . ')'; + } + /** * @example 'blue' */ diff --git a/test/Faker/Provider/ColorTest.php b/test/Faker/Provider/ColorTest.php index 8010a0aa..4f20ef34 100644 --- a/test/Faker/Provider/ColorTest.php +++ b/test/Faker/Provider/ColorTest.php @@ -23,4 +23,10 @@ class ColorTest extends \PHPUnit_Framework_TestCase $this->assertRegExp('/^' . $regexp . ',' . $regexp . ',' . $regexp . '$/i', Color::rgbColor()); } + public function testRgbCssColor() + { + $regexp = '([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])'; + $this->assertRegExp('/^rgb\(' . $regexp . ',' . $regexp . ',' . $regexp . '\)$/i', Color::rgbCssColor()); + } + } \ No newline at end of file