Skip to content

Commit

Permalink
unqiue faker fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Redjik committed Aug 19, 2015
1 parent 22b077c commit 5f0f0d8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions api/tests/Traits/HelpersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ protected function getFakerWithUniqueUserData()
// As the array of already used faker data is protected in Faker and
// has no accessor method, we'll rely on ReflectionObject to modify
// the property before letting faker generate data.

//though reflected object should be added to the faker itself somehow
// which is hacky
//so we decided to overcome it with bindTo hack
$faker = Faker::create();
$unique = $faker->unique();

$object = new ReflectionObject($unique);
$property = $object->getProperty('uniques');
$property->setAccessible(true);
$property->setValue($unique, $this->uniques);
$binder = function($value){
$this->unqiue = $value;
};

$unqiueBinder = $binder->bindTo($unique,$unique);
$unqiueBinder($this->uniques);

return $faker;
}

Expand Down

0 comments on commit 5f0f0d8

Please sign in to comment.