Skip to content

Commit

Permalink
Fix UniqueGenerator not storing previously generated values when call…
Browse files Browse the repository at this point in the history
…ing ->ext() method
  • Loading branch information
Bram Ceulemans committed Jan 18, 2022
1 parent 598bec1 commit 012c00e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Faker/UniqueGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ class UniqueGenerator
protected $uniques = [];

/**
* @param Extension|Generator $generator
* @param int $maxRetries
* @param Extension|Generator $generator
* @param int $maxRetries
* @param array<string, array<string, null>> $uniques
*/
public function __construct($generator, $maxRetries = 10000)
public function __construct($generator, $maxRetries = 10000, & $uniques = [])
{
$this->generator = $generator;
$this->maxRetries = $maxRetries;
$this->uniques = &$uniques;
}

public function ext(string $id)
{
return new self($this->generator->ext($id), $this->maxRetries);
return new self($this->generator->ext($id), $this->maxRetries, $this->uniques);
}

/**
Expand Down Expand Up @@ -80,6 +82,8 @@ public function __call($name, $arguments)
} while (array_key_exists(serialize($res), $this->uniques[$name]));
$this->uniques[$name][serialize($res)] = null;

var_dump($this->uniques);

return $res;
}
}

0 comments on commit 012c00e

Please sign in to comment.