fix(tests): inject appTitle/appUrl into auth services to avoid DB calls in unit tests
This commit is contained in:
@@ -19,10 +19,25 @@ class EmailVerificationService
|
||||
private readonly UserReadRepositoryInterface $userReadRepository,
|
||||
private readonly UserWriteRepositoryInterface $userWriteRepository,
|
||||
private readonly EmailVerificationRepositoryInterface $emailVerificationRepository,
|
||||
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 sendVerification(int $userId, ?string $locale = null): array
|
||||
{
|
||||
$user = $this->userReadRepository->find($userId);
|
||||
@@ -55,17 +70,17 @@ class EmailVerificationService
|
||||
}
|
||||
$greeting .= ',';
|
||||
$verifyPath = Request::withLocale('verify-email', $locale);
|
||||
$verifyUrl = appUrl($verifyPath);
|
||||
$verifyUrl = $this->resolveAppUrl($verifyPath);
|
||||
$previousLocale = I18n::$locale ?? null;
|
||||
I18n::$locale = $locale;
|
||||
$subject = t('Email verification 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,
|
||||
|
||||
Reference in New Issue
Block a user