Skip to content
Permalink
Browse files

Add support for Faker optional modifier

  • Loading branch information...
pskt committed Oct 10, 2019
1 parent 60e1806 commit b69e1e884f9456af33ea28eba28e482cb3f06dec
Showing with 47 additions and 2 deletions.
  1. +36 −0 features/Run/Mask/faker.feature
  2. +11 −2 src/Fogger/Mask/FakerMask.php
@@ -37,3 +37,39 @@ Feature:
| ex2@tsh.io |
| ex3@tsh.io |
| ex4@tsh.io |

Scenario: Support Faker's optional modifier
Given there is a source database
And there is a table users with following columns:
| name | type | length | index |
| id | integer | | primary |
| email | string | 64 | |
| desc | string | 128 | |
And the table users contains following data:
| id | email | desc |
| 4 | ex4@tsh.io | desc 4 |
| 3 | ex3@tsh.io | desc 3 |
| 1 | ex1@tsh.io | desc 1 |
| 2 | ex2@tsh.io | desc 2 |
And there is an empty target database
And the task queue is empty
And the config test.yaml contains:
"""
tables:
users:
columns:
email: { maskStrategy: none, options: { } }
desc: { maskStrategy: "faker", options: { method: "email", modifier: "optional", modifierArguments: [0, default] } }
"""
When I run "run" command with input:
| --chunk-size | 1000 |
| --file | test.yaml |
| --dont-wait | true |
And worker processes 1 task
Then the table users in target database should have 4 rows
And the table users in target database should contain rows:
| email | desc |
| ex1@tsh.io | default |
| ex2@tsh.io | default |
| ex3@tsh.io | default |
| ex4@tsh.io | default |
@@ -21,8 +21,17 @@ public function __construct(Generator $generator, CacheItemPoolInterface $cache)
public function getSubstitution(array $options = []): ?string
{
$method = $options['method'] ?? self::DEFAULT_METHOD;
$parameters = $options['arguments'] ?? [];
$result = $this->generator->$method(...$parameters);
$arguments = $options['arguments'] ?? [];
$modifier = $options['modifier'] ?? null;
$modifierArguments = $options['modifierArguments'] ?? [];
$generator = $this->generator;
if ('optional' === $modifier) {
$generator = $generator->optional(...$modifierArguments);
}
$result = $generator->$method(...$arguments);
if (is_array($result)) {
$result = implode(' ', $result);

0 comments on commit b69e1e8

Please sign in to comment.
You can’t perform that action at this time.