diff --git a/src/Commands/ClearExpiredImpersonationTokens.php b/src/Commands/ClearExpiredImpersonationTokens.php index a8c608ee..1327cad6 100644 --- a/src/Commands/ClearExpiredImpersonationTokens.php +++ b/src/Commands/ClearExpiredImpersonationTokens.php @@ -8,20 +8,15 @@ use Illuminate\Console\Command; use Stancl\Tenancy\Features\UserImpersonation; /** - * This command clears impersonation tokens. - * By default, only expired tokens (= tokens older than 60s, which is the UserImpersonation::$ttl default) are deleted. + * Clears expired impersonation tokens. * - * To override the default behavior, e.g. to clear all tokens newer than 60s, - * you can pass the seconds in the --ttl option. - * - * For example, `tenants:clear-expired-impersonation-tokens --ttl=30` will clear all tokens older than 30 seconds, ignoring the default. + * Tokens older than UserImpersonation::$ttl (60 seconds by default) are considered expired. * * @see Stancl\Tenancy\Features\UserImpersonation */ class ClearExpiredImpersonationTokens extends Command { - protected $signature = 'tenants:clear-expired-impersonation-tokens - {--ttl= : TTL in seconds for impersonation tokens (default is UserImpersonation::$ttl)}'; + protected $signature = 'tenants:clear-expired-impersonation-tokens'; protected $description = 'Clear expired impersonation tokens.'; @@ -29,8 +24,7 @@ class ClearExpiredImpersonationTokens extends Command { $this->components->info('Deleting expired impersonation tokens.'); - $ttl = (int) $this->option('ttl') ?: UserImpersonation::$ttl; - $expirationDate = now()->subSeconds($ttl); + $expirationDate = now()->subSeconds(UserImpersonation::$ttl); $impersonationTokenModel = UserImpersonation::modelClass(); diff --git a/tests/TenantUserImpersonationTest.php b/tests/TenantUserImpersonationTest.php index 134cefa6..a7db662b 100644 --- a/tests/TenantUserImpersonationTest.php +++ b/tests/TenantUserImpersonationTest.php @@ -397,23 +397,13 @@ test('expired impersonation tokens can be cleaned up using a command', function 'created_at' => Carbon::now()->subSeconds(70), ]); - // The --ttl option can be used to specify a custom TTL instead of updating UserImpersonation::$ttl. - // The passed ttl will be used in place of the default ttl, - // and with ttl set to 80s, the active token should not be deleted - pest()->artisan('tenants:clear-expired-impersonation-tokens', [ - '--ttl' => 80, - ])->assertExitCode(0) + // With ttl set to 80s, the active token should not be deleted (token is only considered expired if older than 80s) + UserImpersonation::$ttl = 80; + pest()->artisan('tenants:clear-expired-impersonation-tokens') + ->assertExitCode(0) ->expectsOutputToContain('0 expired impersonation tokens deleted'); expect(ImpersonationToken::find($activeToken->token))->not()->toBeNull(); - - // With ttl set to 40s, the active token should be deleted - pest()->artisan('tenants:clear-expired-impersonation-tokens', [ - '--ttl' => 40, - ])->assertExitCode(0) - ->expectsOutputToContain('1 expired impersonation token deleted'); - - expect(ImpersonationToken::find($activeToken->token))->toBeNull(); }); function migrateTenants()