Fix pint issues

This commit is contained in:
Bubka 2024-11-09 10:18:45 +01:00
parent 6158c6940b
commit fee7a684b2
32 changed files with 126 additions and 120 deletions

View File

@ -34,8 +34,8 @@ class IconController extends Controller
$name = Helpers::getRandomFilename($icon->extension()); $name = Helpers::getRandomFilename($icon->extension());
$isStored = IconStore::store($name, $content); $isStored = IconStore::store($name, $content);
} }
} catch (Exception) {
} }
catch (Exception) { }
} }
return $isStored return $isStored

View File

@ -17,6 +17,7 @@ use Illuminate\Http\Resources\Json\JsonResource;
* @property int|null $period * @property int|null $period
* @property int|null $counter * @property int|null $counter
* @property string $legacy_uri * @property string $legacy_uri
*
* @method string getURI() * @method string getURI()
*/ */
class TwoFAccountExportResource extends JsonResource class TwoFAccountExportResource extends JsonResource

View File

@ -10,14 +10,12 @@ class ToggleIconReplicationToDatabase
/** /**
* Create the event listener. * Create the event listener.
*/ */
public function __construct() public function __construct() {}
{
}
/** /**
* Handle the event. * Handle the event.
*/ */
public function handle(storeIconsInDatabaseSettingChanged $event): void public function handle(storeIconsInDatabaseSettingChanged $event) : void
{ {
IconStore::setDatabaseReplication($event->newValue); IconStore::setDatabaseReplication($event->newValue);
} }

View File

@ -43,7 +43,9 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
* @property string|null $method * @property string|null $method
* @property string|null $login_method * @property string|null $login_method
* @property-read Model|\Eloquent $authenticatable * @property-read Model|\Eloquent $authenticatable
*
* @mixin \Eloquent * @mixin \Eloquent
*
* @method static \Database\Factories\AuthLogFactory factory($count = null, $state = []) * @method static \Database\Factories\AuthLogFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|AuthLog newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|AuthLog newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|AuthLog newQuery() * @method static \Illuminate\Database\Eloquent\Builder|AuthLog newQuery()

View File

@ -20,6 +20,7 @@ use Illuminate\Support\Facades\Log;
* @property int|null $user_id * @property int|null $user_id
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TwoFAccount[] $twofaccounts * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TwoFAccount[] $twofaccounts
* @property-read \App\Models\User|null $user * @property-read \App\Models\User|null $user
*
* @method static \Database\Factories\GroupFactory factory(...$parameters) * @method static \Database\Factories\GroupFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|Group newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Group newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Group newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Group newQuery()
@ -29,7 +30,9 @@ use Illuminate\Support\Facades\Log;
* @method static \Illuminate\Database\Eloquent\Builder|Group whereName($value) * @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 whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Group whereUserId($value) * @method static \Illuminate\Database\Eloquent\Builder|Group whereUserId($value)
*
* @mixin \Eloquent * @mixin \Eloquent
*
* @method static \Illuminate\Database\Eloquent\Builder|Group orphans() * @method static \Illuminate\Database\Eloquent\Builder|Group orphans()
*/ */
class Group extends Model class Group extends Model

View File

@ -17,6 +17,7 @@ use Illuminate\Support\Facades\App;
* @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at * @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\TwoFAccount|null $twofaccount * @property-read \App\Models\TwoFAccount|null $twofaccount
*
* @method static \Database\Factories\IconFactory factory($count = null, $state = []) * @method static \Database\Factories\IconFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Icon newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Icon newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Icon newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Icon newQuery()
@ -31,7 +32,7 @@ class Icon extends Model
/** /**
* @use HasFactory<IconFactory> * @use HasFactory<IconFactory>
*/ */
use HasFactory, CanEncryptField; use CanEncryptField, HasFactory;
/** /**
* The primary key for the model. * The primary key for the model.
@ -40,7 +41,6 @@ class Icon extends Model
*/ */
protected $primaryKey = 'name'; protected $primaryKey = 'name';
/** /**
* The "type" of the primary key ID. * The "type" of the primary key ID.
* *

View File

@ -10,12 +10,14 @@ use Illuminate\Database\Eloquent\Model;
* @property int $id * @property int $id
* @property string $key * @property string $key
* @property string $value * @property string $value
*
* @method static \Illuminate\Database\Eloquent\Builder|Option newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Option newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Option newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Option newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Option query() * @method static \Illuminate\Database\Eloquent\Builder|Option query()
* @method static \Illuminate\Database\Eloquent\Builder|Option whereId($value) * @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 whereKey($value)
* @method static \Illuminate\Database\Eloquent\Builder|Option whereValue($value) * @method static \Illuminate\Database\Eloquent\Builder|Option whereValue($value)
*
* @mixin \Eloquent * @mixin \Eloquent
*/ */
class Option extends Model class Option extends Model

