diff --git a/app/Api/v1/Controllers/GroupController.php b/app/Api/v1/Controllers/GroupController.php index a9756a61..3dc24f07 100644 --- a/app/Api/v1/Controllers/GroupController.php +++ b/app/Api/v1/Controllers/GroupController.php @@ -28,7 +28,7 @@ public function index(Request $request) Groups::setUser($groups, $request->user()); } } - + // We do not use fluent call all over the call chain to ease tests $user = $request->user(); $groups = $user->groups()->withCount('twofaccounts')->get(); diff --git a/app/Api/v1/Controllers/TwoFAccountController.php b/app/Api/v1/Controllers/TwoFAccountController.php index 6dae946c..32d387bb 100644 --- a/app/Api/v1/Controllers/TwoFAccountController.php +++ b/app/Api/v1/Controllers/TwoFAccountController.php @@ -151,8 +151,8 @@ public function reorder(TwoFAccountReorderRequest $request) $orderedIds = $request->user()->twofaccounts->sortBy('order_column')->pluck('id'); return response()->json([ - 'message' => 'order saved', - 'orderedIds' => $orderedIds + 'message' => 'order saved', + 'orderedIds' => $orderedIds, ], 200); } diff --git a/app/Console/Commands/Install.php b/app/Console/Commands/Install.php index 2e42a527..ee751dea 100644 --- a/app/Console/Commands/Install.php +++ b/app/Console/Commands/Install.php @@ -1,19 +1,18 @@ newLine(); $this->components->error($e->getMessage()); $this->components->info('See the error log at storage/logs/laravel.log for the full stack trace.'); - + $this->newLine(); $this->line('Fix the error and rerun the \'2fauth:install\' command to complete installation.'); $this->newLine(); @@ -201,7 +194,6 @@ protected function setMainEnvVars() : void $this->dotenvEditor->setKey('APP_URL', $appUrl); } - /** * Prompt user for valid database credentials and set them to .env file. */ @@ -232,7 +224,7 @@ protected function setDbEnvVars() : void $config['DB_DATABASE'] = $this->ask('Absolute path to the DB file', $databasePath); } else { - $defaultName = $this->dotenvEditor->getValue('DB_DATABASE') ?: '2fauth'; + $defaultName = $this->dotenvEditor->getValue('DB_DATABASE') ?: '2fauth'; $databaseName = $this->dotenvEditor->getValue('DB_CONNECTION') == 'sqlite' ? '2fauth' : $defaultName; @@ -250,7 +242,7 @@ protected function setDbEnvVars() : void // Set the config so that the next DB attempt uses refreshed credentials config([ - 'database.default' => $config['DB_CONNECTION'], + 'database.default' => $config['DB_CONNECTION'], 'database.connections.' . $config['DB_CONNECTION'] . '.database' => $config['DB_DATABASE'], 'database.connections.' . $config['DB_CONNECTION'] . '.host' => $config['DB_HOST'], 'database.connections.' . $config['DB_CONNECTION'] . '.port' => $config['DB_PORT'], @@ -299,7 +291,7 @@ protected function loadEnvFile() : void } $this->components->task('Preparing .env file', static function () : void { - if (!file_exists(base_path('.env'))) { + if (! file_exists(base_path('.env'))) { copy(base_path('.env.example'), base_path('.env')); } }); @@ -315,7 +307,7 @@ protected function maybeGenerateAppKey() : void $key = config('app.key'); $this->components->task($key ? 'Retrieving app key' : 'Generating app key', function () use (&$key) : void { - if (!$key) { + if (! $key) { // Generate the key manually to prevent some clashes with `php artisan key:generate` $key = $this->generateRandomKey(); $this->dotenvEditor->setKey('APP_KEY', $key); diff --git a/app/Console/Commands/Maintenance/FixOrphanAccounts.php b/app/Console/Commands/Maintenance/FixOrphanAccounts.php index 6286f1db..1d5f8a50 100644 --- a/app/Console/Commands/Maintenance/FixOrphanAccounts.php +++ b/app/Console/Commands/Maintenance/FixOrphanAccounts.php @@ -4,7 +4,6 @@ use App\Models\TwoFAccount; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Schema; /** * @codeCoverageIgnore @@ -31,7 +30,7 @@ class FixOrphanAccounts extends Command * @var bool */ protected $hidden = true; - + /** * Create a new command instance. * @@ -50,12 +49,12 @@ public function __construct() public function handle() { $twofaccounts = TwoFAccount::where('otp_type', '') - ->where('secret', '') - ->where('algorithm', '') - ->where('digits', 0) - ->whereNull('period') - ->whereNull('counter') - ->get(); + ->where('secret', '') + ->where('algorithm', '') + ->where('digits', 0) + ->whereNull('period') + ->whereNull('counter') + ->get(); $this->line(sprintf('%d inconsistent accounts found', $twofaccounts->count())); diff --git a/app/Console/Commands/Maintenance/FixUnsplittedAccounts.php b/app/Console/Commands/Maintenance/FixUnsplittedAccounts.php index 40ace518..96f1ae26 100644 --- a/app/Console/Commands/Maintenance/FixUnsplittedAccounts.php +++ b/app/Console/Commands/Maintenance/FixUnsplittedAccounts.php @@ -58,12 +58,12 @@ public function handle() } $twofaccounts = TwoFAccount::where('otp_type', '') - ->where('secret', '') - ->where('algorithm', '') - ->where('digits', 0) - ->whereNull('period') - ->whereNull('counter') - ->get(); + ->where('secret', '') + ->where('algorithm', '') + ->where('digits', 0) + ->whereNull('period') + ->whereNull('counter') + ->get(); $this->line(sprintf('%d inconsistent accounts found', $twofaccounts->count())); diff --git a/app/Extensions/WebauthnCredentialBroker.php b/app/Extensions/WebauthnCredentialBroker.php index f211366f..f50fb7d4 100644 --- a/app/Extensions/WebauthnCredentialBroker.php +++ b/app/Extensions/WebauthnCredentialBroker.php @@ -13,7 +13,7 @@ class WebauthnCredentialBroker extends PasswordBroker /** * Send a password reset link to a user. */ - public function sendResetLink(array $credentials, Closure $callback = null) : string + public function sendResetLink(array $credentials, ?Closure $callback = null) : string { /** * @var \App\Models\User diff --git a/app/Helpers/Helpers.php b/app/Helpers/Helpers.php index 919e204e..620e9159 100644 --- a/app/Helpers/Helpers.php +++ b/app/Helpers/Helpers.php @@ -16,7 +16,6 @@ public static function cleanVersionNumber(?string $release) : string|false /** * Format a string to comply with Base32 format * - * @param string $str * @return string The filename */ public static function PadToBase32Format(?string $str) : string diff --git a/app/Http/Controllers/Auth/SocialiteController.php b/app/Http/Controllers/Auth/SocialiteController.php index cf446fdc..21702a8f 100644 --- a/app/Http/Controllers/Auth/SocialiteController.php +++ b/app/Http/Controllers/Auth/SocialiteController.php @@ -15,7 +15,7 @@ class SocialiteController extends Controller { /** * Redirect to the provider's authentication url - * + * * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Illuminate\Http\RedirectResponse */ public function redirect(Request $request, string $driver) @@ -31,7 +31,7 @@ public function redirect(Request $request, string $driver) /** * Register (if needed) the user and authenticate him - * + * * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse */ public function callback(Request $request, string $driver) @@ -42,7 +42,7 @@ public function callback(Request $request, string $driver) return redirect('/error?err=sso_failed'); } - $uniqueName = $socialiteUser->getId() . '@' . $driver; + $uniqueName = $socialiteUser->getId() . '@' . $driver; $socialiteEmail = $socialiteUser->getEmail() ?? $uniqueName; $socialiteName = ($socialiteUser->getNickname() ?? $socialiteUser->getName()) . ' (' . $uniqueName . ')'; @@ -55,11 +55,9 @@ public function callback(Request $request, string $driver) if (! $user->exists) { if (User::where('email', $socialiteEmail)->exists()) { return redirect('/error?err=sso_email_already_used'); - } - else if (User::count() === 0) { + } elseif (User::count() === 0) { $user->is_admin = true; - } - else if (Settings::get('disableRegistration')) { + } elseif (Settings::get('disableRegistration')) { return redirect('/error?err=sso_no_register'); } $user->password = bcrypt(Str::random()); diff --git a/app/Http/Controllers/SinglePageController.php b/app/Http/Controllers/SinglePageController.php index 09fe79d1..98a4f0f1 100644 --- a/app/Http/Controllers/SinglePageController.php +++ b/app/Http/Controllers/SinglePageController.php @@ -41,7 +41,7 @@ public function index() 'openid' => $openidAuth, 'github' => $githubAuth, ], - 'subdirectory' => $subdir, + 'subdirectory' => $subdir, ])->toJson(), 'defaultPreferences' => $defaultPreferences, 'subdirectory' => $subdir, diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index e886e280..95dfb410 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -55,7 +55,7 @@ class Kernel extends HttpKernel ], 'api.v1' => [ - \Illuminate\Routing\Middleware\ThrottleRequests::class.':api', + \Illuminate\Routing\Middleware\ThrottleRequests::class . ':api', \Illuminate\Routing\Middleware\SubstituteBindings::class, \App\Http\Middleware\KickOutInactiveUser::class, \App\Http\Middleware\LogUserLastSeen::class, diff --git a/app/Models/Group.php b/app/Models/Group.php index 7717f62b..5c8416e4 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -94,24 +94,24 @@ public function twofaccounts() return $this->hasMany(\App\Models\TwoFAccount::class); } - /** - * Get the user that owns the group. - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\User, \App\Models\Group> - */ - public function user() - { - return $this->belongsTo(\App\Models\User::class); - } + /** + * Get the user that owns the group. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\User, \App\Models\Group> + */ + public function user() + { + return $this->belongsTo(\App\Models\User::class); + } - /** - * Scope a query to only include orphan (userless) groups. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeOrphans($query) - { - return $query->where('user_id', null); - } + /** + * Scope a query to only include orphan (userless) groups. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeOrphans($query) + { + return $query->where('user_id', null); + } } diff --git a/app/Models/TwoFAccount.php b/app/Models/TwoFAccount.php index aad5a045..e21e91fc 100644 --- a/app/Models/TwoFAccount.php +++ b/app/Models/TwoFAccount.php @@ -56,7 +56,7 @@ */ class TwoFAccount extends Model implements Sortable { - use SortableTrait, HasFactory; + use HasFactory, SortableTrait; const TOTP = 'totp'; @@ -634,7 +634,7 @@ public function setIcon($data, $extension = null) : void * @param string $extension The file extension, without the dot * @return string|null The filename of the stored icon or null if the operation fails */ - private function storeFileDataAsIcon($content, $extension) : string|null + private function storeFileDataAsIcon($content, $extension) : ?string { $filename = self::getUniqueFilename($extension); @@ -684,7 +684,7 @@ private function isValidIcon($filename, $disk) : bool * * @return string|null The filename of the stored icon or null if the operation fails */ - private function storeRemoteImageAsIcon(string $url) : string|null + private function storeRemoteImageAsIcon(string $url) : ?string { try { $path_parts = pathinfo($url); diff --git a/app/Models/User.php b/app/Models/User.php index d5e0c359..e32ac488 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -40,8 +40,8 @@ */ class User extends Authenticatable implements WebAuthnAuthenticatable { - use WebAuthnAuthentication, WebAuthnManageCredentials; use HasApiTokens, HasFactory, Notifiable; + use WebAuthnAuthentication, WebAuthnManageCredentials; /** * The attributes that are mass assignable. @@ -49,7 +49,7 @@ class User extends Authenticatable implements WebAuthnAuthenticatable * @var string[] */ protected $fillable = [ - 'name', 'email', 'password', 'oauth_id', 'oauth_provider' + 'name', 'email', 'password', 'oauth_id', 'oauth_provider', ]; /** diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index d599233d..8eb1cfad 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -8,9 +8,9 @@ use App\Events\TwoFAccountDeleted; use App\Listeners\CleanIconStorage; use App\Listeners\DissociateTwofaccountFromGroup; +use App\Listeners\RegisterOpenId; use App\Listeners\ReleaseRadar; use App\Listeners\ResetUsersPreference; -use App\Listeners\RegisterOpenId; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; diff --git a/app/Providers/MigrationServiceProvider.php b/app/Providers/MigrationServiceProvider.php index 3c58cee7..426795e8 100644 --- a/app/Providers/MigrationServiceProvider.php +++ b/app/Providers/MigrationServiceProvider.php @@ -14,8 +14,6 @@ class MigrationServiceProvider extends ServiceProvider { /** * Register services. - * - * @return void */ public function register() : void { diff --git a/app/Providers/Socialite/OpenId.php b/app/Providers/Socialite/OpenId.php index 93b77f07..d0786abe 100644 --- a/app/Providers/Socialite/OpenId.php +++ b/app/Providers/Socialite/OpenId.php @@ -3,10 +3,8 @@ namespace App\Providers\Socialite; use GuzzleHttp\RequestOptions; -use InvalidArgumentException; use SocialiteProviders\Manager\OAuth2\AbstractProvider; use SocialiteProviders\Manager\OAuth2\User; -use SocialiteProviders\Manager\SocialiteWasCalled; class OpenId extends AbstractProvider { @@ -48,7 +46,7 @@ protected function getUserByToken($token) { $response = $this->getHttpClient()->get($this->getConfig('userinfo_url'), [ RequestOptions::HEADERS => [ - 'Authorization' => 'Bearer '.$token, + 'Authorization' => 'Bearer ' . $token, ], ]); diff --git a/app/Rules/IsBase32Encoded.php b/app/Rules/IsBase32Encoded.php index 14a2b9f9..cfa8ad61 100644 --- a/app/Rules/IsBase32Encoded.php +++ b/app/Rules/IsBase32Encoded.php @@ -12,7 +12,7 @@ class IsBase32Encoded implements ValidationRule /** * Run the validation rule. */ - public function validate(string $attribute, mixed $value, Closure $fail): void + public function validate(string $attribute, mixed $value, Closure $fail) : void { try { $secret = Base32::decodeUpper(Helpers::PadToBase32Format($value)); diff --git a/app/Services/GroupService.php b/app/Services/GroupService.php index 0f360dc8..dd9a71eb 100644 --- a/app/Services/GroupService.php +++ b/app/Services/GroupService.php @@ -19,7 +19,7 @@ class GroupService * * @throws \Illuminate\Auth\Access\AuthorizationException */ - public static function assign($ids, User $user, Group $group = null) : void + public static function assign($ids, User $user, ?Group $group = null) : void { if (! $group) { $group = self::defaultGroup($user); @@ -62,9 +62,8 @@ public static function prependTheAllGroup(Collection $groups, User $user) : Coll /** * Set owner of given groups - * + * * @param Collection $groups - * @param \App\Models\User $user */ public static function setUser(Collection $groups, User $user) : void { diff --git a/app/Services/ReleaseRadarService.php b/app/Services/ReleaseRadarService.php index 76cce36a..5b460d24 100644 --- a/app/Services/ReleaseRadarService.php +++ b/app/Services/ReleaseRadarService.php @@ -41,8 +41,8 @@ protected static function newRelease() : string|null|false if ($latestRelease) { $latestReleaseData = json_decode($latestRelease); - $githubVersion = Helpers::cleanVersionNumber($latestReleaseData->tag_name); - $installedVersion = Helpers::cleanVersionNumber(config('2fauth.version')); + $githubVersion = Helpers::cleanVersionNumber($latestReleaseData->tag_name); + $installedVersion = Helpers::cleanVersionNumber(config('2fauth.version')); if ($githubVersion && $installedVersion) { if (version_compare($githubVersion, $installedVersion) > 0 && $latestReleaseData->prerelease == false && $latestReleaseData->draft == false) { @@ -63,7 +63,7 @@ protected static function newRelease() : string|null|false /** * Fetch releases on Github */ - protected static function getLatestReleaseData() : string|null + protected static function getLatestReleaseData() : ?string { $url = config('2fauth.latestReleaseUrl'); diff --git a/app/Services/SettingService.php b/app/Services/SettingService.php index 4547a74f..02a433e2 100644 --- a/app/Services/SettingService.php +++ b/app/Services/SettingService.php @@ -215,6 +215,7 @@ private function updateRecords(bool $encrypted) : bool $item->secret = $encrypted ? Crypt::encryptString($item->secret) : Crypt::decryptString($item->secret); } catch (Exception $ex) { $success = false; + // Exit the each iteration return false; } diff --git a/app/Services/TwoFAccountService.php b/app/Services/TwoFAccountService.php index 086f6709..fe11ded5 100644 --- a/app/Services/TwoFAccountService.php +++ b/app/Services/TwoFAccountService.php @@ -40,9 +40,9 @@ public static function withdraw($ids) : void $ids = is_array($ids) ? $ids : func_get_args(); TwoFAccount::whereIn('id', $ids) - ->update( - ['group_id' => null] - ); + ->update( + ['group_id' => null] + ); Log::info(sprintf('TwoFAccounts IDs #%s withdrawn', implode(',', $ids))); } @@ -96,9 +96,8 @@ public static function delete($ids) : int /** * Set owner of given twofaccounts - * + * * @param \Illuminate\Support\Collection $twofaccounts - * @param \App\Models\User $user */ public static function setUser(Collection $twofaccounts, User $user) : void { diff --git a/tests/Api/v1/Controllers/Auth/UserControllerTest.php b/tests/Api/v1/Controllers/Auth/UserControllerTest.php index b1260b30..d459b093 100644 --- a/tests/Api/v1/Controllers/Auth/UserControllerTest.php +++ b/tests/Api/v1/Controllers/Auth/UserControllerTest.php @@ -44,10 +44,10 @@ public function test_show_existing_user_when_authenticated_returns_success() ->json('GET', '/api/v1/user') ->assertOk() ->assertJsonFragment([ - 'name' => $this->user->name, - 'id' => $this->user->id, - 'email' => $this->user->email, - 'is_admin' => $this->user->is_admin, + 'name' => $this->user->name, + 'id' => $this->user->id, + 'email' => $this->user->email, + 'is_admin' => $this->user->is_admin, ]) ->assertJsonStructure([ 'preferences', diff --git a/tests/Api/v1/Controllers/GroupControllerTest.php b/tests/Api/v1/Controllers/GroupControllerTest.php index 6f3ed360..aadf3847 100644 --- a/tests/Api/v1/Controllers/GroupControllerTest.php +++ b/tests/Api/v1/Controllers/GroupControllerTest.php @@ -444,7 +444,7 @@ public function test_destroy_missing_group_returns_not_found() public function test_destroy_group_of_another_user_is_forbidden() { $response = $this->actingAs($this->anotherUser, 'api-guard') - ->json('DELETE', '/api/v1/groups/' . $this->userGroupA->id) + ->json('DELETE', '/api/v1/groups/' . $this->userGroupA->id) ->assertForbidden() ->assertJsonStructure([ 'message', diff --git a/tests/Api/v1/Controllers/TwoFAccountControllerTest.php b/tests/Api/v1/Controllers/TwoFAccountControllerTest.php index 5cbdb42e..f1a8a91b 100644 --- a/tests/Api/v1/Controllers/TwoFAccountControllerTest.php +++ b/tests/Api/v1/Controllers/TwoFAccountControllerTest.php @@ -18,11 +18,11 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use Tests\Classes\LocalFile; use Tests\Data\MigrationTestData; use Tests\Data\OtpTestData; use Tests\FeatureTestCase; -use PHPUnit\Framework\Attributes\DataProvider; /** * TwoFAccountControllerTest test class @@ -1016,7 +1016,7 @@ public function test_export_missing_twofaccount_returns_existing_ones_only() public function test_export_twofaccount_of_another_user_is_forbidden() { $response = $this->actingAs($this->user, 'api-guard') - ->json('GET', '/api/v1/twofaccounts/export?ids=' . $this->twofaccountC->id) + ->json('GET', '/api/v1/twofaccounts/export?ids=' . $this->twofaccountC->id) ->assertForbidden() ->assertJsonStructure([ 'message', @@ -1296,7 +1296,7 @@ public function test_destroy_missing_twofaccount_returns_not_found() public function test_destroy_twofaccount_of_another_user_is_forbidden() { $response = $this->actingAs($this->user, 'api-guard') - ->json('DELETE', '/api/v1/twofaccounts/' . $this->twofaccountC->id) + ->json('DELETE', '/api/v1/twofaccounts/' . $this->twofaccountC->id) ->assertForbidden() ->assertJsonStructure([ 'message', @@ -1346,7 +1346,7 @@ public function test_batch_destroy_twofaccount_of_another_user_is_forbidden() ->implode(','); $response = $this->actingAs($this->user, 'api-guard') - ->json('DELETE', '/api/v1/twofaccounts?ids=' . $ids) + ->json('DELETE', '/api/v1/twofaccounts?ids=' . $ids) ->assertForbidden() ->assertJsonStructure([ 'message', diff --git a/tests/Feature/Console/ResetDemoTest.php b/tests/Feature/Console/ResetDemoTest.php index ca7d8edc..ca727b0d 100644 --- a/tests/Feature/Console/ResetDemoTest.php +++ b/tests/Feature/Console/ResetDemoTest.php @@ -13,8 +13,8 @@ class ResetDemoTest extends FeatureTestCase public function test_reset_demo_without_demo_mode_succeeded() { $this->artisan('2fauth:reset-demo') - ->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On') - ->assertSuccessful(); + ->expectsOutput('2fauth:reset-demo can only run when isDemoApp option is On') + ->assertSuccessful(); } /** @@ -25,9 +25,9 @@ public function test_reset_demo_succeeded() Config::set('2fauth.config.isDemoApp', true); $this->artisan('2fauth:reset-demo') - ->expectsOutput('This will reset the app in order to run a clean and fresh demo.') - ->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'demo') - ->assertSuccessful(); + ->expectsOutput('This will reset the app in order to run a clean and fresh demo.') + ->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'demo') + ->assertSuccessful(); $this->assertDatabaseCount('twofaccounts', 9); @@ -140,9 +140,9 @@ public function test_reset_demo_with_invalid_confirmation_succeeded() Config::set('2fauth.config.isDemoApp', true); $this->artisan('2fauth:reset-demo') - ->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'null') - ->expectsOutput('Bad confirmation word, nothing appened') - ->assertSuccessful(); + ->expectsQuestion('To prevent any mistake please type the word "demo" to go on', 'null') + ->expectsOutput('Bad confirmation word, nothing appened') + ->assertSuccessful(); } /** diff --git a/tests/Feature/Console/ResetTestingTest.php b/tests/Feature/Console/ResetTestingTest.php index f710968b..0509d3d3 100644 --- a/tests/Feature/Console/ResetTestingTest.php +++ b/tests/Feature/Console/ResetTestingTest.php @@ -13,8 +13,8 @@ class ResetTestingTest extends FeatureTestCase public function test_reset_testing_without_testing_mode_succeeded() { $this->artisan('2fauth:reset-testing') - ->expectsOutput('2fauth:reset-testing can only run when isTestingApp option is On') - ->assertSuccessful(); + ->expectsOutput('2fauth:reset-testing can only run when isTestingApp option is On') + ->assertSuccessful(); } /** @@ -25,9 +25,9 @@ public function test_reset_testing_succeeded() Config::set('2fauth.config.isTestingApp', true); $this->artisan('2fauth:reset-testing') - ->expectsOutput('This will reset the app in order to run a clean and fresh testing app.') - ->expectsQuestion('To prevent any mistake please type the word "testing" to go on', 'testing') - ->assertSuccessful(); + ->expectsOutput('This will reset the app in order to run a clean and fresh testing app.') + ->expectsQuestion('To prevent any mistake please type the word "testing" to go on', 'testing') + ->assertSuccessful(); $this->assertDatabaseCount('twofaccounts', 9); @@ -140,9 +140,9 @@ public function test_reset_testing_with_invalid_confirmation_succeeded() Config::set('2fauth.config.isTestingApp', true); $this->artisan('2fauth:reset-testing') - ->expectsQuestion('To prevent any mistake please type the word "testing" to go on', 'null') - ->expectsOutput('Bad confirmation word, nothing appened') - ->assertSuccessful(); + ->expectsQuestion('To prevent any mistake please type the word "testing" to go on', 'null') + ->expectsOutput('Bad confirmation word, nothing appened') + ->assertSuccessful(); } /** @@ -153,6 +153,6 @@ public function test_reset_testing_with_no_confirm_option_succeeded() Config::set('2fauth.config.isTestingApp', true); $this->artisan('2fauth:reset-testing --no-confirm') - ->assertSuccessful(); + ->assertSuccessful(); } } diff --git a/tests/Feature/Http/Auth/LoginTest.php b/tests/Feature/Http/Auth/LoginTest.php index 4c301246..f10ceea3 100644 --- a/tests/Feature/Http/Auth/LoginTest.php +++ b/tests/Feature/Http/Auth/LoginTest.php @@ -163,7 +163,7 @@ public function test_too_many_login_attempts_with_invalid_credentials_returns_to ->assertUnauthorized(); $this->json('POST', '/user/login', $post) - ->assertStatus(429); + ->assertStatus(429); } /** diff --git a/tests/Feature/Http/Auth/RegisterControllerTest.php b/tests/Feature/Http/Auth/RegisterControllerTest.php index b9062799..8d36c989 100644 --- a/tests/Feature/Http/Auth/RegisterControllerTest.php +++ b/tests/Feature/Http/Auth/RegisterControllerTest.php @@ -145,6 +145,6 @@ public function test_register_is_forbidden_when_registration_is_disabled() 'password' => self::PASSWORD, 'password_confirmation' => self::PASSWORD, ]) - ->assertStatus(403); + ->assertStatus(403); } } diff --git a/tests/Feature/Http/Auth/SocialiteControllerTest.php b/tests/Feature/Http/Auth/SocialiteControllerTest.php index f21c3603..d1ca7aef 100644 --- a/tests/Feature/Http/Auth/SocialiteControllerTest.php +++ b/tests/Feature/Http/Auth/SocialiteControllerTest.php @@ -53,14 +53,13 @@ public function setUp() : void 'oauth_provider' => self::USER_OAUTH_PROVIDER, ]); - - $this->socialiteUser = new \Laravel\Socialite\Two\User; - $this->socialiteUser->id = self::USER_OAUTH_ID; - $this->socialiteUser->name = self::USER_NAME; - $this->socialiteUser->email = self::USER_EMAIL; + $this->socialiteUser = new \Laravel\Socialite\Two\User; + $this->socialiteUser->id = self::USER_OAUTH_ID; + $this->socialiteUser->name = self::USER_NAME; + $this->socialiteUser->email = self::USER_EMAIL; $this->socialiteUser->nickname = self::USER_NICKNAME; } - + /** * @test */ @@ -116,9 +115,9 @@ public function test_callback_redirects_authenticated_user_to_accounts() */ public function test_callback_updates_user_informations() { - $socialiteUpdatedUser = new \Laravel\Socialite\Two\User; - $socialiteUpdatedUser->id = self::USER_OAUTH_ID; - $socialiteUpdatedUser->email = 'new_email'; + $socialiteUpdatedUser = new \Laravel\Socialite\Two\User; + $socialiteUpdatedUser->id = self::USER_OAUTH_ID; + $socialiteUpdatedUser->email = 'new_email'; $socialiteUpdatedUser->nickname = 'new_nickname'; Socialite::shouldReceive('driver->user') @@ -138,9 +137,9 @@ public function test_callback_updates_user_informations() */ public function test_callback_updates_username_with_fallback_value() { - $socialiteUpdatedUser = new \Laravel\Socialite\Two\User; - $socialiteUpdatedUser->id = self::USER_OAUTH_ID; - $socialiteUpdatedUser->name = 'new_name'; + $socialiteUpdatedUser = new \Laravel\Socialite\Two\User; + $socialiteUpdatedUser->id = self::USER_OAUTH_ID; + $socialiteUpdatedUser->name = 'new_name'; $socialiteUpdatedUser->email = 'new_email'; Socialite::shouldReceive('driver->user') @@ -160,9 +159,9 @@ public function test_callback_updates_username_with_fallback_value() */ public function test_callback_registers_new_user() { - $newSocialiteUser = new \Laravel\Socialite\Two\User; - $newSocialiteUser->id = 'new_id'; - $newSocialiteUser->name = 'jane'; + $newSocialiteUser = new \Laravel\Socialite\Two\User; + $newSocialiteUser->id = 'new_id'; + $newSocialiteUser->name = 'jane'; $newSocialiteUser->email = 'jane@provider.com'; Socialite::shouldReceive('driver->user') @@ -183,10 +182,10 @@ public function test_callback_registers_new_user() */ public function test_callback_registers_new_user_with_existing_name() { - $socialiteUserWithSameName = new \Laravel\Socialite\Two\User; - $socialiteUserWithSameName->id = 'socialiteUserWithSameNameId'; - $socialiteUserWithSameName->name = self::USER_NAME; - $socialiteUserWithSameName->email = 'socialiteuserwithsamename@example.com'; + $socialiteUserWithSameName = new \Laravel\Socialite\Two\User; + $socialiteUserWithSameName->id = 'socialiteUserWithSameNameId'; + $socialiteUserWithSameName->name = self::USER_NAME; + $socialiteUserWithSameName->email = 'socialiteuserwithsamename@example.com'; $socialiteUserWithSameName->nickname = self::USER_NICKNAME; Socialite::shouldReceive('driver->user') @@ -233,10 +232,10 @@ public function test_callback_returns_error_when_email_is_already_used() 'password' => 'password', ]); - $socialiteUserWithSameEmail = new \Laravel\Socialite\Two\User; - $socialiteUserWithSameEmail->id = '666'; - $socialiteUserWithSameEmail->name = 'socialiteUserWithSameEmail'; - $socialiteUserWithSameEmail->email = 'other@example.com'; + $socialiteUserWithSameEmail = new \Laravel\Socialite\Two\User; + $socialiteUserWithSameEmail->id = '666'; + $socialiteUserWithSameEmail->name = 'socialiteUserWithSameEmail'; + $socialiteUserWithSameEmail->email = 'other@example.com'; $socialiteUserWithSameEmail->nickname = self::USER_NICKNAME; Socialite::shouldReceive('driver->user') @@ -258,9 +257,9 @@ public function test_callback_returns_error_when_registrations_are_closed() { Settings::set('disableRegistration', true); - $newSocialiteUser = new \Laravel\Socialite\Two\User; - $newSocialiteUser->id = 'rejected_id'; - $newSocialiteUser->name = 'jane'; + $newSocialiteUser = new \Laravel\Socialite\Two\User; + $newSocialiteUser->id = 'rejected_id'; + $newSocialiteUser->name = 'jane'; $newSocialiteUser->email = 'jane@provider.com'; Socialite::shouldReceive('driver->user') @@ -278,9 +277,9 @@ public function test_callback_skips_registration_when_registrations_are_closed() { Settings::set('disableRegistration', true); - $newSocialiteUser = new \Laravel\Socialite\Two\User; - $newSocialiteUser->id = 'rejected_id'; - $newSocialiteUser->name = 'jane'; + $newSocialiteUser = new \Laravel\Socialite\Two\User; + $newSocialiteUser->id = 'rejected_id'; + $newSocialiteUser->name = 'jane'; $newSocialiteUser->email = 'jane@provider.com'; Socialite::shouldReceive('driver->user') @@ -293,5 +292,4 @@ public function test_callback_skips_registration_when_registrations_are_closed() 'oauth_provider' => self::USER_OAUTH_PROVIDER, ]); } - } diff --git a/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php b/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php index d2c5d1a6..536cee50 100644 --- a/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php +++ b/tests/Feature/Http/Auth/WebAuthnLoginControllerTest.php @@ -316,7 +316,7 @@ public function test_too_many_invalid_login_attempts_returns_too_many_request_er ->assertUnauthorized(); $this->json('POST', '/webauthn/login', self::ASSERTION_RESPONSE_INVALID) - ->assertStatus(429); + ->assertStatus(429); } /** diff --git a/tests/Feature/Http/Requests/UserDeleteRequestTest.php b/tests/Feature/Http/Requests/UserDeleteRequestTest.php index 5c6337e9..0b0faa5f 100644 --- a/tests/Feature/Http/Requests/UserDeleteRequestTest.php +++ b/tests/Feature/Http/Requests/UserDeleteRequestTest.php @@ -24,8 +24,8 @@ class UserDeleteRequestTest extends FeatureTestCase public function test_user_is_authorized() { Auth::shouldReceive('check') - ->once() - ->andReturn(true); + ->once() + ->andReturn(true); $request = new UserDeleteRequest(); diff --git a/tests/Feature/Http/Requests/UserPatchPwdRequestTest.php b/tests/Feature/Http/Requests/UserPatchPwdRequestTest.php index d4818e95..fc0a0dc2 100644 --- a/tests/Feature/Http/Requests/UserPatchPwdRequestTest.php +++ b/tests/Feature/Http/Requests/UserPatchPwdRequestTest.php @@ -24,8 +24,8 @@ class UserPatchPwdRequestTest extends TestCase public function test_user_is_authorized() { Auth::shouldReceive('check') - ->once() - ->andReturn(true); + ->once() + ->andReturn(true); $request = new UserPatchPwdRequest(); diff --git a/tests/Feature/Http/Requests/UserUpdateRequestTest.php b/tests/Feature/Http/Requests/UserUpdateRequestTest.php index 0e7d2ac3..a0ddfd60 100644 --- a/tests/Feature/Http/Requests/UserUpdateRequestTest.php +++ b/tests/Feature/Http/Requests/UserUpdateRequestTest.php @@ -26,8 +26,8 @@ class UserUpdateRequestTest extends FeatureTestCase public function test_user_is_authorized() { Auth::shouldReceive('check') - ->once() - ->andReturn(true); + ->once() + ->andReturn(true); $request = new UserUpdateRequest(); diff --git a/tests/Feature/Http/Requests/WebauthnRenameRequestTest.php b/tests/Feature/Http/Requests/WebauthnRenameRequestTest.php index a3af788d..e026bb4b 100644 --- a/tests/Feature/Http/Requests/WebauthnRenameRequestTest.php +++ b/tests/Feature/Http/Requests/WebauthnRenameRequestTest.php @@ -24,8 +24,8 @@ class WebauthnRenameRequestTest extends TestCase public function test_user_is_authorized() { Auth::shouldReceive('check') - ->once() - ->andReturn(true); + ->once() + ->andReturn(true); $request = new WebauthnRenameRequest(); diff --git a/tests/Feature/Services/SettingServiceTest.php b/tests/Feature/Services/SettingServiceTest.php index ddd70579..d0600390 100644 --- a/tests/Feature/Services/SettingServiceTest.php +++ b/tests/Feature/Services/SettingServiceTest.php @@ -373,7 +373,7 @@ public function test_isEdited_returns_false() public function test_cache_is_requested_at_instanciation() { Cache::shouldReceive('remember') - ->andReturn(collect([])); + ->andReturn(collect([])); $settingService = new SettingService(); @@ -386,7 +386,7 @@ public function test_cache_is_requested_at_instanciation() public function test_cache_is_updated_when_setting_is_set() { Cache::shouldReceive('remember', 'put') - ->andReturn(collect([]), true); + ->andReturn(collect([]), true); $settingService = new SettingService(); $settingService->set(self::SETTING_NAME, self::SETTING_VALUE_STRING); @@ -400,7 +400,7 @@ public function test_cache_is_updated_when_setting_is_set() public function test_cache_is_updated_when_setting_is_deleted() { Cache::shouldReceive('remember', 'put') - ->andReturn(collect([]), true); + ->andReturn(collect([]), true); $settingService = new SettingService(); $settingService->delete(self::SETTING_NAME); diff --git a/tests/ModelTestCase.php b/tests/ModelTestCase.php index 295300c9..b493e22c 100644 --- a/tests/ModelTestCase.php +++ b/tests/ModelTestCase.php @@ -79,7 +79,7 @@ protected function runConfigurationAssertions( * - `getForeignKey()`: any `HasOneOrMany` or `BelongsTo` relation, but key type differs (see documentaiton). * - `getQualifiedParentKeyName()`: in case of `HasOneOrMany` relation, there is no `getLocalKey()` method, so this one should be asserted. */ - protected function assertHasManyRelation($relation, Model $model, Model $related, $key = null, $parent = null, \Closure $queryCheck = null) + protected function assertHasManyRelation($relation, Model $model, Model $related, $key = null, $parent = null, ?\Closure $queryCheck = null) { $this->assertInstanceOf(HasMany::class, $relation); @@ -111,7 +111,7 @@ protected function assertHasManyRelation($relation, Model $model, Model $related * - `getForeignKey()`: any `HasOneOrMany` or `BelongsTo` relation, but key type differs (see documentaiton). * - `getOwnerKey()`: `BelongsTo` relation and its extendings. */ - protected function assertBelongsToRelation($relation, Model $model, Model $related, $key, $owner = null, \Closure $queryCheck = null) + protected function assertBelongsToRelation($relation, Model $model, Model $related, $key, $owner = null, ?\Closure $queryCheck = null) { $this->assertInstanceOf(BelongsTo::class, $relation);