@@ -241,11 +241,22 @@ private function createModule(string $moduleName, string $template, bool $withAs
241241 private function generateUsers (): array
242242 {
243243 $ users = [];
244+ $ images = [];
245+
244246 for ($ i = 0 ; $ i < self ::COUNTS ['users ' ]; $ i ++) {
245- $ user = $ this ->generateUserData ();
247+ $ generated = $ this ->generateUserData ();
248+ $ users [] = $ generated ['data ' ];
249+ $ images [] = $ generated ['image ' ];
250+ }
251+
252+ $ imageNames = save_remote_images ($ images );
253+
254+ foreach ($ users as $ index => $ user ) {
255+ $ user ['image ' ] = $ imageNames [$ index ];
246256 $ this ->runCommandInternally (self ::COMMANDS ['user_create ' ], $ user );
247- $ users [] = $ user ;
257+ $ users [$ index ] = $ user ;
248258 }
259+
249260 return $ users ;
250261 }
251262
@@ -262,15 +273,24 @@ private function generateUsers(): array
262273 private function generatePosts (array $ users ): array
263274 {
264275 $ posts = [];
276+ $ images = [];
265277
266278 foreach ($ users as $ user ) {
267279 for ($ i = 0 ; $ i < self ::COUNTS ['posts_per_user ' ]; $ i ++) {
268- $ post = $ this ->generatePostData ($ user );
269- $ this -> runCommandInternally ( self :: COMMANDS [ ' post_create ' ], $ post ) ;
270- $ posts [] = $ post ;
280+ $ generated = $ this ->generatePostData ($ user );
281+ $ posts [] = $ generated [ ' data ' ] ;
282+ $ images [] = $ generated [ ' image ' ] ;
271283 }
272284 }
273285
286+ $ imageNames = save_remote_images ($ images );
287+
288+ foreach ($ posts as $ index => $ post ) {
289+ $ post ['image ' ] = $ imageNames [$ index ];
290+ $ this ->runCommandInternally (self ::COMMANDS ['post_create ' ], $ post );
291+ $ posts [$ index ] = $ post ;
292+ }
293+
274294 return $ posts ;
275295 }
276296
@@ -309,20 +329,21 @@ private function generateUserData(): array
309329
310330 create_user_directory ($ userUuid );
311331
312- $ imageName = save_remote_image (
313- $ this ->faker ->gravatarUrl (),
314- $ userUuid ,
315- $ email
316- );
317-
318332 return [
319- 'email ' => $ email ,
320- 'password ' => self ::DEFAULT_PASSWORD ,
321- 'firstname ' => $ this ->faker ->name (),
322- 'lastname ' => $ this ->faker ->lastName (),
323- 'uuid ' => $ userUuid ,
324- 'role ' => Role::EDITOR ,
325- 'image ' => $ imageName ,
333+ 'data ' => [
334+ 'email ' => $ email ,
335+ 'password ' => self ::DEFAULT_PASSWORD ,
336+ 'firstname ' => $ this ->faker ->name (),
337+ 'lastname ' => $ this ->faker ->lastName (),
338+ 'uuid ' => $ userUuid ,
339+ 'role ' => Role::EDITOR ,
340+ 'image ' => '' ,
341+ ],
342+ 'image ' => [
343+ 'url ' => $ this ->faker ->gravatarUrl (),
344+ 'directory ' => $ userUuid ,
345+ 'name ' => $ email ,
346+ ],
326347 ];
327348 }
328349
@@ -340,18 +361,19 @@ private function generatePostData(array $user): array
340361 $ postUuid = $ this ->faker ->uuid ();
341362 $ title = textCleanUp ($ this ->faker ->realText (50 ));
342363
343- $ imageName = save_remote_image (
344- $ this ->faker ->imageUrl (640 , 480 , true , 0 ),
345- $ user ['uuid ' ],
346- $ title
347- );
348-
349364 return [
350- 'title ' => $ title ,
351- 'description ' => textCleanUp ($ this ->faker ->realText (1000 )),
352- 'user_uuid ' => $ user ['uuid ' ],
353- 'uuid ' => $ postUuid ,
354- 'image ' => $ imageName ,
365+ 'data ' => [
366+ 'title ' => $ title ,
367+ 'description ' => textCleanUp ($ this ->faker ->realText (1000 )),
368+ 'user_uuid ' => $ user ['uuid ' ],
369+ 'uuid ' => $ postUuid ,
370+ 'image ' => '' ,
371+ ],
372+ 'image ' => [
373+ 'url ' => $ this ->faker ->imageUrl (640 , 480 , true , 0 ),
374+ 'directory ' => $ user ['uuid ' ],
375+ 'name ' => $ title ,
376+ ],
355377 ];
356378 }
357379
0 commit comments