View File

@ -70,8 +70,11 @@ use SteamTotp\SteamTotp;
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereService($value) * @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 whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereUserId($value) * @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereUserId($value)
*
* @mixin \Eloquent * @mixin \Eloquent
*
* @property-read \App\Models\Icon|null $iconResource * @property-read \App\Models\Icon|null $iconResource
*
* @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount orphans() * @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount orphans()
*/ */
class TwoFAccount extends Model implements Sortable class TwoFAccount extends Model implements Sortable
@ -79,7 +82,7 @@ class TwoFAccount extends Model implements Sortable
/** /**
* @use HasFactory<TwoFAccountFactory> * @use HasFactory<TwoFAccountFactory>
*/ */
use HasFactory, SortableTrait, CanEncryptField; use CanEncryptField, HasFactory, SortableTrait;
const TOTP = 'totp'; const TOTP = 'totp';
@ -236,7 +239,7 @@ class TwoFAccount extends Model implements Sortable
* *
* @return HasOne<\App\Models\Icon> * @return HasOne<\App\Models\Icon>
*/ */
public function iconResource(): HasOne public function iconResource() : HasOne
{ {
return $this->hasOne(Icon::class, 'name', 'icon'); return $this->hasOne(Icon::class, 'name', 'icon');
} }

View File

