浏览代码

Set SettingService behind a Facade

Bubka 3 年之前
父节点
当前提交
f7ac1e96c3

+ 7 - 25
app/Api/v1/Controllers/SettingController.php

@@ -2,9 +2,7 @@
 
 namespace App\Api\v1\Controllers;
 
-use App\Exceptions\DbEncryptionException;
-use App\Services\DbEncryptionService;
-use App\Services\SettingService;
+use App\Facades\Settings;
 use App\Api\v1\Requests\SettingStoreRequest;
 use App\Api\v1\Requests\SettingUpdateRequest;
 use App\Http\Controllers\Controller;
@@ -12,22 +10,6 @@ use App\Http\Controllers\Controller;
 
 class SettingController extends Controller
 {
-
-    /**
-     * The Settings Service instance.
-     */
-    protected SettingService $settingService;
-
-
-    /**
-     * Create a new controller instance.
-     */
-    public function __construct(SettingService $settingService)
-    {
-        $this->settingService = $settingService;
-    }
-
-
     /**
      * List all settings
      * 
@@ -35,7 +17,7 @@ class SettingController extends Controller
      */
     public function index()
     {
-        $settings = $this->settingService->all();
+        $settings = Settings::all();
         $settingsResources = collect();
         $settings->each(function ($item, $key) use ($settingsResources) {
             $settingsResources->push([
@@ -57,7 +39,7 @@ class SettingController extends Controller
      */
     public function show($settingName)
     {
-        $setting = $this->settingService->get($settingName);
+        $setting = Settings::get($settingName);
 
         if (is_null($setting)) {
             abort(404);
@@ -80,7 +62,7 @@ class SettingController extends Controller
     {
         $validated = $request->validated();
 
-        $this->settingService->set($validated['key'], $validated['value']);
+        Settings::set($validated['key'], $validated['value']);
 
         return response()->json([
             'key' => $validated['key'],
@@ -99,7 +81,7 @@ class SettingController extends Controller
     {
         $validated = $request->validated();
 
-        $this->settingService->set($settingName, $validated['value']);
+        Settings::set($settingName, $validated['value']);
 
         return response()->json([
             'key' => $settingName,
@@ -117,7 +99,7 @@ class SettingController extends Controller
      */
     public function destroy($settingName)
     {
-        $setting = $this->settingService->get($settingName);
+        $setting = Settings::get($settingName);
 
         if (is_null($setting)) {
             abort(404);
@@ -131,7 +113,7 @@ class SettingController extends Controller
             ], 400);
         }
 
-        $this->settingService->delete($settingName);
+        Settings::delete($settingName);
 
         return response()->json(null, 204);
     }

+ 2 - 2
app/Extensions/EloquentTwoFAuthProvider.php

@@ -6,7 +6,7 @@ use DarkGhostHunter\Larapass\Auth\EloquentWebAuthnProvider;
 use DarkGhostHunter\Larapass\WebAuthn\WebAuthnAssertValidator;
 use Illuminate\Contracts\Config\Repository as ConfigContract;
 use Illuminate\Contracts\Hashing\Hasher as HasherContract;
-use Facades\App\Services\SettingService;
+use App\Facades\Settings;
 
 class EloquentTwoFAuthProvider extends EloquentWebAuthnProvider
 {
@@ -26,6 +26,6 @@ class EloquentTwoFAuthProvider extends EloquentWebAuthnProvider
     ) {
         parent::__construct($config, $validator, $hasher, $model);
 
-        $this->fallback = !SettingService::get('useWebauthnOnly');
+        $this->fallback = !Settings::get('useWebauthnOnly');
     }
 }

+ 14 - 0
app/Facades/Settings.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Facades;
+
+use App\Services\SettingService;
+use Illuminate\Support\Facades\Facade;
+
+class Settings extends Facade
+{
+    protected static function getFacadeAccessor()
+    {
+        return SettingService::class;
+    }
+}

+ 2 - 17
app/Http/Controllers/SinglePageController.php

@@ -2,27 +2,12 @@
 
 namespace App\Http\Controllers;
 
-use App\Services\SettingService;
+use App\Facades\Settings;
 use Illuminate\Support\Facades\App;
 
 class SinglePageController extends Controller
 {
 
-    /**
-     * The Settings Service instance.
-     */
-    protected SettingService $settingService;
-
-
-    /**
-     * Create a new controller instance.
-     * 
-     */
-    public function __construct(SettingService $settingService)
-    {
-        $this->settingService = $settingService;
-    }
-
 
     /**
      * return the main view
@@ -31,7 +16,7 @@ class SinglePageController extends Controller
     public function index()
     {
         return view('landing')->with([
-            'appSettings' => $this->settingService->all()->toJson(),
+            'appSettings' => Settings::all()->toJson(),
             'appConfig' => collect([
                 'proxyAuth' => config("auth.defaults.guard") === 'reverse-proxy-guard' ? true : false,
                 'proxyLogoutUrl' => config("2fauth.config.proxyLogoutUrl") ? config("2fauth.config.proxyLogoutUrl") : false,

+ 2 - 17
app/Http/Controllers/SystemController.php

@@ -3,27 +3,12 @@
 namespace App\Http\Controllers;
 
 use App\Http\Controllers\Controller;
-use App\Services\SettingService;
+use App\Facades\Settings;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 
 class SystemController extends Controller
 {
-    /**
-     * The Settings Service instance.
-     */
-    protected SettingService $settingService;
-
-
-    /**
-     * Create a new controller instance.
-     */
-    public function __construct(SettingService $settingService)
-    {
-        $this->settingService = $settingService;
-    }
-
-
     /**
      * Get detailed information about the current installation
      * 
@@ -55,7 +40,7 @@ class SystemController extends Controller
         $infos['Trusted proxies']  = config('2fauth.trustedProxies') ?: 'none';
         // User info
         if ($request->user()) {
-            $infos['options']     = $this->settingService->all()->toArray();
+            $infos['options']     = Settings::all()->toArray();
         }
 
         return response()->json($infos);

+ 2 - 2
app/Http/Middleware/KickOutInactiveUser.php

@@ -7,6 +7,7 @@ use Carbon\Carbon;
 use Illuminate\Http\Response;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Log;
+use App\Facades\Settings;
 
 class KickOutInactiveUser
 {
@@ -32,8 +33,7 @@ class KickOutInactiveUser
         $inactiveFor = $now->diffInSeconds(Carbon::parse($user->last_seen_at));
 
         // Fetch all setting values
-        $settingService = resolve('App\Services\SettingService');
-        $kickUserAfterXSecond = intval($settingService->get('kickUserAfter')) * 60;
+        $kickUserAfterXSecond = intval(Settings::get('kickUserAfter')) * 60;
 
         // If user has been inactive longer than the allowed inactivity period
         if ($kickUserAfterXSecond > 0 && $inactiveFor > $kickUserAfterXSecond) {

+ 3 - 3
app/Http/Middleware/SetLanguage.php

@@ -4,7 +4,7 @@ namespace App\Http\Middleware;
 
 use Closure;
 use Illuminate\Support\Facades\App;
-use Facades\App\Services\SettingService;
+use App\Facades\Settings;
 
 class SetLanguage
 {
@@ -23,8 +23,8 @@ class SetLanguage
         // - No language is passed from the client
         //
         // We prioritize the user defined one, then the request header one, and finally the fallback one.
-        // FI: SettingService::get() always returns a fallback value
-        $lang = SettingService::get('lang');
+        // FI: Settings::get() always returns a fallback value
+        $lang = Settings::get('lang');
 
         if($lang === 'browser') {
             $lang = config('app.fallback_locale');

+ 6 - 11
app/Models/TwoFAccount.php

@@ -4,7 +4,7 @@ namespace App\Models;
 
 use Exception;
 use App\Services\LogoService;
-use App\Services\SettingService;
+use App\Facades\Settings;
 use App\Models\Dto\TotpDto;
 use App\Models\Dto\HotpDto;
 use App\Events\TwoFAccountDeleted;
@@ -395,8 +395,7 @@ class TwoFAccount extends Model implements Sortable
             $this->icon = $this->getDefaultIcon();
         }
 
-        $settingService = App::make(SettingService::class);
-        if (!$this->icon && $settingService->get('getOfficialIcons') && !$skipIconFetching) {
+        if (!$this->icon && Settings::get('getOfficialIcons') && !$skipIconFetching) {
             $this->icon = $this->getDefaultIcon();
         } 
 
@@ -450,8 +449,7 @@ class TwoFAccount extends Model implements Sortable
             $this->icon = $this->storeImageAsIcon($this->generator->getParameter('image'));
         }
 
-        $settingService = App::make(SettingService::class);
-        if (!$this->icon && $settingService->get('getOfficialIcons') && !$skipIconFetching) {
+        if (!$this->icon && Settings::get('getOfficialIcons') && !$skipIconFetching) {
             $this->icon = $this->getDefaultIcon();
         }    
 
@@ -598,9 +596,8 @@ class TwoFAccount extends Model implements Sortable
     private function getDefaultIcon()
     {
         $logoService = App::make(LogoService::class);
-        $settingService = App::make(SettingService::class);
 
-        return $settingService->get('getOfficialIcons') ? $logoService->getIcon($this->service) : null;
+        return Settings::get('getOfficialIcons') ? $logoService->getIcon($this->service) : null;
     }
 
 
@@ -609,9 +606,8 @@ class TwoFAccount extends Model implements Sortable
      */
     private function decryptOrReturn($value)
     {
-        $settingService = App::make(SettingService::class);
         // Decipher when needed
-        if ( $settingService->get('useEncryption') )
+        if ( Settings::get('useEncryption') )
         {
             try {
                 return Crypt::decryptString($value);
@@ -631,9 +627,8 @@ class TwoFAccount extends Model implements Sortable
      */
     private function encryptOrReturn($value)
     {
-        $settingService = App::make(SettingService::class);
         // should be replaced by laravel 8 attribute encryption casting
-        return $settingService->get('useEncryption') ? Crypt::encryptString($value) : $value;
+        return Settings::get('useEncryption') ? Crypt::encryptString($value) : $value;
     }
 
 }

+ 6 - 9
app/Services/GroupService.php

@@ -4,7 +4,7 @@ namespace App\Services;
 
 use App\Models\Group;
 use App\Models\TwoFAccount;
-use App\Services\SettingService;
+use App\Facades\Settings;
 use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\App;
@@ -86,25 +86,23 @@ class GroupService
      */
     public static function delete($ids) : int
     {
-        $settingService = App::make(SettingService::class);
-
         $ids = is_array($ids) ? $ids : func_get_args();
 
         // A group is possibly set as the default group in Settings.
         // In this case we reset the setting to "No group" (groupId = 0)
-        $defaultGroupId = $settingService->get('defaultGroup');
+        $defaultGroupId = Settings::get('defaultGroup');
 
         if (in_array($defaultGroupId, $ids)) {
-            $settingService->set('defaultGroup', 0);
+            Settings::set('defaultGroup', 0);
         }
 
         // A group is also possibly set as the active group if the user
         // configured 2FAuth to memorize the active group.
         // In this case we reset the setting to the pseudo "All" group (groupId = 0)
-        $activeGroupId = $settingService->get('activeGroup');
+        $activeGroupId = Settings::get('activeGroup');
 
         if (in_array($activeGroupId, $ids)) {
-            $settingService->set('activeGroup', 0);
+            Settings::set('activeGroup', 0);
         }
 
         $deleted = Group::destroy($ids);
@@ -166,8 +164,7 @@ class GroupService
      */
     private static function defaultGroup()
     {
-        $settingService = App::make(SettingService::class);
-        $id = $settingService->get('defaultGroup') === -1 ? (int) $settingService->get('activeGroup') : (int) $settingService->get('defaultGroup');
+        $id = Settings::get('defaultGroup') === -1 ? (int) Settings::get('activeGroup') : (int) Settings::get('defaultGroup');
 
         return Group::find($id);
     }

+ 3 - 3
database/migrations/2021_09_14_195451_change_nullable_in_twofaccounts_table.php

@@ -6,6 +6,7 @@ use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Schema;
 use Illuminate\Support\Facades\Crypt;
 use Illuminate\Support\Facades\Log;
+use App\Facades\Settings;
 
 class ChangeNullableInTwofaccountsTable extends Migration
 {
@@ -17,18 +18,17 @@ class ChangeNullableInTwofaccountsTable extends Migration
     public function up()
     {
         $twofaccounts = DB::table('twofaccounts')->select('id', 'legacy_uri')->get();
-        $settingService = resolve('App\Services\SettingService');
 
         foreach ($twofaccounts as $twofaccount) {
             try {
-                $legacy_uri = $settingService->get('useEncryption') ? Crypt::decryptString($twofaccount->legacy_uri) : $twofaccount->legacy_uri;
+                $legacy_uri = Settings::get('useEncryption') ? Crypt::decryptString($twofaccount->legacy_uri) : $twofaccount->legacy_uri;
                 $token = \OTPHP\Factory::loadFromProvisioningUri($legacy_uri);
 
                 $affected = DB::table('twofaccounts')
                     ->where('id', $twofaccount->id)
                     ->update([
                         'otp_type'  => get_class($token) === 'OTPHP\TOTP' ? 'totp' : 'hotp',
-                        'secret'    => $settingService->get('useEncryption') ? Crypt::encryptString($token->getSecret()) : $token->getSecret(),
+                        'secret'    => Settings::get('useEncryption') ? Crypt::encryptString($token->getSecret()) : $token->getSecret(),
                         'algorithm' => $token->getDigest(),
                         'digits'    => $token->getDigits(),
                         'period'    => $token->hasParameter('period') ? $token->getParameter('period') : null,

+ 6 - 12
tests/Api/v1/Controllers/SettingControllerTest.php

@@ -3,9 +3,8 @@
 namespace Tests\Api\v1\Controllers;
 
 use App\Models\User;
-use App\Models\Group;
 use Tests\FeatureTestCase;
-use App\Models\TwoFAccount;
+use App\Facades\Settings;
 
 
 /**
@@ -74,8 +73,7 @@ class SettingControllerTest extends FeatureTestCase
      */
     public function test_show_native_changed_setting_returns_consistent_value()
     {
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set(self::TWOFAUTH_NATIVE_SETTING, self::TWOFAUTH_NATIVE_SETTING_CHANGED_VALUE);
+        Settings::set(self::TWOFAUTH_NATIVE_SETTING, self::TWOFAUTH_NATIVE_SETTING_CHANGED_VALUE);
 
         $response = $this->actingAs($this->user, 'api-guard')
             ->json('GET', '/api/v1/settings/' . self::TWOFAUTH_NATIVE_SETTING)
@@ -92,8 +90,7 @@ class SettingControllerTest extends FeatureTestCase
      */
     public function test_show_custom_user_setting_returns_consistent_value()
     {
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set(self::USER_DEFINED_SETTING, self::USER_DEFINED_SETTING_VALUE);
+        Settings::set(self::USER_DEFINED_SETTING, self::USER_DEFINED_SETTING_VALUE);
 
         $response = $this->actingAs($this->user, 'api-guard')
             ->json('GET', '/api/v1/settings/' . self::USER_DEFINED_SETTING)
@@ -153,8 +150,7 @@ class SettingControllerTest extends FeatureTestCase
      */
     public function test_store_existing_custom_user_setting_returns_validation_error()
     {
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set(self::USER_DEFINED_SETTING, self::USER_DEFINED_SETTING_VALUE);
+        Settings::set(self::USER_DEFINED_SETTING, self::USER_DEFINED_SETTING_VALUE);
 
         $response = $this->actingAs($this->user, 'api-guard')
             ->json('POST', '/api/v1/settings', [
@@ -187,8 +183,7 @@ class SettingControllerTest extends FeatureTestCase
      */
     public function test_update_custom_user_setting_returns_updated_setting()
     {
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set(self::USER_DEFINED_SETTING, self::USER_DEFINED_SETTING_VALUE);
+        Settings::set(self::USER_DEFINED_SETTING, self::USER_DEFINED_SETTING_VALUE);
 
         $response = $this->actingAs($this->user, 'api-guard')
             ->json('PUT', '/api/v1/settings/' . self::USER_DEFINED_SETTING, [
@@ -224,8 +219,7 @@ class SettingControllerTest extends FeatureTestCase
      */
     public function test_destroy_user_setting_returns_success()
     {
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set(self::USER_DEFINED_SETTING, self::USER_DEFINED_SETTING_VALUE);
+        Settings::set(self::USER_DEFINED_SETTING, self::USER_DEFINED_SETTING_VALUE);
 
         $response = $this->actingAs($this->user, 'api-guard')
             ->json('DELETE', '/api/v1/settings/' . self::USER_DEFINED_SETTING)

+ 7 - 15
tests/Api/v1/Controllers/TwoFAccountControllerTest.php

@@ -4,12 +4,12 @@ namespace Tests\Api\v1\Controllers;
 
 use App\Models\User;
 use App\Models\Group;
+use App\Facades\Settings;
 use Tests\FeatureTestCase;
 use Tests\Classes\OtpTestData;
 use App\Models\TwoFAccount;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Storage;
-use Illuminate\Http\UploadedFile;
 
 
 /**
@@ -393,8 +393,7 @@ class TwoFAccountControllerTest extends FeatureTestCase
     public function test_store_assigns_created_account_when_default_group_is_a_specific_one()
     {
         // Set the default group to a specific one
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set('defaultGroup', $this->group->id);
+        Settings::set('defaultGroup', $this->group->id);
 
         $response = $this->actingAs($this->user, 'api-guard')
             ->json('POST', '/api/v1/twofaccounts', [
@@ -411,12 +410,10 @@ class TwoFAccountControllerTest extends FeatureTestCase
      */
     public function test_store_assigns_created_account_when_default_group_is_the_active_one()
     {
-        $settingService = resolve('App\Services\SettingService');
-
         // Set the default group to be the active one
-        $settingService->set('defaultGroup', -1);
+        Settings::set('defaultGroup', -1);
         // Set the active group
-        $settingService->set('activeGroup', $this->group->id);
+        Settings::set('activeGroup', $this->group->id);
 
         $response = $this->actingAs($this->user, 'api-guard')
             ->json('POST', '/api/v1/twofaccounts', [
@@ -433,10 +430,8 @@ class TwoFAccountControllerTest extends FeatureTestCase
      */
     public function test_store_assigns_created_account_when_default_group_is_no_group()
     {
-        $settingService = resolve('App\Services\SettingService');
-
         // Set the default group to No group
-        $settingService->set('defaultGroup', 0);
+        Settings::set('defaultGroup', 0);
 
         $response = $this->actingAs($this->user, 'api-guard')
             ->json('POST', '/api/v1/twofaccounts', [
@@ -453,10 +448,8 @@ class TwoFAccountControllerTest extends FeatureTestCase
      */
     public function test_store_assigns_created_account_when_default_group_does_not_exist()
     {
-        $settingService = resolve('App\Services\SettingService');
-
         // Set the default group to a non-existing one
-        $settingService->set('defaultGroup', 1000);
+        Settings::set('defaultGroup', 1000);
 
         $response = $this->actingAs($this->user, 'api-guard')
             ->json('POST', '/api/v1/twofaccounts', [
@@ -836,8 +829,7 @@ class TwoFAccountControllerTest extends FeatureTestCase
      */
     public function test_get_otp_using_indecipherable_twofaccount_id_returns_bad_request()
     {
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set('useEncryption', true);
+        Settings::set('useEncryption', true);
 
         $twofaccount = TwoFAccount::factory()->create();
 

+ 2 - 2
tests/Api/v1/Requests/SettingStoreRequestTest.php

@@ -7,6 +7,7 @@ use Illuminate\Foundation\Testing\WithoutMiddleware;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Support\Facades\Auth;
 use Tests\FeatureTestCase;
+use App\Facades\Settings;
 
 class SettingStoreRequestTest extends FeatureTestCase
 {
@@ -69,8 +70,7 @@ class SettingStoreRequestTest extends FeatureTestCase
      */
     public function test_invalid_data(array $data) : void
     {
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set($this->uniqueKey, 'uniqueValue');
+        Settings::set($this->uniqueKey, 'uniqueValue');
 
         $request = new SettingStoreRequest();
         $validator = Validator::make($data, $request->rules());

+ 2 - 2
tests/Feature/Http/Auth/LoginTest.php

@@ -3,6 +3,7 @@
 namespace Tests\Feature\Http\Auth;
 
 use App\Models\User;
+use App\Facades\Settings;
 use Tests\FeatureTestCase;
 
 class LoginTest extends FeatureTestCase
@@ -163,8 +164,7 @@ class LoginTest extends FeatureTestCase
     public function test_user_logout_after_inactivity_returns_teapot()
     {
         // Set the autolock period to 1 minute
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set('kickUserAfter', 1);
+        Settings::set('kickUserAfter', 1);
 
         $response = $this->json('POST', '/user/login', [
             'email' => $this->user->email,

+ 3 - 5
tests/Feature/Http/Auth/UserControllerTest.php

@@ -3,6 +3,7 @@
 namespace Tests\Feature\Http\Auth;
 
 use App\Models\User;
+use App\Facades\Settings;
 use Tests\FeatureTestCase;
 use Illuminate\Support\Facades\Config;
 
@@ -53,8 +54,7 @@ class UserControllerTest extends FeatureTestCase
      */
     public function test_update_user_in_demo_mode_returns_unchanged_user()
     {
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set('isDemoApp', true);
+        Settings::set('isDemoApp', true);
 
         $response = $this->actingAs($this->user, 'web-guard')
             ->json('PUT', '/user', [
@@ -120,9 +120,7 @@ class UserControllerTest extends FeatureTestCase
     public function test_delete_user_in_demo_mode_returns_unauthorized()
     {
         Config::set('2fauth.config.isDemoApp', true);
-
-        $settingService = resolve('App\Services\SettingService');
-        $settingService->set('isDemoApp', true);
+        Settings::set('isDemoApp', true);
 
         $response = $this->actingAs($this->user, 'web-guard')
             ->json('DELETE', '/user', [

+ 9 - 17
tests/Feature/Services/GroupServiceTest.php

@@ -6,7 +6,7 @@ use App\Models\Group;
 use App\Models\TwoFAccount;
 use Tests\FeatureTestCase;
 use App\Facades\Groups;
-use App\Services\SettingService;
+use App\Facades\Settings;
 
 
 /**
@@ -14,12 +14,6 @@ use App\Services\SettingService;
  */
 class GroupServiceTest extends FeatureTestCase
 {
-    /**
-     * App\Services\SettingService $settingService
-     */
-    protected $settingService;
-
-
     /**
      * App\Models\Group $groupOne, $groupTwo
      */
@@ -52,8 +46,6 @@ class GroupServiceTest extends FeatureTestCase
     {
         parent::setUp();
 
-        $this->settingService = $this->app->make(SettingService::class);
-
         $this->groupOne = new Group;
         $this->groupOne->name = 'MyGroupOne';
         $this->groupOne->save();
@@ -178,7 +170,7 @@ class GroupServiceTest extends FeatureTestCase
      */
     public function test_delete_default_group_reset_defaultGroup_setting()
     {
-        $this->settingService->set('defaultGroup', $this->groupOne->id);
+        Settings::set('defaultGroup', $this->groupOne->id);
 
         $deleted = Groups::delete($this->groupOne->id);
         
@@ -194,8 +186,8 @@ class GroupServiceTest extends FeatureTestCase
      */
     public function test_delete_active_group_reset_activeGroup_setting()
     {
-        $this->settingService->set('rememberActiveGroup', true);
-        $this->settingService->set('activeGroup', $this->groupOne->id);
+        Settings::set('rememberActiveGroup', true);
+        Settings::set('activeGroup', $this->groupOne->id);
         
         $deleted = Groups::delete($this->groupOne->id);
         
@@ -244,7 +236,7 @@ class GroupServiceTest extends FeatureTestCase
      */
     public function test_assign_a_twofaccountid_to_no_group_assigns_to_default_group()
     {
-        $this->settingService->set('defaultGroup', $this->groupTwo->id);
+        Settings::set('defaultGroup', $this->groupTwo->id);
         
         Groups::assign($this->twofaccountOne->id);
         
@@ -260,8 +252,8 @@ class GroupServiceTest extends FeatureTestCase
      */
     public function test_assign_a_twofaccountid_to_no_group_assigns_to_active_group()
     {
-        $this->settingService->set('defaultGroup', -1);
-        $this->settingService->set('activeGroup', $this->groupTwo->id);
+        Settings::set('defaultGroup', -1);
+        Settings::set('activeGroup', $this->groupTwo->id);
         
         Groups::assign($this->twofaccountOne->id);
         
@@ -277,8 +269,8 @@ class GroupServiceTest extends FeatureTestCase
      */
     public function test_assign_a_twofaccountid_to_missing_active_group_does_not_fails()
     {
-        $this->settingService->set('defaultGroup', -1);
-        $this->settingService->set('activeGroup', 100000);
+        Settings::set('defaultGroup', -1);
+        Settings::set('activeGroup', 100000);
         
         Groups::assign($this->twofaccountOne->id);
         

+ 23 - 31
tests/Feature/Services/SettingServiceTest.php

@@ -6,7 +6,7 @@ use Tests\FeatureTestCase;
 use Illuminate\Support\Facades\Crypt;
 use Illuminate\Support\Facades\DB;
 use App\Models\TwoFAccount;
-use App\Services\SettingService;
+use App\Facades\Settings;
 
 
 /**
@@ -14,12 +14,6 @@ use App\Services\SettingService;
  */
 class SettingServiceTest extends FeatureTestCase
 {
-    /**
-     * App\Services\SettingService $settingService
-     */
-    protected $settingService;
-
-
     /**
      * App\Models\Group $groupOne, $groupTwo
      */
@@ -51,8 +45,6 @@ class SettingServiceTest extends FeatureTestCase
     {
         parent::setUp();
 
-        $this->settingService = $this->app->make(SettingService::class);
-
         $this->twofaccountOne = new TwoFAccount;
         $this->twofaccountOne->legacy_uri = self::TOTP_FULL_CUSTOM_URI;
         $this->twofaccountOne->service = self::SERVICE;
@@ -86,9 +78,9 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_get_string_setting_returns_correct_value()
     {
-        $this->settingService->set(self::SETTING_NAME, self::SETTING_VALUE_STRING);
+        Settings::set(self::SETTING_NAME, self::SETTING_VALUE_STRING);
 
-        $this->assertEquals(self::SETTING_VALUE_STRING, $this->settingService->get(self::SETTING_NAME));
+        $this->assertEquals(self::SETTING_VALUE_STRING, Settings::get(self::SETTING_NAME));
     }
 
 
@@ -97,9 +89,9 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_get_boolean_setting_returns_true()
     {
-        $this->settingService->set(self::SETTING_NAME, self::SETTING_VALUE_TRUE_TRANSFORMED);
+        Settings::set(self::SETTING_NAME, self::SETTING_VALUE_TRUE_TRANSFORMED);
 
-        $this->assertEquals(true, $this->settingService->get(self::SETTING_NAME));
+        $this->assertEquals(true, Settings::get(self::SETTING_NAME));
     }
 
 
@@ -108,9 +100,9 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_get_boolean_setting_returns_false()
     {
-        $this->settingService->set(self::SETTING_NAME, self::SETTING_VALUE_FALSE_TRANSFORMED);
+        Settings::set(self::SETTING_NAME, self::SETTING_VALUE_FALSE_TRANSFORMED);
 
-        $this->assertEquals(false, $this->settingService->get(self::SETTING_NAME));
+        $this->assertEquals(false, Settings::get(self::SETTING_NAME));
     }
 
 
@@ -119,9 +111,9 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_get_int_setting_returns_int()
     {
-        $this->settingService->set(self::SETTING_NAME, self::SETTING_VALUE_INT);
+        Settings::set(self::SETTING_NAME, self::SETTING_VALUE_INT);
 
-        $value = $this->settingService->get(self::SETTING_NAME);
+        $value = Settings::get(self::SETTING_NAME);
 
         $this->assertEquals(self::SETTING_VALUE_INT, $value);
         $this->assertIsInt($value);
@@ -135,9 +127,9 @@ class SettingServiceTest extends FeatureTestCase
     {
         $native_options = config('2fauth.options');
 
-        $this->settingService->set(self::SETTING_NAME, self::SETTING_VALUE_STRING);
+        Settings::set(self::SETTING_NAME, self::SETTING_VALUE_STRING);
 
-        $all = $this->settingService->all();
+        $all = Settings::all();
 
         $this->assertArrayHasKey(self::SETTING_NAME, $all);
         $this->assertEquals($all[self::SETTING_NAME], self::SETTING_VALUE_STRING);
@@ -157,7 +149,7 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_set_setting_persist_correct_value()
     {
-        $value = $this->settingService->set(self::SETTING_NAME, self::SETTING_VALUE_STRING);
+        $value = Settings::set(self::SETTING_NAME, self::SETTING_VALUE_STRING);
 
         $this->assertDatabaseHas('options', [
             self::KEY => self::SETTING_NAME,
@@ -171,7 +163,7 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_set_useEncryption_on_encrypts_all_accounts()
     {
-        $this->settingService->set('useEncryption', true);
+        Settings::set('useEncryption', true);
 
         $twofaccounts = DB::table('twofaccounts')->get();
 
@@ -188,8 +180,8 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_set_useEncryption_on_twice_prevents_successive_encryption()
     {
-        $this->settingService->set('useEncryption', true);
-        $this->settingService->set('useEncryption', true);
+        Settings::set('useEncryption', true);
+        Settings::set('useEncryption', true);
 
         $twofaccounts = DB::table('twofaccounts')->get();
 
@@ -206,8 +198,8 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_set_useEncryption_off_decrypts_all_accounts()
     {
-        $this->settingService->set('useEncryption', true);
-        $this->settingService->set('useEncryption', false);
+        Settings::set('useEncryption', true);
+        Settings::set('useEncryption', false);
 
         $twofaccounts = DB::table('twofaccounts')->get();
 
@@ -227,13 +219,13 @@ class SettingServiceTest extends FeatureTestCase
     {
         $this->expectException(\App\Exceptions\DbEncryptionException::class);
 
-        $this->settingService->set('useEncryption', true);
+        Settings::set('useEncryption', true);
 
         $affected = DB::table('twofaccounts')
             ->where('id', $this->twofaccountOne->id)
             ->update($data);
 
-            $this->settingService->set('useEncryption', false);
+            Settings::set('useEncryption', false);
 
         $twofaccount = TwoFAccount::find($this->twofaccountOne->id);
     }
@@ -263,7 +255,7 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_set_array_of_settings_persist_correct_values()
     {
-        $value = $this->settingService->set([
+        $value = Settings::set([
             self::SETTING_NAME => self::SETTING_VALUE_STRING,
             self::SETTING_NAME_ALT => self::SETTING_VALUE_INT,
         ]);
@@ -285,7 +277,7 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_set_true_setting_persist_transformed_boolean()
     {
-        $value = $this->settingService->set(self::SETTING_NAME, true);
+        $value = Settings::set(self::SETTING_NAME, true);
 
         $this->assertDatabaseHas('options', [
             self::KEY => self::SETTING_NAME,
@@ -299,7 +291,7 @@ class SettingServiceTest extends FeatureTestCase
      */
     public function test_set_false_setting_persist_transformed_boolean()
     {
-        $value = $this->settingService->set(self::SETTING_NAME, false);
+        $value = Settings::set(self::SETTING_NAME, false);
 
         $this->assertDatabaseHas('options', [
             self::KEY => self::SETTING_NAME,
@@ -317,7 +309,7 @@ class SettingServiceTest extends FeatureTestCase
             [self::KEY => self::SETTING_NAME, self::VALUE => strval(self::SETTING_VALUE_STRING)]
         );
 
-        $value = $this->settingService->delete(self::SETTING_NAME);
+        $value = Settings::delete(self::SETTING_NAME);
 
         $this->assertDatabaseMissing('options', [
             self::KEY => self::SETTING_NAME,

+ 2 - 3
tests/Unit/Api/v1/Controllers/GroupControllerTest.php

@@ -142,9 +142,8 @@ class GroupControllerTest extends TestCase
     {
         $group = Group::factory()->make();
         
-        $this->mock(SettingService::class, function (MockInterface $mock) {
-            $mock->shouldReceive('get')
-                ->with('useEncryption')
+        $settingService = $this->mock(SettingService::class, function (MockInterface $settingService) {
+            $settingService->shouldReceive('get')
                 ->andReturn(false);
         });
 

+ 0 - 15
tests/Unit/Events/TwoFAccountDeletedTest.php

@@ -23,21 +23,6 @@ class TwoFAccountDeletedTest extends TestCase
                 ->andReturn(false);
         });
 
-        // SettingService::shouldReceive('get')
-        //             ->andReturn(false);
-
-        // $settingService->shouldReceive('get')
-        //     ->with('useEncryption')
-        //     ->andReturn(false);
-
-        // $settingService->shouldReceive('get')
-        //     ->with('getOfficialIcons')
-        //     ->andReturn(false);
-
-        // \Facades\App\Services\SettingService::shouldReceive('get')
-        //     ->with('useEncryption')
-        //     ->andReturn(false);
-
         $twofaccount = TwoFAccount::factory()->make();
         $event = new TwoFAccountDeleted($twofaccount);
 

+ 0 - 5
tests/Unit/Listeners/CleanIconStorageTest.php

@@ -21,14 +21,9 @@ class CleanIconStorageTest extends TestCase
     {
         $settingService = $this->mock(SettingService::class, function (MockInterface $settingService) {
             $settingService->shouldReceive('get')
-                ->with('useEncryption')
                 ->andReturn(false);
         });
 
-        // \Facades\App\Services\SettingService::shouldReceive('get')
-        //     ->with('useEncryption')
-        //     ->andReturn(false);
-
         $twofaccount = TwoFAccount::factory()->make();
         $event = new TwoFAccountDeleted($twofaccount);
         $listener = new CleanIconStorage();

+ 0 - 12
tests/Unit/TwoFAccountModelTest.php

@@ -50,10 +50,6 @@ class TwoFAccountModelTest extends ModelTestCase
                 ->andReturn(true);
         });
 
-        // \Facades\App\Services\SettingService::shouldReceive('get')
-        //     ->with('useEncryption')
-        //     ->andReturn(true);
-
         $twofaccount = TwoFAccount::factory()->make([
             $attribute => 'string',
         ]);
@@ -92,10 +88,6 @@ class TwoFAccountModelTest extends ModelTestCase
                 ->andReturn(false);
         });
 
-        // \Facades\App\Services\SettingService::shouldReceive('get')
-        //     ->with('useEncryption')
-        //     ->andReturn(false);
-
         $twofaccount = TwoFAccount::factory()->make();
 
         $this->assertEquals($twofaccount->getAttributes()[$attribute], $twofaccount->$attribute);
@@ -115,10 +107,6 @@ class TwoFAccountModelTest extends ModelTestCase
                 ->andReturn(true);
         });
 
-        // \Facades\App\Services\SettingService::shouldReceive('get')
-        //     ->with('useEncryption')
-        //     ->andReturn(true);
-
         Crypt::shouldReceive('encryptString')
             ->andReturn('indecipherableString');