From 1582e6f4c345eac143a580063936a5b95508178d Mon Sep 17 00:00:00 2001 From: Constantin Graf Date: Wed, 7 Oct 2026 16:53:18 +0200 Subject: [PATCH] Generate profile photo in user factory locally Faker's image() downloads the image from via.placeholder.com, which no longer exists. Since the domain resolves again but does not respond, the download (without timeout) hangs and the PHPUnit runs time out. The profile photo is now generated locally with GD, which also stores a real image instead of the temporary file path returned by image(). --- database/factories/UserFactory.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 15b3393e..29703b1d 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -91,7 +91,7 @@ class UserFactory extends Factory public function withProfilePicture(): static { - $profilePhoto = $this->faker->image(null, 500, 500); + $profilePhoto = $this->generateProfilePhoto(); /** @see FileHelpers::hashName */ $path = 'profile-photos/'.Str::random(40).'.png'; Storage::disk(config('filesystems.public'))->put($path, $profilePhoto); @@ -103,6 +103,21 @@ class UserFactory extends Factory }); } + /** + * Generates a PNG image with a random background color. + * Note: The image is generated locally, since downloading a placeholder image (Faker image()) depends on an external service. + */ + private function generateProfilePhoto(): string + { + $image = imagecreatetruecolor(500, 500); + $color = imagecolorallocate($image, $this->faker->numberBetween(0, 255), $this->faker->numberBetween(0, 255), $this->faker->numberBetween(0, 255)); + imagefill($image, 0, 0, $color); + ob_start(); + imagepng($image); + + return (string) ob_get_clean(); + } + /** * Indicate that the user should have a personal team. */