@ -47,6 +47,7 @@ use Laravel\Passport\HasApiTokens;
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\AuthLog> $authentications * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\AuthLog> $authentications
* @property-read int|null $authentications_count * @property-read int|null $authentications_count
* @property-read \App\Models\AuthLog|null $latestAuthentication * @property-read \App\Models\AuthLog|null $latestAuthentication
*
* @method static \Illuminate\Database\Eloquent\Builder|User admins() * @method static \Illuminate\Database\Eloquent\Builder|User admins()
* @method static \Database\Factories\UserFactory factory(...$parameters) * @method static \Database\Factories\UserFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
@ -63,7 +64,9 @@ use Laravel\Passport\HasApiTokens;
* @method static \Illuminate\Database\Eloquent\Builder|User wherePreferences($value) * @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 whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
*
* @mixin \Eloquent * @mixin \Eloquent
*
* @method static \Illuminate\Database\Eloquent\Builder|User whereOauthId($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereOauthId($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereOauthProvider($value) * @method static \Illuminate\Database\Eloquent\Builder|User whereOauthProvider($value)
*/ */

View File

@ -4,8 +4,8 @@ namespace App\Providers;
use App\Events\GroupDeleted; use App\Events\GroupDeleted;
use App\Events\GroupDeleting; use App\Events\GroupDeleting;
use App\Events\storeIconsInDatabaseSettingChanged;
use App\Events\ScanForNewReleaseCalled; use App\Events\ScanForNewReleaseCalled;
use App\Events\storeIconsInDatabaseSettingChanged;
use App\Events\TwoFAccountDeleted; use App\Events\TwoFAccountDeleted;
use App\Events\VisitedByProxyUser; use App\Events\VisitedByProxyUser;
use App\Listeners\Authentication\FailedLoginListener; use App\Listeners\Authentication\FailedLoginListener;
@ -15,10 +15,10 @@ use App\Listeners\Authentication\VisitedByProxyUserListener;
use App\Listeners\CleanIconStorage; use App\Listeners\CleanIconStorage;
use App\Listeners\DissociateTwofaccountFromGroup; use App\Listeners\DissociateTwofaccountFromGroup;
use App\Listeners\LogNotificationListener; use App\Listeners\LogNotificationListener;
use App\Listeners\ToggleIconReplicationToDatabase;
use App\Listeners\RegisterOpenId; use App\Listeners\RegisterOpenId;
use App\Listeners\ReleaseRadar; use App\Listeners\ReleaseRadar;
use App\Listeners\ResetUsersPreference; use App\Listeners\ResetUsersPreference;
use App\Listeners\ToggleIconReplicationToDatabase;
use App\Models\User; use App\Models\User;
use App\Observers\UserObserver; use App\Observers\UserObserver;
use Illuminate\Auth\Events\Failed; use Illuminate\Auth\Events\Failed;

View File

@ -3,8 +3,8 @@
namespace App\Providers; namespace App\Providers;
use App\Factories\MigratorFactoryInterface; use App\Factories\MigratorFactoryInterface;
use App\Services\IconStoreService;
use App\Services\IconService; use App\Services\IconService;
use App\Services\IconStoreService;
use App\Services\LogoService; use App\Services\LogoService;
use App\Services\ReleaseRadarService; use App\Services\ReleaseRadarService;
use App\Services\SettingService; use App\Services\SettingService;

View File

@ -67,8 +67,8 @@ class IconService
protected function storeRemoteImage(string $url) : ?string protected function storeRemoteImage(string $url) : ?string
{ {
try { try {
$path_parts = pathinfo($url); $path_parts = pathinfo($url);
$filename = Helpers::getRandomFilename($path_parts['extension']); $filename = Helpers::getRandomFilename($path_parts['extension']);
try { try {
$response = Http::withOptions([ $response = Http::withOptions([

View File

@ -19,7 +19,7 @@ class IconStoreService
/** /**
* The storage disk to use * The storage disk to use
*/ */
protected string|null $disk; protected ?string $disk;
/** /**
* Icon replication to database to ease backup * Icon replication to database to ease backup
@ -73,8 +73,7 @@ class IconStoreService
if ($usesDatabase) { if ($usesDatabase) {
$this->clearDatabase(); $this->clearDatabase();
$this->mirrorDiskToDatabase(); $this->mirrorDiskToDatabase();
} } else {
else {
$this->mirrorDatabaseToDisk(); $this->mirrorDatabaseToDisk();
$this->clearDatabase(); $this->clearDatabase();
} }

View File

@ -157,7 +157,7 @@ class LogoService
* *
* @param string $logoFilename * @param string $logoFilename
* @param string $iconFilename * @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 protected function copyToIconStore($logoFilename, $iconFilename) : bool
{ {

View File

@ -3,8 +3,8 @@
namespace App\Services\Migrators; namespace App\Services\Migrators;
use App\Exceptions\InvalidMigrationDataException; use App\Exceptions\InvalidMigrationDataException;
use App\Services\IconService;
use App\Models\TwoFAccount; use App\Models\TwoFAccount;
use App\Services\IconService;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
@ -39,7 +39,7 @@ class AegisMigrator extends Migrator
public function migrate(mixed $migrationPayload) : Collection public function migrate(mixed $migrationPayload) : Collection
{ {
$iconService = App::make(IconService::class); $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) { if (is_null($json) || Arr::has($json, 'db.entries') == false) {
Log::error('Aegis JSON migration data cannot be read'); Log::error('Aegis JSON migration data cannot be read');

View File

@ -3,8 +3,8 @@
namespace App\Services\Migrators; namespace App\Services\Migrators;
use App\Exceptions\InvalidMigrationDataException; use App\Exceptions\InvalidMigrationDataException;
use App\Services\IconService;
use App\Models\TwoFAccount; use App\Models\TwoFAccount;
use App\Services\IconService;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
@ -43,7 +43,7 @@ class TwoFAuthMigrator extends Migrator
public function migrate(mixed $migrationPayload) : Collection public function migrate(mixed $migrationPayload) : Collection
{ {
$iconService = App::make(IconService::class); $iconService = App::make(IconService::class);
$json = json_decode(htmlspecialchars_decode($migrationPayload), true); $json = json_decode(htmlspecialchars_decode($migrationPayload), true);
if (is_null($json)) { if (is_null($json)) {
Log::error('2FAuth JSON migration data cannot be read'); Log::error('2FAuth JSON migration data cannot be read');

View File

@ -51,7 +51,7 @@ class IconControllerTest extends FeatureTestCase
public function test_upload_icon_returns_filename_using_the_iconStore() public function test_upload_icon_returns_filename_using_the_iconStore()
{ {
$iconName = 'testIcon.jpg'; $iconName = 'testIcon.jpg';
$file = UploadedFile::fake()->image($iconName); $file = UploadedFile::fake()->image($iconName);
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')
->json('POST', '/api/v1/icons', [ ->json('POST', '/api/v1/icons', [

View File

@ -48,30 +48,30 @@ class TwoFAccountExportRequestTest extends TestCase
{ {
return [ return [
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => '1', 'otpauth' => '1',
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => 1, 'otpauth' => 1,
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => true, 'otpauth' => true,
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => '0', 'otpauth' => '0',
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => 0, 'otpauth' => 0,
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => false, 'otpauth' => false,
]], ]],
]; ];
@ -94,31 +94,31 @@ class TwoFAccountExportRequestTest extends TestCase
{ {
return [ return [
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => null, 'otpauth' => null,
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => '', 'otpauth' => '',
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => 2, 'otpauth' => 2,
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => 'string', 'otpauth' => 'string',
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => 0.1, 'otpauth' => 0.1,
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => '01/01/2020', 'otpauth' => '01/01/2020',
]], ]],
[[ [[
'ids' => '1', 'ids' => '1',
'otpauth' => '01', 'otpauth' => '01',
]], ]],
]; ];

View File

@ -4,7 +4,6 @@ namespace Tests\Feature\Models;
use App\Facades\IconStore; use App\Facades\IconStore;
use App\Models\AuthLog; use App\Models\AuthLog;
use App\Models\Dto\IconDto;
use App\Models\Group; use App\Models\Group;
use App\Models\TwoFAccount; use App\Models\TwoFAccount;
use App\Models\User; use App\Models\User;

View File

@ -63,11 +63,11 @@ class IconServiceTest extends FeatureTestCase
#[Test] #[Test]
public function test_buildFromResource_stores_icon_and_returns_name() 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'; $extension = 'png';
$this->iconService = $this->app->make(IconService::class); $this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromResource($resource, $extension); $iconName = $this->iconService->buildFromResource($resource, $extension);
Storage::disk('icons')->assertExists($iconName); Storage::disk('icons')->assertExists($iconName);
$this->assertEquals($resource, Storage::disk('icons')->get($iconName)); $this->assertEquals($resource, Storage::disk('icons')->get($iconName));
@ -80,7 +80,7 @@ class IconServiceTest extends FeatureTestCase
->andReturn(false); ->andReturn(false);
$this->iconService = $this->app->make(IconService::class); $this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromResource('lorem', 'ipsum'); $iconName = $this->iconService->buildFromResource('lorem', 'ipsum');
$this->assertNull($iconName); $this->assertNull($iconName);
} }
@ -90,7 +90,7 @@ class IconServiceTest extends FeatureTestCase
public function test_buildFromResource_with_bad_inputs_returns_null($resource, $extension) public function test_buildFromResource_with_bad_inputs_returns_null($resource, $extension)
{ {
$this->iconService = $this->app->make(IconService::class); $this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromResource($resource, $extension); $iconName = $this->iconService->buildFromResource($resource, $extension);
$this->assertNull($iconName); $this->assertNull($iconName);
} }
@ -149,7 +149,7 @@ class IconServiceTest extends FeatureTestCase
]); ]);
$this->iconService = $this->app->make(IconService::class); $this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl); $iconName = $this->iconService->buildFromRemoteImage($imageUrl);
Storage::disk('icons')->assertExists($iconName); Storage::disk('icons')->assertExists($iconName);
Storage::disk('imagesLink')->assertMissing($iconName); Storage::disk('imagesLink')->assertMissing($iconName);
@ -174,7 +174,7 @@ class IconServiceTest extends FeatureTestCase
->andReturn(false); ->andReturn(false);
$this->iconService = $this->app->make(IconService::class); $this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl); $iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$this->assertNull($iconName); $this->assertNull($iconName);
} }
@ -207,7 +207,7 @@ class IconServiceTest extends FeatureTestCase
$imageUrl = 'https://www.example.com/image.png'; $imageUrl = 'https://www.example.com/image.png';
$this->iconService = $this->app->make(IconService::class); $this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl); $iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$this->assertNull($iconName); $this->assertNull($iconName);
} }
@ -223,7 +223,7 @@ class IconServiceTest extends FeatureTestCase
]); ]);
$this->iconService = $this->app->make(IconService::class); $this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl); $iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$this->assertNull($iconName); $this->assertNull($iconName);
} }
@ -240,7 +240,7 @@ class IconServiceTest extends FeatureTestCase
]); ]);
$this->iconService = $this->app->make(IconService::class); $this->iconService = $this->app->make(IconService::class);
$iconName = $this->iconService->buildFromRemoteImage($imageUrl); $iconName = $this->iconService->buildFromRemoteImage($imageUrl);
$this->assertNull($iconName); $this->assertNull($iconName);
} }

View File

@ -115,7 +115,7 @@ class IconStoreServiceTest extends FeatureTestCase
'BPM' => [ 'BPM' => [
OtpTestData::ICON_BMP, OtpTestData::ICON_BMP,
OtpTestData::ICON_BMP_DATA, OtpTestData::ICON_BMP_DATA,
'image/bmp|image/x-ms-bmp' 'image/bmp|image/x-ms-bmp',
], ],
'SVG' => [ 'SVG' => [
OtpTestData::ICON_SVG, OtpTestData::ICON_SVG,
@ -183,10 +183,10 @@ class IconStoreServiceTest extends FeatureTestCase
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG); Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG); Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_JPEG, 'name' => OtpTestData::ICON_JPEG,
]); ]);
$result = $this->iconStore->clear(); $result = $this->iconStore->clear();
@ -218,10 +218,10 @@ class IconStoreServiceTest extends FeatureTestCase
]); ]);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_JPEG, 'name' => OtpTestData::ICON_JPEG,
]); ]);
$result = $this->iconStore->clear(); $result = $this->iconStore->clear();
@ -281,14 +281,14 @@ class IconStoreServiceTest extends FeatureTestCase
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG); Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
$this->iconStore->delete(OtpTestData::ICON_PNG); $this->iconStore->delete(OtpTestData::ICON_PNG);
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG); Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
$this->assertDatabaseMissing('icons', [ $this->assertDatabaseMissing('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
} }
@ -304,13 +304,13 @@ class IconStoreServiceTest extends FeatureTestCase
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG); Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
$this->iconStore->delete(OtpTestData::ICON_PNG); $this->iconStore->delete(OtpTestData::ICON_PNG);
$this->assertDatabaseMissing('icons', [ $this->assertDatabaseMissing('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
} }
@ -351,10 +351,10 @@ class IconStoreServiceTest extends FeatureTestCase
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG); Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG); Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_JPEG, 'name' => OtpTestData::ICON_JPEG,
]); ]);
$this->iconStore->delete([ $this->iconStore->delete([
@ -365,10 +365,10 @@ class IconStoreServiceTest extends FeatureTestCase
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG); Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG); Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG);
$this->assertDatabaseMissing('icons', [ $this->assertDatabaseMissing('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
$this->assertDatabaseMissing('icons', [ $this->assertDatabaseMissing('icons', [
'name' => OtpTestData::ICON_JPEG, 'name' => OtpTestData::ICON_JPEG,
]); ]);
} }
@ -389,10 +389,10 @@ class IconStoreServiceTest extends FeatureTestCase
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG); Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG); Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_JPEG, 'name' => OtpTestData::ICON_JPEG,
]); ]);
$this->iconStore->delete([ $this->iconStore->delete([
@ -401,10 +401,10 @@ class IconStoreServiceTest extends FeatureTestCase
]); ]);
$this->assertDatabaseMissing('icons', [ $this->assertDatabaseMissing('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
$this->assertDatabaseMissing('icons', [ $this->assertDatabaseMissing('icons', [
'name' => OtpTestData::ICON_JPEG, 'name' => OtpTestData::ICON_JPEG,
]); ]);
} }
@ -458,7 +458,7 @@ class IconStoreServiceTest extends FeatureTestCase
Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG); Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
$this->assertDatabaseMissing('icons', [ $this->assertDatabaseMissing('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
$result = $this->iconStore->store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA)); $result = $this->iconStore->store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
@ -466,7 +466,7 @@ class IconStoreServiceTest extends FeatureTestCase
$this->assertTrue($result); $this->assertTrue($result);
Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG); Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
$this->assertDatabaseHas('icons', [ $this->assertDatabaseHas('icons', [
'name' => OtpTestData::ICON_PNG, 'name' => OtpTestData::ICON_PNG,
]); ]);
} }
@ -553,7 +553,7 @@ class IconStoreServiceTest extends FeatureTestCase
#[Test] #[Test]
public function test_setDatabaseReplication_stores_only_registered_icon_to_database() public function test_setDatabaseReplication_stores_only_registered_icon_to_database()
{ {
$user = User::factory()->create(); $user = User::factory()->create();
TwoFAccount::factory()->for($user)->create([ TwoFAccount::factory()->for($user)->create([
'icon' => OtpTestData::ICON_PNG, 'icon' => OtpTestData::ICON_PNG,
@ -594,7 +594,7 @@ class IconStoreServiceTest extends FeatureTestCase
#[Test] #[Test]
public function test_setDatabaseReplication_skips_icon_when_file_is_missing() public function test_setDatabaseReplication_skips_icon_when_file_is_missing()
{ {
$user = User::factory()->create(); $user = User::factory()->create();
TwoFAccount::factory()->for($user)->create([ TwoFAccount::factory()->for($user)->create([
'icon' => OtpTestData::ICON_PNG, 'icon' => OtpTestData::ICON_PNG,
@ -644,7 +644,7 @@ class IconStoreServiceTest extends FeatureTestCase
{ {
Settings::set('storeIconsInDatabase', true); Settings::set('storeIconsInDatabase', true);
$user = User::factory()->create(); $user = User::factory()->create();
TwoFAccount::factory()->for($user)->create([ TwoFAccount::factory()->for($user)->create([
'icon' => OtpTestData::ICON_PNG, 'icon' => OtpTestData::ICON_PNG,
@ -721,8 +721,8 @@ class IconStoreServiceTest extends FeatureTestCase
]); ]);
Storage::shouldReceive('disk->put') Storage::shouldReceive('disk->put')
->once() ->once()
->andThrow(new FailedIconStoreDatabaseTogglingException); ->andThrow(new FailedIconStoreDatabaseTogglingException);
$this->expectException(FailedIconStoreDatabaseTogglingException::class); $this->expectException(FailedIconStoreDatabaseTogglingException::class);

View File

@ -52,7 +52,7 @@ class LogoServiceTest extends FeatureTestCase
Http::preventStrayRequests(); Http::preventStrayRequests();
Http::fake([ Http::fake([
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200), 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); $this->logoService = $this->app->make(LogoService::class);
@ -97,7 +97,7 @@ class LogoServiceTest extends FeatureTestCase
Http::preventStrayRequests(); Http::preventStrayRequests();
Http::fake([ Http::fake([
LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200), 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); $this->logoService = $this->app->make(LogoService::class);

View File

@ -8,13 +8,11 @@ use App\Facades\IconStore;
use App\Facades\Settings; use App\Facades\Settings;
use App\Models\Icon; use App\Models\Icon;
use App\Models\TwoFAccount; use App\Models\TwoFAccount;
use App\Services\IconStoreService;
use App\Services\SettingService; use App\Services\SettingService;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Mockery\MockInterface;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;

View File

@ -17,7 +17,7 @@ class storeIconsInDatabaseSettingChangedTest extends TestCase
public function test_event_constructor() public function test_event_constructor()
{ {
$newValue = true; $newValue = true;
$event = new storeIconsInDatabaseSettingChanged($newValue); $event = new storeIconsInDatabaseSettingChanged($newValue);
$this->assertSame($newValue, $event->newValue); $this->assertSame($newValue, $event->newValue);
} }

View File

@ -3,7 +3,6 @@
namespace Tests\Unit\Listeners; namespace Tests\Unit\Listeners;
use App\Events\TwoFAccountDeleted; use App\Events\TwoFAccountDeleted;
use App\Facades\Settings;
use App\Listeners\CleanIconStorage; use App\Listeners\CleanIconStorage;
use App\Models\TwoFAccount; use App\Models\TwoFAccount;
use App\Services\IconStoreService; use App\Services\IconStoreService;

View File

@ -6,7 +6,6 @@ use App\Exceptions\EncryptedMigrationException;
use App\Exceptions\InvalidMigrationDataException; use App\Exceptions\InvalidMigrationDataException;
use App\Exceptions\UnsupportedMigrationException; use App\Exceptions\UnsupportedMigrationException;
use App\Facades\Icons; use App\Facades\Icons;
use App\Facades\IconStore;
use App\Factories\MigratorFactory; use App\Factories\MigratorFactory;
use App\Models\TwoFAccount; use App\Models\TwoFAccount;
use App\Providers\MigrationServiceProvider; use App\Providers\MigrationServiceProvider;

View File

@ -149,7 +149,7 @@ class TwoFAccountModelTest extends ModelTestCase
#[Test] #[Test]
public function test_twofaccount_relation() public function test_twofaccount_relation()
{ {
$model = new Icon(); $model = new Icon;
$relation = $model->twofaccount(); $relation = $model->twofaccount();
$this->assertInstanceOf(BelongsTo::class, $relation); $this->assertInstanceOf(BelongsTo::class, $relation);