Skip to content

Commit

Permalink
Adds support for @original replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleyhindle committed Jan 20, 2019
1 parent 7cc9f89 commit 8181e83
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/PrivateDump/Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(Generator $faker)
* Generate random string
*
* @param string $value
*
* @return bool|string
*/
public function transformString($value)
Expand All @@ -49,6 +50,7 @@ public function transformString($value)

/**
* @param string $value
*
* @return string
*/
public function transformUppercase($value)
Expand All @@ -58,6 +60,7 @@ public function transformUppercase($value)

/**
* @param string $value
*
* @return string
*/
public function transformLowercase($value)
Expand All @@ -67,13 +70,24 @@ public function transformLowercase($value)

/**
* @param string $value
*
* @return string
*/
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
Expand Down
19 changes: 19 additions & 0 deletions tests/PrivateDump/TransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]', $this->transformer->transform('[email protected]', '@original'));
$this->assertEquals('admin@exa', $this->transformer->transform('[email protected]', '@original|max:9'));
}
}

0 comments on commit 8181e83

Please sign in to comment.