fix(tests): inject appTitle/appUrl into auth services to avoid DB calls in unit tests

This commit is contained in:
aminovfariz
2026-06-05 14:21:04 +02:00
parent 3f08f6189e
commit c12d155e23
3 changed files with 46 additions and 12 deletions

View File

@@ -20,10 +20,25 @@ class PasswordResetService
private readonly PasswordResetRepositoryInterface $passwordResetRepository,
private readonly UserPasswordService $userPasswordService,
private readonly RememberMeService $rememberMeService,
private readonly MailService $mailService
private readonly MailService $mailService,
private readonly string $appTitle = '',
private readonly string $appUrl = '',
) {
}
private function resolveAppTitle(): string
{
return $this->appTitle !== '' ? $this->appTitle : appTitle();
}
private function resolveAppUrl(string $path = ''): string
{
if ($this->appUrl !== '') {
return rtrim($this->appUrl, '/') . ($path !== '' ? '/' . ltrim($path, '/') : '');
}
return appUrl($path);
}
public function requestReset(string $email, ?string $locale = null): array
{
$email = trim($email);
@@ -58,17 +73,17 @@ class PasswordResetService
}
$greeting .= ',';
$verifyPath = Request::withLocale('password/verify', $locale);
$verifyUrl = appUrl($verifyPath);
$verifyUrl = $this->resolveAppUrl($verifyPath);
$previousLocale = I18n::$locale ?? null;
I18n::$locale = $locale;
$subject = t('Password reset code');
I18n::$locale = $previousLocale;
$vars = [
'app_name' => appTitle(),
'app_name' => $this->resolveAppTitle(),
'app_logo_url' => appLogoUrlAbsolute(128),
'imprint_url' => appUrl(Request::withLocale('imprint', $locale)),
'privacy_url' => appUrl(Request::withLocale('privacy', $locale)),
'imprint_url' => $this->resolveAppUrl(Request::withLocale('imprint', $locale)),
'privacy_url' => $this->resolveAppUrl(Request::withLocale('privacy', $locale)),
'code' => $code,
'expires_minutes' => self::EXPIRY_MINUTES,
'verify_url' => $verifyUrl,