From 8181e83da737f43c0e8483f4d86d5c3dc47f752c Mon Sep 17 00:00:00 2001 From: Ashley Hindle Date: Sun, 20 Jan 2019 22:55:50 +0000 Subject: [PATCH] Adds support for @original replacement --- README.md | 3 ++- src/PrivateDump/Transformer.php | 14 ++++++++++++++ tests/PrivateDump/TransformerTest.php | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aa68626..bef8601 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ composer require ashleyhindle/private-dump Install with [curl](https://curl.haxx.se/) ```bash -curl -Lo private-dump https://github.com/ashleyhindle/private-dump/releases/download/v0.0.5/private-dump +curl -Lo private-dump https://github.com/ashleyhindle/private-dump/releases/download/v0.0.6/private-dump chmod a+x private-dump ``` @@ -200,6 +200,7 @@ If you need to use a hardcoded value (active=0, completed=1) you can do this by #### Text +- `original` - The original value, useful to use for modifiers - `string` - Random length string up to 255 characters - `realText` - Quotes from books - `loremSentence` - 1 sentence of Lorem diff --git a/src/PrivateDump/Transformer.php b/src/PrivateDump/Transformer.php index 3b0bffd..05efee4 100644 --- a/src/PrivateDump/Transformer.php +++ b/src/PrivateDump/Transformer.php @@ -33,6 +33,7 @@ public function __construct(Generator $faker) * Generate random string * * @param string $value + * * @return bool|string */ public function transformString($value) @@ -49,6 +50,7 @@ public function transformString($value) /** * @param string $value + * * @return string */ public function transformUppercase($value) @@ -58,6 +60,7 @@ public function transformUppercase($value) /** * @param string $value + * * @return string */ public function transformLowercase($value) @@ -67,6 +70,7 @@ public function transformLowercase($value) /** * @param string $value + * * @return string */ public function transformIso8601Recent($value) @@ -74,6 +78,16 @@ public function transformIso8601Recent($value) return $this->faker->dateTimeBetween('-3 months')->format(\DateTime::ATOM); } + /** + * @param $value + * + * @return mixed + */ + public function transformOriginal($value) + { + return $value; + } + /** * Transform given value based on the replacement string provided from the JSON * @param string $value diff --git a/tests/PrivateDump/TransformerTest.php b/tests/PrivateDump/TransformerTest.php index e0e4aeb..b75f4f8 100644 --- a/tests/PrivateDump/TransformerTest.php +++ b/tests/PrivateDump/TransformerTest.php @@ -32,4 +32,23 @@ public function nonFakerTransformersWork() $this->transformer->transform('test', '@iso8601Recent') ); } + + /** @test */ + public function max_modifier_works() + { + $this->assertEquals(8, strlen($this->transformer->transform('test', '@userName|max:8'))); + } + + /** @test */ + public function static_values_work() + { + $this->assertEquals('replacementValue', $this->transformer->transform('test', 'replacementValue')); + } + + /** @test */ + public function original_replacement_works() + { + $this->assertEquals('admin@example.com', $this->transformer->transform('admin@example.com', '@original')); + $this->assertEquals('admin@exa', $this->transformer->transform('admin@example.com', '@original|max:9')); + } }