diff --git a/app/Api/v1/Controllers/IconController.php b/app/Api/v1/Controllers/IconController.php index 9f258cb5..219e150a 100644 --- a/app/Api/v1/Controllers/IconController.php +++ b/app/Api/v1/Controllers/IconController.php @@ -34,8 +34,8 @@ public function upload(Request $request) $name = Helpers::getRandomFilename($icon->extension()); $isStored = IconStore::store($name, $content); } + } catch (Exception) { } - catch (Exception) { } } return $isStored diff --git a/app/Api/v1/Resources/TwoFAccountExportResource.php b/app/Api/v1/Resources/TwoFAccountExportResource.php index e7d76876..d5a514bb 100644 --- a/app/Api/v1/Resources/TwoFAccountExportResource.php +++ b/app/Api/v1/Resources/TwoFAccountExportResource.php @@ -17,6 +17,7 @@ * @property int|null $period * @property int|null $counter * @property string $legacy_uri + * * @method string getURI() */ class TwoFAccountExportResource extends JsonResource diff --git a/app/Api/v1/Resources/TwoFAccountReadResource.php b/app/Api/v1/Resources/TwoFAccountReadResource.php index 4de6c0aa..773be357 100644 --- a/app/Api/v1/Resources/TwoFAccountReadResource.php +++ b/app/Api/v1/Resources/TwoFAccountReadResource.php @@ -5,7 +5,7 @@ /** * @property mixed $id * @property mixed $group_id - * + * * @method App\Models\Dto\TotpDto|App\Models\Dto\HotpDto getOtp(int $time) */ class TwoFAccountReadResource extends TwoFAccountStoreResource diff --git a/app/Console/Commands/ResetTesting.php b/app/Console/Commands/ResetTesting.php index 39101882..6aa7fb39 100644 --- a/app/Console/Commands/ResetTesting.php +++ b/app/Console/Commands/ResetTesting.php @@ -48,7 +48,7 @@ public function __construct() public function handle() { $this->callSilently('config:clear'); - + if (! config('2fauth.config.isTestingApp') && ! $this->option('force')) { $this->comment('2fauth:reset-testing can only run when isTestingApp option is On'); diff --git a/app/Listeners/CleanIconStorage.php b/app/Listeners/CleanIconStorage.php index 9c0d1b0b..bc4e6375 100644 --- a/app/Listeners/CleanIconStorage.php +++ b/app/Listeners/CleanIconStorage.php @@ -26,7 +26,7 @@ public function __construct() public function handle(TwoFAccountDeleted $event) { IconStore::delete($event->twofaccount->icon ?? []); - + Log::info(sprintf('Icon cleaned for deleted TwoFAccount #%d', $event->twofaccount->id)); } } diff --git a/app/Listeners/ToggleIconReplicationToDatabase.php b/app/Listeners/ToggleIconReplicationToDatabase.php index a2670093..37233f31 100644 --- a/app/Listeners/ToggleIconReplicationToDatabase.php +++ b/app/Listeners/ToggleIconReplicationToDatabase.php @@ -10,14 +10,12 @@ class ToggleIconReplicationToDatabase /** * Create the event listener. */ - public function __construct() - { - } + public function __construct() {} /** * Handle the event. */ - public function handle(storeIconsInDatabaseSettingChanged $event): void + public function handle(storeIconsInDatabaseSettingChanged $event) : void { IconStore::setDatabaseReplication($event->newValue); } diff --git a/app/Models/AuthLog.php b/app/Models/AuthLog.php index 17b984dc..bb174dbb 100644 --- a/app/Models/AuthLog.php +++ b/app/Models/AuthLog.php @@ -43,7 +43,9 @@ * @property string|null $method * @property string|null $login_method * @property-read Model|\Eloquent $authenticatable + * * @mixin \Eloquent + * * @method static \Database\Factories\AuthLogFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|AuthLog newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|AuthLog newQuery() diff --git a/app/Models/Group.php b/app/Models/Group.php index f2e506dd..88ff1db8 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -20,6 +20,7 @@ * @property int|null $user_id * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TwoFAccount[] $twofaccounts * @property-read \App\Models\User|null $user + * * @method static \Database\Factories\GroupFactory factory(...$parameters) * @method static \Illuminate\Database\Eloquent\Builder|Group newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Group newQuery() @@ -29,7 +30,9 @@ * @method static \Illuminate\Database\Eloquent\Builder|Group whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereUserId($value) + * * @mixin \Eloquent + * * @method static \Illuminate\Database\Eloquent\Builder|Group orphans() */ class Group extends Model diff --git a/app/Models/Icon.php b/app/Models/Icon.php index b7bed8db..2f90119d 100644 --- a/app/Models/Icon.php +++ b/app/Models/Icon.php @@ -17,6 +17,7 @@ * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property-read \App\Models\TwoFAccount|null $twofaccount + * * @method static \Database\Factories\IconFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|Icon newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Icon newQuery() @@ -31,7 +32,7 @@ class Icon extends Model /** * @use HasFactory */ - use HasFactory, CanEncryptField; + use CanEncryptField, HasFactory; /** * The primary key for the model. @@ -40,7 +41,6 @@ class Icon extends Model */ protected $primaryKey = 'name'; - /** * The "type" of the primary key ID. * @@ -57,7 +57,7 @@ class Icon extends Model /** * Get the twofaccount that owns the icon. - * + * * @return BelongsTo<\App\Models\TwoFAccount, \App\Models\Icon> */ public function twofaccount() : BelongsTo @@ -71,7 +71,7 @@ public function twofaccount() : BelongsTo * @var array */ protected $attributes = []; - + /** * The attributes that should be hidden for arrays. * diff --git a/app/Models/Option.php b/app/Models/Option.php index ec20da66..c47ddf67 100644 --- a/app/Models/Option.php +++ b/app/Models/Option.php @@ -10,12 +10,14 @@ * @property int $id * @property string $key * @property string $value + * * @method static \Illuminate\Database\Eloquent\Builder|Option newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Option newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Option query() * @method static \Illuminate\Database\Eloquent\Builder|Option whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|Option whereKey($value) * @method static \Illuminate\Database\Eloquent\Builder|Option whereValue($value) + * * @mixin \Eloquent */ class Option extends Model diff --git a/app/Models/TwoFAccount.php b/app/Models/TwoFAccount.php index 14f89ad6..8307a84b 100644 --- a/app/Models/TwoFAccount.php +++ b/app/Models/TwoFAccount.php @@ -70,8 +70,11 @@ * @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereService($value) * @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereUserId($value) + * * @mixin \Eloquent + * * @property-read \App\Models\Icon|null $iconResource + * * @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount orphans() */ class TwoFAccount extends Model implements Sortable @@ -79,7 +82,7 @@ class TwoFAccount extends Model implements Sortable /** * @use HasFactory */ - use HasFactory, SortableTrait, CanEncryptField; + use CanEncryptField, HasFactory, SortableTrait; const TOTP = 'totp'; @@ -233,10 +236,10 @@ public function user() /** * Get the relation between the icon resource and the model. - * + * * @return HasOne<\App\Models\Icon> */ - public function iconResource(): HasOne + public function iconResource() : HasOne { return $this->hasOne(Icon::class, 'name', 'icon'); } diff --git a/app/Models/User.php b/app/Models/User.php index 60158e31..77d7760d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -47,6 +47,7 @@ * @property-read \Illuminate\Database\Eloquent\Collection $authentications * @property-read int|null $authentications_count * @property-read \App\Models\AuthLog|null $latestAuthentication + * * @method static \Illuminate\Database\Eloquent\Builder|User admins() * @method static \Database\Factories\UserFactory factory(...$parameters) * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery() @@ -63,7 +64,9 @@ * @method static \Illuminate\Database\Eloquent\Builder|User wherePreferences($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value) + * * @mixin \Eloquent + * * @method static \Illuminate\Database\Eloquent\Builder|User whereOauthId($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereOauthProvider($value) */ diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index f78fc338..8a9a6be9 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -4,8 +4,8 @@ use App\Events\GroupDeleted; use App\Events\GroupDeleting; -use App\Events\storeIconsInDatabaseSettingChanged; use App\Events\ScanForNewReleaseCalled; +use App\Events\storeIconsInDatabaseSettingChanged; use App\Events\TwoFAccountDeleted; use App\Events\VisitedByProxyUser; use App\Listeners\Authentication\FailedLoginListener; @@ -15,10 +15,10 @@ use App\Listeners\CleanIconStorage; use App\Listeners\DissociateTwofaccountFromGroup; use App\Listeners\LogNotificationListener; -use App\Listeners\ToggleIconReplicationToDatabase; use App\Listeners\RegisterOpenId; use App\Listeners\ReleaseRadar; use App\Listeners\ResetUsersPreference; +use App\Listeners\ToggleIconReplicationToDatabase; use App\Models\User; use App\Observers\UserObserver; use Illuminate\Auth\Events\Failed; diff --git a/app/Providers/TwoFAuthServiceProvider.php b/app/Providers/TwoFAuthServiceProvider.php index 77089274..4792bdfd 100644 --- a/app/Providers/TwoFAuthServiceProvider.php +++ b/app/Providers/TwoFAuthServiceProvider.php @@ -3,8 +3,8 @@ namespace App\Providers; use App\Factories\MigratorFactoryInterface; -use App\Services\IconStoreService; use App\Services\IconService; +use App\Services\IconStoreService; use App\Services\LogoService; use App\Services\ReleaseRadarService; use App\Services\SettingService; diff --git a/app/Services/IconService.php b/app/Services/IconService.php index a2ac6f06..acd7d8e9 100644 --- a/app/Services/IconService.php +++ b/app/Services/IconService.php @@ -23,7 +23,7 @@ public function buildFromOfficialLogo(?string $service) : ?string /** * Build an icon from an image resource - * + * * @param \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource $resource * @param string $extension The file extension, without the dot */ @@ -49,7 +49,7 @@ public function buildFromResource($resource, $extension) : ?string } /** - * Build an icon by fetching an image file on the internet + * Build an icon by fetching an image file on the internet */ public function buildFromRemoteImage(string $url) : ?string { @@ -67,8 +67,8 @@ public function buildFromRemoteImage(string $url) : ?string protected function storeRemoteImage(string $url) : ?string { try { - $path_parts = pathinfo($url); - $filename = Helpers::getRandomFilename($path_parts['extension']); + $path_parts = pathinfo($url); + $filename = Helpers::getRandomFilename($path_parts['extension']); try { $response = Http::withOptions([ @@ -80,7 +80,7 @@ protected function storeRemoteImage(string $url) : ?string } } catch (\Exception $exception) { Log::error(sprintf('Cannot fetch imageLink at "%s"', $url)); - + return null; } @@ -129,7 +129,7 @@ public static function isValidImageResource($filename, $content) : bool 'image/x-ms-bmp', 'image/svg+xml', ]; - + $isValid = in_array($mimeType, $acceptedMimeTypes) && ($mimeType !== 'image/svg+xml' ? getimagesize(Storage::disk('temp')->path($filename)) : true) && Str::contains($mimeType, $extension, true); diff --git a/app/Services/IconStoreService.php b/app/Services/IconStoreService.php index ed579c4f..3209cbb0 100644 --- a/app/Services/IconStoreService.php +++ b/app/Services/IconStoreService.php @@ -19,7 +19,7 @@ class IconStoreService /** * The storage disk to use */ - protected string|null $disk; + protected ?string $disk; /** * Icon replication to database to ease backup @@ -73,8 +73,7 @@ public function setDatabaseReplication(bool $usesDatabase) : void if ($usesDatabase) { $this->clearDatabase(); $this->mirrorDiskToDatabase(); - } - else { + } else { $this->mirrorDatabaseToDisk(); $this->clearDatabase(); } @@ -98,7 +97,7 @@ protected function mirrorDiskToDatabase() : void DB::commit(); } catch (\Exception $e) { DB::rollback(); - + throw new FailedIconStoreDatabaseTogglingException; } } @@ -117,14 +116,14 @@ protected function mirrorDatabaseToDisk() : void /** * Get the list of all icon names registered in the TwoFAccount table - * + * * @return Collection */ protected function registeredIcons() { return TwoFAccount::whereNotNull('icon')->pluck('icon'); } - + /** * Get the content of a given icon resource, prior to the database record */ @@ -189,7 +188,7 @@ public function delete(array|string $names) : bool $names = is_array($names) ? $names : func_get_args(); $deletedFromDisk = $this->disk()->delete($names); - + if ($deletedFromDisk && $this->usesDatabase) { Icon::destroy($names); @@ -206,7 +205,7 @@ public function store(string $name, string $content) : bool { $storedToDisk = $this->storeToDisk($name, $content); - if ($this->usesDatabase) { + if ($this->usesDatabase) { return $this->storeToDatabase($name, $content); } diff --git a/app/Services/LogoService.php b/app/Services/LogoService.php index c66f132f..27dce361 100644 --- a/app/Services/LogoService.php +++ b/app/Services/LogoService.php @@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Storage; class LogoService -{ +{ /** * @var \Illuminate\Support\Collection */ @@ -157,7 +157,7 @@ protected function cleanDomain(string $domain) : string * * @param string $logoFilename * @param string $iconFilename - * @return bool Whether the copy succeed or not + * @return bool Whether the copy succeed or not */ protected function copyToIconStore($logoFilename, $iconFilename) : bool { diff --git a/app/Services/Migrators/AegisMigrator.php b/app/Services/Migrators/AegisMigrator.php index f651c4dd..3df9b48d 100644 --- a/app/Services/Migrators/AegisMigrator.php +++ b/app/Services/Migrators/AegisMigrator.php @@ -3,8 +3,8 @@ namespace App\Services\Migrators; use App\Exceptions\InvalidMigrationDataException; -use App\Services\IconService; use App\Models\TwoFAccount; +use App\Services\IconService; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Facades\App; @@ -39,7 +39,7 @@ class AegisMigrator extends Migrator public function migrate(mixed $migrationPayload) : Collection { $iconService = App::make(IconService::class); - $json = json_decode(htmlspecialchars_decode($migrationPayload), true); + $json = json_decode(htmlspecialchars_decode($migrationPayload), true); if (is_null($json) || Arr::has($json, 'db.entries') == false) { Log::error('Aegis JSON migration data cannot be read'); diff --git a/app/Services/Migrators/TwoFAuthMigrator.php b/app/Services/Migrators/TwoFAuthMigrator.php index 7aff06d3..5f755521 100644 --- a/app/Services/Migrators/TwoFAuthMigrator.php +++ b/app/Services/Migrators/TwoFAuthMigrator.php @@ -3,8 +3,8 @@ namespace App\Services\Migrators; use App\Exceptions\InvalidMigrationDataException; -use App\Services\IconService; use App\Models\TwoFAccount; +use App\Services\IconService; use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Facades\App; @@ -43,7 +43,7 @@ class TwoFAuthMigrator extends Migrator public function migrate(mixed $migrationPayload) : Collection { $iconService = App::make(IconService::class); - $json = json_decode(htmlspecialchars_decode($migrationPayload), true); + $json = json_decode(htmlspecialchars_decode($migrationPayload), true); if (is_null($json)) { Log::error('2FAuth JSON migration data cannot be read'); diff --git a/tests/Api/v1/Controllers/IconControllerTest.php b/tests/Api/v1/Controllers/IconControllerTest.php index ccc99cda..e9bba6af 100644 --- a/tests/Api/v1/Controllers/IconControllerTest.php +++ b/tests/Api/v1/Controllers/IconControllerTest.php @@ -34,7 +34,7 @@ public function setUp() : void Storage::fake('icons'); Storage::fake('logos'); - + Http::preventStrayRequests(); Http::fake([ LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200), @@ -51,7 +51,7 @@ public function setUp() : void public function test_upload_icon_returns_filename_using_the_iconStore() { $iconName = 'testIcon.jpg'; - $file = UploadedFile::fake()->image($iconName); + $file = UploadedFile::fake()->image($iconName); $response = $this->actingAs($this->user, 'api-guard') ->json('POST', '/api/v1/icons', [ @@ -111,7 +111,7 @@ public function test_fetch_unknown_logo_returns_nothing() public function test_delete_icon_returns_success_using_the_iconStore() { IconStore::spy(); - + $iconName = 'testIcon.jpg'; $response = $this->actingAs($this->user, 'api-guard') diff --git a/tests/Api/v1/Controllers/TwoFAccountControllerTest.php b/tests/Api/v1/Controllers/TwoFAccountControllerTest.php index 51bc17e4..0f0a43e5 100644 --- a/tests/Api/v1/Controllers/TwoFAccountControllerTest.php +++ b/tests/Api/v1/Controllers/TwoFAccountControllerTest.php @@ -237,7 +237,7 @@ public function setUp() : void Storage::fake('icons'); Storage::fake('logos'); Storage::fake('imagesLink'); - + Http::preventStrayRequests(); Http::fake([ LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200), diff --git a/tests/Api/v1/Requests/TwoFAccountExportRequestTest.php b/tests/Api/v1/Requests/TwoFAccountExportRequestTest.php index 9730f418..112b405f 100644 --- a/tests/Api/v1/Requests/TwoFAccountExportRequestTest.php +++ b/tests/Api/v1/Requests/TwoFAccountExportRequestTest.php @@ -48,30 +48,30 @@ public static function provideValidData() : array { return [ [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => '1', ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => 1, ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => true, ]], [[ 'ids' => '1', ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => '0', ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => 0, ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => false, ]], ]; @@ -94,31 +94,31 @@ public static function provideInvalidData() : array { return [ [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => null, ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => '', ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => 2, ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => 'string', ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => 0.1, ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => '01/01/2020', ]], [[ - 'ids' => '1', + 'ids' => '1', 'otpauth' => '01', ]], ]; diff --git a/tests/Feature/Models/TwoFAccountModelTest.php b/tests/Feature/Models/TwoFAccountModelTest.php index d802d50e..441c9c73 100644 --- a/tests/Feature/Models/TwoFAccountModelTest.php +++ b/tests/Feature/Models/TwoFAccountModelTest.php @@ -49,7 +49,7 @@ public function setUp() : void Storage::fake('imagesLink'); Storage::fake('icons'); - + Http::preventStrayRequests(); /** @var \Illuminate\Contracts\Auth\Authenticatable $user */ @@ -671,7 +671,7 @@ public function test_scopeOrphans_retreives_accounts_without_owner() Http::fake([ OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response(HttpRequestTestData::ICON_PNG, 200), ]); - + $orphan = new TwoFAccount; $orphan->fillWithURI(OtpTestData::HOTP_FULL_CUSTOM_URI); $orphan->save(); diff --git a/tests/Feature/Models/UserModelTest.php b/tests/Feature/Models/UserModelTest.php index 18cf783d..f6b15c9c 100644 --- a/tests/Feature/Models/UserModelTest.php +++ b/tests/Feature/Models/UserModelTest.php @@ -4,7 +4,6 @@ use App\Facades\IconStore; use App\Models\AuthLog; -use App\Models\Dto\IconDto; use App\Models\Group; use App\Models\TwoFAccount; use App\Models\User; @@ -174,7 +173,7 @@ public function test_delete_flushes_icons_of_user_twofaccounts() 'icon' => OtpTestData::ICON_PNG, ]); IconStore::store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA)); - + Storage::disk('icons')->assertExists($twofaccount->icon); $user->delete(); diff --git a/tests/Feature/Services/IconServiceTest.php b/tests/Feature/Services/IconServiceTest.php index 10081dee..a7faa526 100644 --- a/tests/Feature/Services/IconServiceTest.php +++ b/tests/Feature/Services/IconServiceTest.php @@ -34,11 +34,11 @@ class IconServiceTest extends FeatureTestCase public function setUp() : void { parent::setUp(); - + Storage::fake('icons'); Storage::fake('logos'); Storage::fake('imagesLink'); - + Http::preventStrayRequests(); Http::fake([ LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200), @@ -63,11 +63,11 @@ public function test_buildFromOfficialLogo_calls_logoservice_to_get_the_icon() #[Test] public function test_buildFromResource_stores_icon_and_returns_name() { - $resource = base64_decode(OtpTestData::ICON_PNG_DATA); + $resource = base64_decode(OtpTestData::ICON_PNG_DATA); $extension = 'png'; $this->iconService = $this->app->make(IconService::class); - $iconName = $this->iconService->buildFromResource($resource, $extension); + $iconName = $this->iconService->buildFromResource($resource, $extension); Storage::disk('icons')->assertExists($iconName); $this->assertEquals($resource, Storage::disk('icons')->get($iconName)); @@ -80,7 +80,7 @@ public function test_buildFromResource_returns_null_when_store_fails() ->andReturn(false); $this->iconService = $this->app->make(IconService::class); - $iconName = $this->iconService->buildFromResource('lorem', 'ipsum'); + $iconName = $this->iconService->buildFromResource('lorem', 'ipsum'); $this->assertNull($iconName); } @@ -90,7 +90,7 @@ public function test_buildFromResource_returns_null_when_store_fails() public function test_buildFromResource_with_bad_inputs_returns_null($resource, $extension) { $this->iconService = $this->app->make(IconService::class); - $iconName = $this->iconService->buildFromResource($resource, $extension); + $iconName = $this->iconService->buildFromResource($resource, $extension); $this->assertNull($iconName); } @@ -149,7 +149,7 @@ public function test_buildFromRemoteImage_stores_icon_and_returns_name($name, $b ]); $this->iconService = $this->app->make(IconService::class); - $iconName = $this->iconService->buildFromRemoteImage($imageUrl); + $iconName = $this->iconService->buildFromRemoteImage($imageUrl); Storage::disk('icons')->assertExists($iconName); Storage::disk('imagesLink')->assertMissing($iconName); @@ -174,7 +174,7 @@ public function test_buildFromRemoteImage_returns_null_when_url_is_invalid() ->andReturn(false); $this->iconService = $this->app->make(IconService::class); - $iconName = $this->iconService->buildFromRemoteImage($imageUrl); + $iconName = $this->iconService->buildFromRemoteImage($imageUrl); $this->assertNull($iconName); } @@ -203,11 +203,11 @@ public function test_buildFromRemoteImage_returns_null_when_remote_img_is_unreac Http::fake([ 'example.com/*' => Http::response(null, 400), ]); - + $imageUrl = 'https://www.example.com/image.png'; $this->iconService = $this->app->make(IconService::class); - $iconName = $this->iconService->buildFromRemoteImage($imageUrl); + $iconName = $this->iconService->buildFromRemoteImage($imageUrl); $this->assertNull($iconName); } @@ -223,7 +223,7 @@ public function test_buildFromRemoteImage_returns_null_when_remote_img_is_not_su ]); $this->iconService = $this->app->make(IconService::class); - $iconName = $this->iconService->buildFromRemoteImage($imageUrl); + $iconName = $this->iconService->buildFromRemoteImage($imageUrl); $this->assertNull($iconName); } @@ -240,8 +240,8 @@ public function test_buildFromRemoteImage_returns_null_when_remote_img_is_not_va ]); $this->iconService = $this->app->make(IconService::class); - $iconName = $this->iconService->buildFromRemoteImage($imageUrl); + $iconName = $this->iconService->buildFromRemoteImage($imageUrl); $this->assertNull($iconName); } -} \ No newline at end of file +} diff --git a/tests/Feature/Services/IconStoreServiceTest.php b/tests/Feature/Services/IconStoreServiceTest.php index f2ea83c3..19c35621 100644 --- a/tests/Feature/Services/IconStoreServiceTest.php +++ b/tests/Feature/Services/IconStoreServiceTest.php @@ -40,7 +40,7 @@ public function setUp() : void Storage::fake('icons'); $this->iconStore = $this->app->make(IconStoreService::class); } - + #[Test] public function test_get_returns_icon_content() { @@ -90,7 +90,7 @@ public function test_mimeType_returns_correct_mimetype($name, $base64content, $e $this->assertStringContainsStringIgnoringCase($mimeType, $expected); } - + /** * Provide data for index tests */ @@ -115,7 +115,7 @@ public static function supportedMimeTypesProvider() 'BPM' => [ OtpTestData::ICON_BMP, OtpTestData::ICON_BMP_DATA, - 'image/bmp|image/x-ms-bmp' + 'image/bmp|image/x-ms-bmp', ], 'SVG' => [ OtpTestData::ICON_SVG, @@ -140,7 +140,7 @@ public function test_mimeType_returns_null_when_icon_is_missing() { $this->assertFalse($this->iconStore->mimeType(OtpTestData::ICON_PNG)); } - + #[Test] public function test_mimeType_returns_null_when_nothing_is_requested() { @@ -183,10 +183,10 @@ public function test_clear_deletes_all_icons_in_database_and_returns_true() Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG); Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_JPEG, + 'name' => OtpTestData::ICON_JPEG, ]); $result = $this->iconStore->clear(); @@ -218,10 +218,10 @@ public function test_clear_empty_disk_deletes_icons_in_database() ]); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_JPEG, + 'name' => OtpTestData::ICON_JPEG, ]); $result = $this->iconStore->clear(); @@ -272,23 +272,23 @@ public function test_delete_deletes_provided_icon_and_returns_true() public function test_delete_deletes_provided_icon_in_database_and_returns_true() { Settings::set('storeIconsInDatabase', true); - + Storage::disk('icons')->put(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA)); DB::table('icons')->insert([ 'name' => OtpTestData::ICON_PNG, 'content' => OtpTestData::ICON_PNG_DATA, ]); - + Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); $this->iconStore->delete(OtpTestData::ICON_PNG); Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG); $this->assertDatabaseMissing('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); } @@ -296,21 +296,21 @@ public function test_delete_deletes_provided_icon_in_database_and_returns_true() public function test_delete_deletes_provided_icon_in_database_when_disk_is_empty() { Settings::set('storeIconsInDatabase', true); - + DB::table('icons')->insert([ 'name' => OtpTestData::ICON_PNG, 'content' => OtpTestData::ICON_PNG_DATA, ]); - + Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); $this->iconStore->delete(OtpTestData::ICON_PNG); $this->assertDatabaseMissing('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); } @@ -336,7 +336,7 @@ public function test_delete_deletes_provided_icons_and_returns_true() public function test_delete_deletes_provided_icons_in_database_and_returns_true() { Settings::set('storeIconsInDatabase', true); - + Storage::disk('icons')->put(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA)); Storage::disk('icons')->put(OtpTestData::ICON_JPEG, base64_decode(OtpTestData::ICON_JPEG_DATA)); DB::table('icons')->insert([ @@ -351,10 +351,10 @@ public function test_delete_deletes_provided_icons_in_database_and_returns_true( Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG); Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_JPEG, + 'name' => OtpTestData::ICON_JPEG, ]); $this->iconStore->delete([ @@ -365,10 +365,10 @@ public function test_delete_deletes_provided_icons_in_database_and_returns_true( Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG); Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG); $this->assertDatabaseMissing('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); $this->assertDatabaseMissing('icons', [ - 'name' => OtpTestData::ICON_JPEG, + 'name' => OtpTestData::ICON_JPEG, ]); } @@ -376,7 +376,7 @@ public function test_delete_deletes_provided_icons_in_database_and_returns_true( public function test_delete_deletes_provided_icons_in_database_when_disk_is_empty() { Settings::set('storeIconsInDatabase', true); - + DB::table('icons')->insert([ 'name' => OtpTestData::ICON_PNG, 'content' => OtpTestData::ICON_PNG_DATA, @@ -389,10 +389,10 @@ public function test_delete_deletes_provided_icons_in_database_when_disk_is_empt Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG); Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_JPEG, + 'name' => OtpTestData::ICON_JPEG, ]); $this->iconStore->delete([ @@ -401,10 +401,10 @@ public function test_delete_deletes_provided_icons_in_database_when_disk_is_empt ]); $this->assertDatabaseMissing('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); $this->assertDatabaseMissing('icons', [ - 'name' => OtpTestData::ICON_JPEG, + 'name' => OtpTestData::ICON_JPEG, ]); } @@ -458,7 +458,7 @@ public function test_store_writes_the_icon_to_disk_and_database_and_returns_true Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG); $this->assertDatabaseMissing('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); $result = $this->iconStore->store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA)); @@ -466,7 +466,7 @@ public function test_store_writes_the_icon_to_disk_and_database_and_returns_true $this->assertTrue($result); Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG); $this->assertDatabaseHas('icons', [ - 'name' => OtpTestData::ICON_PNG, + 'name' => OtpTestData::ICON_PNG, ]); } @@ -481,7 +481,7 @@ public function test_store_returns_false_when_it_fails() Storage::shouldReceive('disk->put') ->with($iconName, $iconContent) ->andReturn(false); - + $result = $this->iconStore->store($iconName, $iconContent); $this->assertFalse($result); @@ -553,7 +553,7 @@ public function test_setDatabaseReplication_stores_icon_files_to_database() #[Test] public function test_setDatabaseReplication_stores_only_registered_icon_to_database() { - $user = User::factory()->create(); + $user = User::factory()->create(); TwoFAccount::factory()->for($user)->create([ 'icon' => OtpTestData::ICON_PNG, @@ -594,7 +594,7 @@ public function test_setDatabaseReplication_clears_database_before_replication() #[Test] public function test_setDatabaseReplication_skips_icon_when_file_is_missing() { - $user = User::factory()->create(); + $user = User::factory()->create(); TwoFAccount::factory()->for($user)->create([ 'icon' => OtpTestData::ICON_PNG, @@ -644,7 +644,7 @@ public function test_setDatabaseReplication_overrides_existing_files_during_rest { Settings::set('storeIconsInDatabase', true); - $user = User::factory()->create(); + $user = User::factory()->create(); TwoFAccount::factory()->for($user)->create([ 'icon' => OtpTestData::ICON_PNG, @@ -721,9 +721,9 @@ public function test_setDatabaseReplication_Off_sends_exception_and_does_nothing ]); Storage::shouldReceive('disk->put') - ->once() - ->andThrow(new FailedIconStoreDatabaseTogglingException); - + ->once() + ->andThrow(new FailedIconStoreDatabaseTogglingException); + $this->expectException(FailedIconStoreDatabaseTogglingException::class); Settings::set('storeIconsInDatabase', false); diff --git a/tests/Feature/Services/LogoServiceTest.php b/tests/Feature/Services/LogoServiceTest.php index 521247dd..25e08398 100644 --- a/tests/Feature/Services/LogoServiceTest.php +++ b/tests/Feature/Services/LogoServiceTest.php @@ -52,7 +52,7 @@ public function test_getIcon_returns_null_when_github_request_fails() Http::preventStrayRequests(); Http::fake([ LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200), - LogoService::TFA_URL => Http::response('not found', 404), + LogoService::TFA_URL => Http::response('not found', 404), ]); $this->logoService = $this->app->make(LogoService::class); @@ -97,7 +97,7 @@ public function test_logoService_loads_empty_collection_when_tfajson_fetching_fa Http::preventStrayRequests(); Http::fake([ LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200), - LogoService::TFA_URL => Http::response('not found', 404), + LogoService::TFA_URL => Http::response('not found', 404), ]); $this->logoService = $this->app->make(LogoService::class); diff --git a/tests/Feature/Services/SettingServiceTest.php b/tests/Feature/Services/SettingServiceTest.php index c61443eb..e640a256 100644 --- a/tests/Feature/Services/SettingServiceTest.php +++ b/tests/Feature/Services/SettingServiceTest.php @@ -8,13 +8,11 @@ use App\Facades\Settings; use App\Models\Icon; use App\Models\TwoFAccount; -use App\Services\IconStoreService; use App\Services\SettingService; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; -use Mockery\MockInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -396,7 +394,7 @@ public function test_set_storeIconsInDatabase_setting_impacts_the_icon_store() public function test_set_storeIconsInDatabase_is_cancelled_if_database_toggling_failed() { $this->expectException(FailedIconStoreDatabaseTogglingException::class); - + $newValue = true; IconStore::shouldReceive('setDatabaseReplication') diff --git a/tests/Unit/Events/storeIconsInDatabaseSettingChangedTest.php b/tests/Unit/Events/storeIconsInDatabaseSettingChangedTest.php index 69d4120c..5e954524 100644 --- a/tests/Unit/Events/storeIconsInDatabaseSettingChangedTest.php +++ b/tests/Unit/Events/storeIconsInDatabaseSettingChangedTest.php @@ -17,7 +17,7 @@ class storeIconsInDatabaseSettingChangedTest extends TestCase public function test_event_constructor() { $newValue = true; - $event = new storeIconsInDatabaseSettingChanged($newValue); + $event = new storeIconsInDatabaseSettingChanged($newValue); $this->assertSame($newValue, $event->newValue); } diff --git a/tests/Unit/Listeners/CleanIconStorageTest.php b/tests/Unit/Listeners/CleanIconStorageTest.php index 36fb4508..e77226c1 100644 --- a/tests/Unit/Listeners/CleanIconStorageTest.php +++ b/tests/Unit/Listeners/CleanIconStorageTest.php @@ -3,7 +3,6 @@ namespace Tests\Unit\Listeners; use App\Events\TwoFAccountDeleted; -use App\Facades\Settings; use App\Listeners\CleanIconStorage; use App\Models\TwoFAccount; use App\Services\IconStoreService; @@ -42,7 +41,7 @@ public function test_it_deletes_icon_file_using_the_iconstore() ->with($event->twofaccount->icon) ->andReturn(true); }); - + /** * @disregard P1009 Undefined type */ diff --git a/tests/Unit/MigratorTest.php b/tests/Unit/MigratorTest.php index 367f8e05..37f0a4e5 100644 --- a/tests/Unit/MigratorTest.php +++ b/tests/Unit/MigratorTest.php @@ -6,7 +6,6 @@ use App\Exceptions\InvalidMigrationDataException; use App\Exceptions\UnsupportedMigrationException; use App\Facades\Icons; -use App\Facades\IconStore; use App\Factories\MigratorFactory; use App\Models\TwoFAccount; use App\Providers\MigrationServiceProvider; @@ -416,13 +415,13 @@ public function test_migrate_2fauth_payload_with_icon_sets_and_stores_the_icon($ { Icons::spy(); Storage::fake('icons'); - + $migrator = new TwoFAuthMigrator; $accounts = $migrator->migrate($migration); - + $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts); $this->assertCount(1, $accounts); - + Icons::shouldHaveReceived('buildFromResource')->once(); Storage::disk('icons')->assertExists($accounts->first()->icon); } diff --git a/tests/Unit/TwoFAccountModelTest.php b/tests/Unit/TwoFAccountModelTest.php index a454bde2..f14fdcb2 100644 --- a/tests/Unit/TwoFAccountModelTest.php +++ b/tests/Unit/TwoFAccountModelTest.php @@ -149,7 +149,7 @@ public function test_user_relation() #[Test] public function test_twofaccount_relation() { - $model = new Icon(); + $model = new Icon; $relation = $model->twofaccount(); $this->assertInstanceOf(BelongsTo::class, $relation);