fix(tests): inject appTitle/appUrl into auth services to avoid DB calls in unit tests
This commit is contained in:
@@ -59,7 +59,9 @@ class AuthServicesFactory
|
||||
$this->authRepositoryFactory->createPasswordResetRepository(),
|
||||
$this->userServicesFactory->createUserPasswordService(),
|
||||
$this->createRememberMeService(),
|
||||
$this->mailServicesFactory->createMailService()
|
||||
$this->mailServicesFactory->createMailService(),
|
||||
appTitle(),
|
||||
appUrl(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,7 +71,9 @@ class AuthServicesFactory
|
||||
$this->userServicesFactory->createUserReadRepository(),
|
||||
$this->userServicesFactory->createUserWriteRepository(),
|
||||
$this->authRepositoryFactory->createEmailVerificationRepository(),
|
||||
$this->mailServicesFactory->createMailService()
|
||||
$this->mailServicesFactory->createMailService(),
|
||||
appTitle(),
|
||||
appUrl(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user