+
+ public function test_exception_message_on_failed_fetch()
+ {
+ // set wrong url
+ config()->set([
+ 'services.disable_services' => false,
+ 'services.avatar_url' => 'http_malformed_url/${email}/${hash}/${size}',
+ ]);
+
+ $user = User::factory()->make();
+ $avatar = app()->make(UserAvatars::class);
+ $logger = $this->withTestLogger();
+ $this->mockHttpClient([new ConnectException('Could not resolve host http_malformed_url', new Request('GET', ''))]);
+
+ $avatar->fetchAndAssignToUser($user);
+
+ $url = 'http_malformed_url/' . urlencode(strtolower($user->email)) . '/' . md5(strtolower($user->email)) . '/500';
+ $this->assertTrue($logger->hasError('Failed to save user avatar image'));
+ $exception = $logger->getRecords()[0]['context']['exception'];
+ $this->assertInstanceOf(HttpFetchException::class, $exception);
+ $this->assertEquals('Cannot get image from ' . $url, $exception->getMessage());
+ $this->assertEquals('Could not resolve host http_malformed_url', $exception->getPrevious()->getMessage());
+ }