FEATURE: Add basic support for faker

This commit is contained in:
Daniel Siepmann 2017-02-03 17:11:28 +01:00
parent ee310bd580
commit 3b0e0bdd0f
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 23 additions and 0 deletions

View file

@ -17,3 +17,6 @@ data:
type: userfunc type: userfunc
class: DSiepmann\Userfunction\RepeatingFilenames class: DSiepmann\Userfunction\RepeatingFilenames
method: filename method: filename
date:
type: faker
formatter: dateTime

View file

@ -71,6 +71,14 @@ types are supported:
class: DSiepmann\Userfunction\RepeatingFilenames class: DSiepmann\Userfunction\RepeatingFilenames
method: filename method: filename
``faker``
Uses a formatter defined by `faker`_.
.. code:: yml
date:
type: faker
formatter: dateTime
.. _faker: https://github.com/fzaninotto/Faker .. _faker: https://github.com/fzaninotto/Faker
.. _Doctrine DBAL: http://www.doctrine-project.org/projects/dbal.html .. _Doctrine DBAL: http://www.doctrine-project.org/projects/dbal.html

View file

@ -121,6 +121,18 @@ class FakeMysqlCommand extends Command
return $userfunction->$userMethod(); return $userfunction->$userMethod();
} }
if ($config['type'] === 'faker') {
$formatterToUse = $config['formatter'];
$fakerData = $this->faker->$formatterToUse();
if ($fakerData instanceof \DateTime) {
$fakerData = $fakerData->format('Y-m-d H:i:s');
}
return $fakerData;
}
throw new \Exception('Unkown configured value.', 1486135949); throw new \Exception('Unkown configured value.', 1486135949);
} }
} }