@@ -28,6 +28,9 @@ class ObjectGraphGenerator
2828 /** @var array */
2929 private $ registry ;
3030
31+ /** @var array */
32+ private $ temporaryRegistry = [];
33+
3134 public function __construct (array $ registry = [])
3235 {
3336 $ this ->fakerInstance = Factory::create ();
@@ -40,16 +43,18 @@ public function __construct(array $registry = [])
4043 $ this ->registry = $ registry ;
4144 }
4245
43- public function generateWithSeed (string $ className, int $ seed ): object
46+ public function generate (string $ className ): object
4447 {
45- $ this ->fakerInstance ->seed ($ seed );
46-
4748 return $ this ->generateObject ($ className );
4849 }
4950
50- public function generate (string $ className ): object
51+ public function generateWithTemporaryConfig (string $ className, array $ config ): object
5152 {
52- return $ this ->generateObject ($ className );
53+ $ this ->temporaryRegistry = $ config ;
54+ $ object = $ this ->generateObject ($ className );
55+ $ this ->temporaryRegistry = [];
56+
57+ return $ object ;
5358 }
5459
5560 /**
@@ -146,11 +151,14 @@ function () use ($argumentName, $className, $type) {
146151
147152 private function isInRegistry (string $ key ): bool
148153 {
149- return array_key_exists ($ key , $ this ->registry );
154+ return array_key_exists ($ key , $ this ->temporaryRegistry ) || array_key_exists ( $ key , $ this -> registry );
150155 }
151156
152157 private function getFromRegistry (string $ key )
153158 {
159+ if (isset ($ this ->temporaryRegistry [$ key ])) {
160+ return $ this ->temporaryRegistry [$ key ]($ this , $ this ->fakerInstance );
161+ }
154162 return $ this ->registry [$ key ]($ this , $ this ->fakerInstance );
155163 }
156164}
0 commit comments