From ae25e25715c86c74f4cc8f2b57c9667e60ec31f0 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 25 Apr 2023 12:33:29 +0200 Subject: [PATCH] Fix job & test --- src/Jobs/CreatePostgresUserForTenant.php | 2 +- tests/PostgresTest.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Jobs/CreatePostgresUserForTenant.php b/src/Jobs/CreatePostgresUserForTenant.php index 80ad9e52..ebe87dc9 100644 --- a/src/Jobs/CreatePostgresUserForTenant.php +++ b/src/Jobs/CreatePostgresUserForTenant.php @@ -38,7 +38,7 @@ class CreatePostgresUserForTenant implements ShouldQueue $password = $this->tenant->database()->getPassword() ?? 'password'; // Create the user only if it doesn't already exist - if (count(DB::select("SELECT usename FROM pg_user WHERE usename = '$name';")) > 0) { + if (! count(DB::select("SELECT usename FROM pg_user WHERE usename = '$name';")) > 0) { DB::statement("CREATE USER \"$name\" LOGIN PASSWORD '$password';"); } } diff --git a/tests/PostgresTest.php b/tests/PostgresTest.php index 74d16608..3684759d 100644 --- a/tests/PostgresTest.php +++ b/tests/PostgresTest.php @@ -15,13 +15,13 @@ test('postgres user can get created using the job', function() { $tenant = Tenant::create(); $name = $tenant->getTenantKey(); - $tenantHasPostgresUser = count(DB::select("SELECT usename FROM pg_user WHERE usename = '$name';")) > 0; + $tenantHasPostgresUser = fn () => count(DB::select("SELECT usename FROM pg_user WHERE usename = '$name';")) > 0; - expect($tenantHasPostgresUser)->toBeFalse(); + expect($tenantHasPostgresUser())->toBeFalse(); CreatePostgresUserForTenant::dispatchSync($tenant); - expect($tenantHasPostgresUser)->toBeTrue(); + expect($tenantHasPostgresUser())->toBeTrue(); }); @@ -30,13 +30,13 @@ test('postgres user can get deleted using the job', function() { $name = $tenant->getTenantKey(); CreatePostgresUserForTenant::dispatchSync($tenant); - $tenantHasPostgresUser = count(DB::select("SELECT usename FROM pg_user WHERE usename = '$name';")) > 0; + $tenantHasPostgresUser = fn () => count(DB::select("SELECT usename FROM pg_user WHERE usename = '$name';")) > 0; - expect($tenantHasPostgresUser)->toBeTrue(); + expect($tenantHasPostgresUser())->toBeTrue(); DeleteTenantsPostgresUser::dispatchSync($tenant); - expect($tenantHasPostgresUser)->toBeFalse(); + expect($tenantHasPostgresUser())->toBeFalse(); }); test('correct rls policies get created using the command', function() {