From b4d79c573faeb894895c650d6c1870e77d92c241 Mon Sep 17 00:00:00 2001 From: David Pashaev Date: Mon, 22 Apr 2024 23:01:35 +0200 Subject: [PATCH 1/9] allow to disable signup --- .env.example | 4 ++ app/Helpers/SignupHelper.php | 33 ++++++++++++ app/Http/Controllers/Auth/LoginController.php | 9 ++++ app/Http/Middleware/EnsureSignupIsEnabled.php | 32 +++++++++++ app/Providers/FortifyServiceProvider.php | 23 +++++++- bootstrap/app.php | 2 + config/monica.php | 10 ++++ lang/en/auth.php | 1 + resources/js/Pages/Auth/Login.vue | 3 +- tests/Feature/Auth/RegistrationTest.php | 50 +++++++++++------ tests/PHPUnit/Helpers/SignupHelperTest.php | 53 +++++++++++++++++++ 11 files changed, 203 insertions(+), 17 deletions(-) create mode 100644 app/Helpers/SignupHelper.php create mode 100644 app/Http/Middleware/EnsureSignupIsEnabled.php create mode 100644 tests/PHPUnit/Helpers/SignupHelperTest.php diff --git a/.env.example b/.env.example index 4040b53090e..5f38afa03df 100644 --- a/.env.example +++ b/.env.example @@ -26,6 +26,10 @@ APP_DEBUG=true # The URL of your application. APP_URL=http://localhost:8000 +# Ability to disable signups on your instance. +# Can be true or false. Default to false. +APP_DISABLE_SIGNUP=false + # Database to store information # The documentation is here: https://laravel.com/docs/10.x/database # You can also see the different values you can use in config/database.php diff --git a/app/Helpers/SignupHelper.php b/app/Helpers/SignupHelper.php new file mode 100644 index 00000000000..0504362cfee --- /dev/null +++ b/app/Helpers/SignupHelper.php @@ -0,0 +1,33 @@ +configRepository = $configRepository; + } + + public function isEnabled(): bool + { + return !($this->isDisabledByConfig() && $this->hasAtLeastOneAccount()); + } + + protected function isDisabledByConfig(): bool + { + return (bool) $this->configRepository->get('monica.disable_signup'); + } + + protected function hasAtLeastOneAccount(): bool + { + return !empty(Account::first()); + } +} diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 26f775f9fc2..a1cab56495d 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Auth; +use App\Helpers\SignupHelper; use App\Helpers\WallpaperHelper; use App\Http\Controllers\Controller; use App\Models\User; @@ -14,6 +15,13 @@ class LoginController extends Controller { + protected SignupHelper $signupHelper; + + public function __construct(SignupHelper $signupHelper) + { + $this->signupHelper = $signupHelper; + } + /** * Display the login view. */ @@ -40,6 +48,7 @@ public function __invoke(Request $request): Response } return Inertia::render('Auth/Login', $data + [ + 'isSignupEnabled' => $this->signupHelper->isEnabled(), 'canResetPassword' => Route::has('password.request'), 'status' => session('status'), 'wallpaperUrl' => WallpaperHelper::getRandomWallpaper(), diff --git a/app/Http/Middleware/EnsureSignupIsEnabled.php b/app/Http/Middleware/EnsureSignupIsEnabled.php new file mode 100644 index 00000000000..6c2a35890ba --- /dev/null +++ b/app/Http/Middleware/EnsureSignupIsEnabled.php @@ -0,0 +1,32 @@ +signupHelper = $signupHelper; + $this->translator = $translator; + } + + public function handle(Request $request, Closure $next): Response + { + if (!$this->signupHelper->isEnabled()) { + abort(Response::HTTP_FORBIDDEN, $this->translator->get('auth.signup_disabled')); + } + + return $next($request); + } +} diff --git a/app/Providers/FortifyServiceProvider.php b/app/Providers/FortifyServiceProvider.php index f48783deef0..559a77c72e0 100644 --- a/app/Providers/FortifyServiceProvider.php +++ b/app/Providers/FortifyServiceProvider.php @@ -11,9 +11,11 @@ use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Contracts\Auth\StatefulGuard; use Illuminate\Http\Request; +use Illuminate\Routing\Router; use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\ServiceProvider; use Laravel\Fortify\Fortify; +use Laravel\Fortify\Http\Controllers\RegisteredUserController; class FortifyServiceProvider extends ServiceProvider { @@ -34,7 +36,11 @@ public function register() */ public function boot() { - Fortify::loginView(fn ($request) => (new LoginController())($request)); + $this->patchRoutes(); + + $loginController = $this->app->make(LoginController::class); + + Fortify::loginView(fn ($request) => $loginController($request)); Fortify::confirmPasswordsUsing(fn ($user, ?string $password = null) => $user->password ? app(StatefulGuard::class)->validate([ 'email' => $user->email, @@ -57,4 +63,19 @@ public function boot() RateLimiter::for('two-factor', fn (Request $request) => Limit::perMinute(5)->by($request->session()->get('login.id'))); } + + protected function patchRoutes(): void + { + if ($this->app->routesAreCached()) { + return; + } + + $router = $this->app->make(Router::class); + $routes = $router->getRoutes(); + collect(['create', 'store'])->each(function ($method) use ($routes) { + if ($route = $routes->getByAction(RegisteredUserController::class . '@' . $method)) { + $route->middleware('monica.signup_is_enabled'); + } + }); + } } diff --git a/bootstrap/app.php b/bootstrap/app.php index 52fa54e0634..bb770561633 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -1,5 +1,6 @@ CheckAbilities::class, 'ability' => CheckForAnyAbility::class, 'webauthn' => WebauthnMiddleware::class, + 'monica.signup_is_enabled' => EnsureSignupIsEnabled::class, ]); $middleware->web(remove: [ \Illuminate\Routing\Middleware\SubstituteBindings::class, diff --git a/config/monica.php b/config/monica.php index 479ecf2b2ee..451ea3edb56 100644 --- a/config/monica.php +++ b/config/monica.php @@ -13,6 +13,16 @@ 'app_version' => readVersion(__DIR__.'/.version', 'git describe --abbrev=0 --tags', '0.0.0'), + /* + |-------------------------------------------------------------------------- + | Disable User registration + |-------------------------------------------------------------------------- + | + | Disables registration of new users + | + */ + 'disable_signup' => env('APP_DISABLE_SIGNUP', false), + /* |-------------------------------------------------------------------------- | Commit hash of the application diff --git a/lang/en/auth.php b/lang/en/auth.php index 5970c201c32..7c77387a76c 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -4,6 +4,7 @@ return [ 'failed' => 'These credentials do not match our records.', + 'signup_disabled' => 'Registration is currently disabled', 'lang' => 'English', 'login_provider_azure' => 'Microsoft', 'login_provider_facebook' => 'Facebook', diff --git a/resources/js/Pages/Auth/Login.vue b/resources/js/Pages/Auth/Login.vue index b7203b39a00..8f9d5e14eaa 100644 --- a/resources/js/Pages/Auth/Login.vue +++ b/resources/js/Pages/Auth/Login.vue @@ -11,6 +11,7 @@ import WebauthnLogin from '@/Pages/Webauthn/WebauthnLogin.vue'; import AuthenticationCardLogo from '@/Components/AuthenticationCardLogo.vue'; const props = defineProps({ + isSignupEnabled: Boolean, canResetPassword: Boolean, status: String, wallpaperUrl: String, @@ -195,7 +196,7 @@ const reload = () => { -
+
{{ $t('New to Monica?') }} {{ $t('Create an account') }} diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 83f3bea2293..2a4e5ba33f4 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -1,47 +1,67 @@ withoutVite(); - if (! Features::enabled(Features::registration())) { - return $this->markTestSkipped('Registration support is not enabled.'); - } + $isSignupEnabled = null; + $this->app->bind(SignupHelper::class, function () use (&$isSignupEnabled) { + $mock = Mockery::mock(SignupHelper::class)->makePartial(); + $mock->shouldReceive('isEnabled')->andReturn($isSignupEnabled); + return $mock; + }); + $isSignupEnabled = true; $response = $this->get('/register'); + $response->assertStatus(Response::HTTP_OK); - $response->assertStatus(200); + $isSignupEnabled = false; + $response = $this->get('/register'); + $response->assertStatus(Response::HTTP_FORBIDDEN); + $response->assertSeeText('Registration is currently disabled'); } - #[Test] - public function new_users_can_register() + public function testRegistration(): void { - if (! Features::enabled(Features::registration())) { - return $this->markTestSkipped('Registration support is not enabled.'); - } + $isSignupEnabled = null; + $this->app->bind(SignupHelper::class, function () use (&$isSignupEnabled) { + $mock = Mockery::mock(SignupHelper::class)->makePartial(); + $mock->shouldReceive('isEnabled')->andReturn($isSignupEnabled); + return $mock; + }); - $response = $this->post('/register', [ + $data = [ 'first_name' => 'Test', 'last_name' => 'User', 'email' => 'test@example.com', 'password' => 'Password$123', 'password_confirmation' => 'Password$123', 'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(), - ]); + ]; + + $isSignupEnabled = false; + $response = $this->post('/register', $data); + $response->assertStatus(Response::HTTP_FORBIDDEN); + $response->assertSeeText('Registration is currently disabled'); + $isSignupEnabled = true; + $response = $this->post('/register', $data); + $response->assertStatus(Response::HTTP_OK); $this->assertAuthenticated(); $response->assertRedirect('/vaults'); } diff --git a/tests/PHPUnit/Helpers/SignupHelperTest.php b/tests/PHPUnit/Helpers/SignupHelperTest.php new file mode 100644 index 00000000000..0a0ef84fc76 --- /dev/null +++ b/tests/PHPUnit/Helpers/SignupHelperTest.php @@ -0,0 +1,53 @@ +shouldAllowMockingProtectedMethods()->makePartial(); + $helper->shouldReceive('isDisabledByConfig')->andReturn($isSignupDisabled); + $helper->shouldReceive('hasAtLeastOneAccount')->andReturn($hasAtLeastOneAccount); + + $this->assertEquals($expectedResult, $helper->isEnabled()); + } + + public function isEnabledDataProvider(): iterable + { + // $isSignupDisabled, $hasAtLeastOneAccount, $expectedResult + return [ + [true, true, false], + [true, false, true], + [false, true, true], + [false, false, true], + ]; + } + + public function testIsDisabledByConfig(): void + { + $configRepository = Mockery::mock(ConfigRepository::class)->makePartial(); + $configRepository->shouldReceive('get') + ->once() + ->withArgs(function ($name) { + return $name === 'monica.disable_signup'; + }) + ->andReturnTrue(); + + $helper = Mockery::mock(SignupHelper::class, [$configRepository])->makePartial(); + $helper->isDisabledByConfig(); + } +} From 74854eeeb4c891da605ee6ed9f54253c77e61070 Mon Sep 17 00:00:00 2001 From: David Pashaev Date: Thu, 2 May 2024 16:42:58 +0200 Subject: [PATCH 2/9] add PHPUnit to test suit --- phpunit.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml b/phpunit.xml index 6b6569e6a78..f71dc25f770 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,6 +8,7 @@ ./tests/Feature ./tests/Unit + ./tests/PHPUnit From 5be941b97c60ba485466320cee26116df4326625 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 4 May 2024 18:12:18 +0800 Subject: [PATCH 3/9] Update app/Helpers/SignupHelper.php Co-authored-by: Alexis Saettler --- app/Helpers/SignupHelper.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/Helpers/SignupHelper.php b/app/Helpers/SignupHelper.php index 0504362cfee..8773e1c93ef 100644 --- a/app/Helpers/SignupHelper.php +++ b/app/Helpers/SignupHelper.php @@ -5,16 +5,14 @@ namespace App\Helpers; use App\Models\Account; -use Illuminate\Contracts\Config\Repository as ConfigRepository; +use Illuminate\Contracts\Config\Repository as Config; class SignupHelper { - protected ConfigRepository $configRepository; - - public function __construct(ConfigRepository $configRepository) - { - $this->configRepository = $configRepository; - } + public function __construct( + protected Config $config + ) + { } public function isEnabled(): bool { @@ -23,7 +21,7 @@ public function isEnabled(): bool protected function isDisabledByConfig(): bool { - return (bool) $this->configRepository->get('monica.disable_signup'); + return (bool) $this->config->get('monica.disable_signup'); } protected function hasAtLeastOneAccount(): bool From bdd4a66300fc3ece0c01e61706a3c838b1f9232c Mon Sep 17 00:00:00 2001 From: David Date: Sat, 4 May 2024 18:12:47 +0800 Subject: [PATCH 4/9] Update app/Http/Controllers/Auth/LoginController.php Co-authored-by: Alexis Saettler --- app/Http/Controllers/Auth/LoginController.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index a1cab56495d..58a7aebd629 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -15,12 +15,10 @@ class LoginController extends Controller { - protected SignupHelper $signupHelper; - - public function __construct(SignupHelper $signupHelper) - { - $this->signupHelper = $signupHelper; - } + public function __construct( + protected SignupHelper $signupHelper + ) + { } /** * Display the login view. From 9fe936f3a3f6d243084b4cfcfb90e776e48bba33 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 4 May 2024 18:13:19 +0800 Subject: [PATCH 5/9] Update app/Http/Middleware/EnsureSignupIsEnabled.php Co-authored-by: Alexis Saettler --- app/Http/Middleware/EnsureSignupIsEnabled.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/Http/Middleware/EnsureSignupIsEnabled.php b/app/Http/Middleware/EnsureSignupIsEnabled.php index 6c2a35890ba..4f767ac236a 100644 --- a/app/Http/Middleware/EnsureSignupIsEnabled.php +++ b/app/Http/Middleware/EnsureSignupIsEnabled.php @@ -12,14 +12,11 @@ class EnsureSignupIsEnabled { - protected SignupHelper $signupHelper; - protected Translator $translator; - - public function __construct(SignupHelper $signupHelper, Translator $translator) - { - $this->signupHelper = $signupHelper; - $this->translator = $translator; - } + public function __construct( + protected SignupHelper $signupHelper, + protected Translator $translator + ) + { } public function handle(Request $request, Closure $next): Response { From e9a45210831956aad5ed7232cf50967a9d70a94a Mon Sep 17 00:00:00 2001 From: David Date: Sat, 4 May 2024 22:08:49 +0800 Subject: [PATCH 6/9] Update app/Http/Middleware/EnsureSignupIsEnabled.php Co-authored-by: Alexis Saettler --- app/Http/Middleware/EnsureSignupIsEnabled.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Http/Middleware/EnsureSignupIsEnabled.php b/app/Http/Middleware/EnsureSignupIsEnabled.php index 4f767ac236a..e5c9bbe11dd 100644 --- a/app/Http/Middleware/EnsureSignupIsEnabled.php +++ b/app/Http/Middleware/EnsureSignupIsEnabled.php @@ -20,9 +20,7 @@ public function __construct( public function handle(Request $request, Closure $next): Response { - if (!$this->signupHelper->isEnabled()) { - abort(Response::HTTP_FORBIDDEN, $this->translator->get('auth.signup_disabled')); - } + abort_if(! $this->signupHelper->isEnabled(), 403, trans('Registration is currently disabled')); return $next($request); } From 3bdd89d11dc2ffbe8320ff5c7acb2fdcc196baa5 Mon Sep 17 00:00:00 2001 From: David Pashaev Date: Wed, 8 May 2024 09:09:21 +0200 Subject: [PATCH 7/9] move phpunit test to unit folder --- phpunit.xml | 1 - tests/{PHPUnit => Unit}/Helpers/SignupHelperTest.php | 7 ++----- 2 files changed, 2 insertions(+), 6 deletions(-) rename tests/{PHPUnit => Unit}/Helpers/SignupHelperTest.php (91%) diff --git a/phpunit.xml b/phpunit.xml index f71dc25f770..6b6569e6a78 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,6 @@ ./tests/Feature ./tests/Unit - ./tests/PHPUnit diff --git a/tests/PHPUnit/Helpers/SignupHelperTest.php b/tests/Unit/Helpers/SignupHelperTest.php similarity index 91% rename from tests/PHPUnit/Helpers/SignupHelperTest.php rename to tests/Unit/Helpers/SignupHelperTest.php index 0a0ef84fc76..85d3511b443 100644 --- a/tests/PHPUnit/Helpers/SignupHelperTest.php +++ b/tests/Unit/Helpers/SignupHelperTest.php @@ -2,20 +2,17 @@ declare(strict_types=1); -namespace Tests\PHPUnit\Helpers; +namespace Tests\Unit\Helpers; use App\Helpers\SignupHelper; use Illuminate\Contracts\Config\Repository as ConfigRepository; use Mockery; -use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; #[CoversClass(SignupHelper::class)] class SignupHelperTest extends TestCase { - use MockeryPHPUnitIntegration; - #[DataProvider('isEnabledDataProvider')] public function testIsEnabled(bool $isSignupDisabled, bool $hasAtLeastOneAccount, bool $expectedResult): void { From 500aaf71e1baca250a24fb3561170c991a3d1923 Mon Sep 17 00:00:00 2001 From: David Pashaev Date: Wed, 8 May 2024 09:17:08 +0200 Subject: [PATCH 8/9] fixes --- app/Http/Middleware/EnsureSignupIsEnabled.php | 4 +--- lang/en/auth.php | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/Http/Middleware/EnsureSignupIsEnabled.php b/app/Http/Middleware/EnsureSignupIsEnabled.php index e5c9bbe11dd..25445a4060b 100644 --- a/app/Http/Middleware/EnsureSignupIsEnabled.php +++ b/app/Http/Middleware/EnsureSignupIsEnabled.php @@ -6,7 +6,6 @@ use App\Helpers\SignupHelper; use Closure; -use Illuminate\Contracts\Translation\Translator; use Illuminate\Http\Request; use Symfony\Component\HttpFoundation\Response; @@ -14,13 +13,12 @@ class EnsureSignupIsEnabled { public function __construct( protected SignupHelper $signupHelper, - protected Translator $translator ) { } public function handle(Request $request, Closure $next): Response { - abort_if(! $this->signupHelper->isEnabled(), 403, trans('Registration is currently disabled')); + abort_if(!$this->signupHelper->isEnabled(), 403, trans('Registration is currently disabled')); return $next($request); } diff --git a/lang/en/auth.php b/lang/en/auth.php index 7c77387a76c..5970c201c32 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -4,7 +4,6 @@ return [ 'failed' => 'These credentials do not match our records.', - 'signup_disabled' => 'Registration is currently disabled', 'lang' => 'English', 'login_provider_azure' => 'Microsoft', 'login_provider_facebook' => 'Facebook', From adbadab367aaf46d1104a5e3d36f2306b7d1633a Mon Sep 17 00:00:00 2001 From: David Pashaev Date: Wed, 8 May 2024 09:44:23 +0200 Subject: [PATCH 9/9] fixes for test and cs --- app/Helpers/SignupHelper.php | 8 ++++---- app/Http/Controllers/Auth/LoginController.php | 4 ++-- app/Http/Middleware/EnsureSignupIsEnabled.php | 6 +++--- app/Providers/FortifyServiceProvider.php | 2 +- tests/Feature/Auth/RegistrationTest.php | 3 ++- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/Helpers/SignupHelper.php b/app/Helpers/SignupHelper.php index 8773e1c93ef..244bbd506a7 100644 --- a/app/Helpers/SignupHelper.php +++ b/app/Helpers/SignupHelper.php @@ -11,12 +11,12 @@ class SignupHelper { public function __construct( protected Config $config - ) - { } + ) { + } public function isEnabled(): bool { - return !($this->isDisabledByConfig() && $this->hasAtLeastOneAccount()); + return ! ($this->isDisabledByConfig() && $this->hasAtLeastOneAccount()); } protected function isDisabledByConfig(): bool @@ -26,6 +26,6 @@ protected function isDisabledByConfig(): bool protected function hasAtLeastOneAccount(): bool { - return !empty(Account::first()); + return ! empty(Account::first()); } } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 58a7aebd629..6b3debe559c 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -17,8 +17,8 @@ class LoginController extends Controller { public function __construct( protected SignupHelper $signupHelper - ) - { } + ) { + } /** * Display the login view. diff --git a/app/Http/Middleware/EnsureSignupIsEnabled.php b/app/Http/Middleware/EnsureSignupIsEnabled.php index 25445a4060b..68710708c47 100644 --- a/app/Http/Middleware/EnsureSignupIsEnabled.php +++ b/app/Http/Middleware/EnsureSignupIsEnabled.php @@ -13,12 +13,12 @@ class EnsureSignupIsEnabled { public function __construct( protected SignupHelper $signupHelper, - ) - { } + ) { + } public function handle(Request $request, Closure $next): Response { - abort_if(!$this->signupHelper->isEnabled(), 403, trans('Registration is currently disabled')); + abort_if(! $this->signupHelper->isEnabled(), 403, trans('Registration is currently disabled')); return $next($request); } diff --git a/app/Providers/FortifyServiceProvider.php b/app/Providers/FortifyServiceProvider.php index 559a77c72e0..6fb371ea636 100644 --- a/app/Providers/FortifyServiceProvider.php +++ b/app/Providers/FortifyServiceProvider.php @@ -73,7 +73,7 @@ protected function patchRoutes(): void $router = $this->app->make(Router::class); $routes = $router->getRoutes(); collect(['create', 'store'])->each(function ($method) use ($routes) { - if ($route = $routes->getByAction(RegisteredUserController::class . '@' . $method)) { + if ($route = $routes->getByAction(RegisteredUserController::class.'@'.$method)) { $route->middleware('monica.signup_is_enabled'); } }); diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 2a4e5ba33f4..c28c5e0f739 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -23,6 +23,7 @@ public function testAccessToRegistrationPage(): void $this->app->bind(SignupHelper::class, function () use (&$isSignupEnabled) { $mock = Mockery::mock(SignupHelper::class)->makePartial(); $mock->shouldReceive('isEnabled')->andReturn($isSignupEnabled); + return $mock; }); @@ -42,6 +43,7 @@ public function testRegistration(): void $this->app->bind(SignupHelper::class, function () use (&$isSignupEnabled) { $mock = Mockery::mock(SignupHelper::class)->makePartial(); $mock->shouldReceive('isEnabled')->andReturn($isSignupEnabled); + return $mock; }); @@ -61,7 +63,6 @@ public function testRegistration(): void $isSignupEnabled = true; $response = $this->post('/register', $data); - $response->assertStatus(Response::HTTP_OK); $this->assertAuthenticated(); $response->assertRedirect('/vaults'); }