From f1e93a0ca0d1dfaf9f0c86a41da9a9462c32cf81 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 2 Sep 2022 09:56:43 +0200 Subject: [PATCH] Make the exception only about requiring a stateful guard --- src/Database/Models/ImpersonationToken.php | 4 ++-- ...TokenCouldNotBeCreatedWithNonStatefulGuard.php | 15 --------------- src/Exceptions/StatefulGuardRequiredException.php | 15 +++++++++++++++ tests/TenantUserImpersonationTest.php | 4 ++-- 4 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 src/Exceptions/ImpersonationTokenCouldNotBeCreatedWithNonStatefulGuard.php create mode 100644 src/Exceptions/StatefulGuardRequiredException.php diff --git a/src/Database/Models/ImpersonationToken.php b/src/Database/Models/ImpersonationToken.php index 71979343..88c8ee47 100644 --- a/src/Database/Models/ImpersonationToken.php +++ b/src/Database/Models/ImpersonationToken.php @@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Str; use Stancl\Tenancy\Database\Concerns\CentralConnection; -use Stancl\Tenancy\Exceptions\ImpersonationTokenCouldNotBeCreatedWithNonStatefulGuard; +use Stancl\Tenancy\Exceptions\StatefulGuardRequiredException; /** * @param string $token @@ -44,7 +44,7 @@ class ImpersonationToken extends Model $authGuard = $model->auth_guard ?? config('auth.defaults.guard'); if (! Auth::guard($authGuard) instanceof StatefulGuard) { - throw new ImpersonationTokenCouldNotBeCreatedWithNonStatefulGuard($authGuard); + throw new StatefulGuardRequiredException($authGuard); } $model->created_at = $model->created_at ?? $model->freshTimestamp(); diff --git a/src/Exceptions/ImpersonationTokenCouldNotBeCreatedWithNonStatefulGuard.php b/src/Exceptions/ImpersonationTokenCouldNotBeCreatedWithNonStatefulGuard.php deleted file mode 100644 index e6655193..00000000 --- a/src/Exceptions/ImpersonationTokenCouldNotBeCreatedWithNonStatefulGuard.php +++ /dev/null @@ -1,15 +0,0 @@ -artisan('migrate', [ @@ -257,7 +257,7 @@ test('impersonation tokens can be created only with stateful guards', function ( Auth::extend('nonstateful', fn($app, $name, array $config) => new TokenGuard(Auth::createUserProvider($config['provider']), request())); expect(fn() => tenancy()->impersonate($tenant, $user->id, '/dashboard', 'nonstateful')) - ->toThrow(ImpersonationTokenCouldNotBeCreatedWithNonStatefulGuard::class); + ->toThrow(StatefulGuardRequiredException::class); Auth::extend('stateful', fn ($app, $name, array $config) => new SessionGuard($name, Auth::createUserProvider($config['provider']), session()));