From 265a5f6deaa584ae361c539ce1ac875afc1fa61f Mon Sep 17 00:00:00 2001 From: ildyria Date: Fri, 11 Oct 2024 15:04:51 +0200 Subject: [PATCH] improve coverage --- .../Pipes/AbstractUpdateInstallerPipe.php | 4 +- .../AbstractSizeVariantNamingStrategy.php | 4 +- app/DTO/AbstractDTO.php | 2 + .../Admin/DiagnosticsController.php | 4 +- .../Admin/Maintenance/Optimize.php | 4 +- app/Http/Middleware/Checks/IsInstalled.php | 6 +- app/Legacy/AdminAuthentication.php | 2 + app/Legacy/BaseConfigMigration.php | 4 + app/Legacy/EnumLocalization.php | 82 ------------------- app/Legacy/V1/Controllers/IndexController.php | 4 +- app/Metadata/Extractor.php | 6 ++ app/Metadata/RateLimiterStore.php | 25 ------ app/Models/SizeVariant.php | 4 +- codecov.yml | 1 + 14 files changed, 29 insertions(+), 123 deletions(-) delete mode 100644 app/Legacy/EnumLocalization.php delete mode 100644 app/Metadata/RateLimiterStore.php diff --git a/app/Actions/InstallUpdate/Pipes/AbstractUpdateInstallerPipe.php b/app/Actions/InstallUpdate/Pipes/AbstractUpdateInstallerPipe.php index d2275f1b4ef..44b3bf5a579 100644 --- a/app/Actions/InstallUpdate/Pipes/AbstractUpdateInstallerPipe.php +++ b/app/Actions/InstallUpdate/Pipes/AbstractUpdateInstallerPipe.php @@ -9,10 +9,10 @@ abstract class AbstractUpdateInstallerPipe * @param \Closure(array $output): array $next * * @return array + * + * @codeCoverageIgnore */ - // @codeCoverageIgnoreStart abstract public function handle(array &$output, \Closure $next): array; - // @codeCoverageIgnoreEnd /** * Arrayify a string and append it to $output. diff --git a/app/Contracts/Models/AbstractSizeVariantNamingStrategy.php b/app/Contracts/Models/AbstractSizeVariantNamingStrategy.php index cb139ae1f85..d7189cd47c2 100644 --- a/app/Contracts/Models/AbstractSizeVariantNamingStrategy.php +++ b/app/Contracts/Models/AbstractSizeVariantNamingStrategy.php @@ -57,8 +57,8 @@ public function setPhoto(?Photo $photo): void * @return FlysystemFile the file * * @throws LycheeException + * + * @codeCoverageIgnore */ - // @codeCoverageIgnoreStart abstract public function createFile(SizeVariantType $sizeVariant, bool $isBackup = false): FlysystemFile; - // @codeCoverageIgnoreEnd } diff --git a/app/DTO/AbstractDTO.php b/app/DTO/AbstractDTO.php index c094367c70f..824e620bcef 100644 --- a/app/DTO/AbstractDTO.php +++ b/app/DTO/AbstractDTO.php @@ -78,6 +78,8 @@ public function jsonSerialize(): array /** * {@inheritDoc} + * + * @codeCoverageIgnore */ abstract public function toArray(): array; } diff --git a/app/Http/Controllers/Admin/DiagnosticsController.php b/app/Http/Controllers/Admin/DiagnosticsController.php index c23c16ce85c..66e0debad9e 100644 --- a/app/Http/Controllers/Admin/DiagnosticsController.php +++ b/app/Http/Controllers/Admin/DiagnosticsController.php @@ -79,13 +79,13 @@ public function config(DiagnosticsRequest $_request, Configuration $config): arr * @param DiagnosticsRequest $_request * * @return void + * + * @codeCoverageIgnore */ - // @codeCoverageIgnoreStart public function phpinfo(DiagnosticsRequest $_request): void { phpinfo(); } - // @codeCoverageIgnoreEnd /** * Return the table of access permissions currently available on the server. diff --git a/app/Http/Controllers/Admin/Maintenance/Optimize.php b/app/Http/Controllers/Admin/Maintenance/Optimize.php index c08229ef33e..1fa90098926 100644 --- a/app/Http/Controllers/Admin/Maintenance/Optimize.php +++ b/app/Http/Controllers/Admin/Maintenance/Optimize.php @@ -16,13 +16,13 @@ class Optimize extends Controller * Apply the indexing and optimization of the database. * * @return string[] + * + * @codeCoverageIgnore */ public function do(MaintenanceRequest $request, OptimizeDb $optimizeDb, OptimizeTables $optimizeTables): array { - // @codeCoverageIgnoreStart return collect($optimizeDb->do()) ->merge(collect($optimizeTables->do())) ->all(); - // @codeCoverageIgnoreEnd } } diff --git a/app/Http/Middleware/Checks/IsInstalled.php b/app/Http/Middleware/Checks/IsInstalled.php index 3f04c04b929..95b3fbb05b5 100644 --- a/app/Http/Middleware/Checks/IsInstalled.php +++ b/app/Http/Middleware/Checks/IsInstalled.php @@ -16,6 +16,8 @@ class IsInstalled implements MiddlewareCheck { /** * @throws InternalLycheeException + * + * @codeCoverageIgnore */ public function assert(): bool { @@ -24,7 +26,6 @@ public function assert(): bool config('app.key') !== null && config('app.key') !== '' && Schema::hasTable('configs'); - // @codeCoverageIgnoreStart } catch (QueryException $e) { // Authentication to DB failed. // This means that we cannot even check that `configs` is present, @@ -40,15 +41,12 @@ public function assert(): bool return false; } // Not coverable by tests unless we actually remove the php dependencies... - // @codeCoverageIgnoreStart if (Str::contains($e->getMessage(), 'could not find driver')) { return false; } - // @codeCoverageIgnoreEnd throw $e; } catch (BindingResolutionException|NotFoundExceptionInterface|ContainerExceptionInterface $e) { throw new FrameworkException('Laravel\'s container component', $e); } } - // @codeCoverageIgnoreEnd } \ No newline at end of file diff --git a/app/Legacy/AdminAuthentication.php b/app/Legacy/AdminAuthentication.php index a1472a55239..5095f3b4134 100644 --- a/app/Legacy/AdminAuthentication.php +++ b/app/Legacy/AdminAuthentication.php @@ -32,7 +32,9 @@ public static function loginAsAdmin(string $username, string $password, string $ // For version up to 4.0.8 the admin password is stored in the settings /** @codeCoverageIgnore */ if ($db_version_number->toInteger() <= 40008) { + // @codeCoverageIgnoreStart return self::logAsAdminFromConfig($username, $password, $ip); + // @codeCoverageIgnoreEnd } // For version up to 4.6.3 diff --git a/app/Legacy/BaseConfigMigration.php b/app/Legacy/BaseConfigMigration.php index b5ba9a2338d..d614cae61ee 100644 --- a/app/Legacy/BaseConfigMigration.php +++ b/app/Legacy/BaseConfigMigration.php @@ -16,6 +16,8 @@ abstract class BaseConfigMigration extends Migration /** * @return array + * + * @codeCoverageIgnore */ abstract public function getConfigs(): array; @@ -29,6 +31,8 @@ final public function up(): void /** * Reverse the migrations. + * + * @codeCoverageIgnore */ final public function down(): void { diff --git a/app/Legacy/EnumLocalization.php b/app/Legacy/EnumLocalization.php deleted file mode 100644 index ba313eafef7..00000000000 --- a/app/Legacy/EnumLocalization.php +++ /dev/null @@ -1,82 +0,0 @@ - - * - * @throws BindingResolutionException - */ - public static function of(string $class): array - { - return match ($class) { - AlbumDecorationOrientation::class => [ - AlbumDecorationOrientation::ROW->value => __('lychee.ALBUM_DECORATION_ORIENTATION_ROW'), - AlbumDecorationOrientation::ROW_REVERSE->value => __('lychee.ALBUM_DECORATION_ORIENTATION_ROW_REVERSE'), - AlbumDecorationOrientation::COLUMN->value => __('lychee.ALBUM_DECORATION_ORIENTATION_COLUMN'), - AlbumDecorationOrientation::COLUMN_REVERSE->value => __('lychee.ALBUM_DECORATION_ORIENTATION_COLUMN_REVERSE'), - ], - AlbumDecorationType::class => [ - AlbumDecorationType::NONE->value => __('lychee.ALBUM_DECORATION_NONE'), - AlbumDecorationType::LAYERS->value => __('lychee.ALBUM_DECORATION_ORIGINAL'), - AlbumDecorationType::ALBUM->value => __('lychee.ALBUM_DECORATION_ALBUM'), - AlbumDecorationType::PHOTO->value => __('lychee.ALBUM_DECORATION_PHOTO'), - AlbumDecorationType::ALL->value => __('lychee.ALBUM_DECORATION_ALL'), - ], - AspectRatioType::class => [ - AspectRatioType::aspect5by4->value => __('aspect_ratio.5by4'), - AspectRatioType::aspect4by5->value => __('aspect_ratio.4by5'), - AspectRatioType::aspect2by3->value => __('aspect_ratio.2by3'), - AspectRatioType::aspect3by2->value => __('aspect_ratio.3by2'), - AspectRatioType::aspect1by1->value => __('aspect_ratio.1by1'), - AspectRatioType::aspect1byx9->value => __('aspect_ratio.1byx9'), - ], - ColumnSortingAlbumType::class => [ - ColumnSortingAlbumType::CREATED_AT->value => __('lychee.SORT_ALBUM_SELECT_1'), - ColumnSortingAlbumType::TITLE->value => __('lychee.SORT_ALBUM_SELECT_2'), - ColumnSortingAlbumType::DESCRIPTION->value => __('lychee.SORT_ALBUM_SELECT_3'), - ColumnSortingAlbumType::MIN_TAKEN_AT->value => __('lychee.SORT_ALBUM_SELECT_6'), - ColumnSortingAlbumType::MAX_TAKEN_AT->value => __('lychee.SORT_ALBUM_SELECT_5'), - ], - ColumnSortingPhotoType::class => [ - ColumnSortingPhotoType::CREATED_AT->value => __('lychee.SORT_PHOTO_SELECT_1'), - ColumnSortingPhotoType::TAKEN_AT->value => __('lychee.SORT_PHOTO_SELECT_2'), - ColumnSortingPhotoType::TITLE->value => __('lychee.SORT_PHOTO_SELECT_3'), - ColumnSortingPhotoType::DESCRIPTION->value => __('lychee.SORT_PHOTO_SELECT_4'), - ColumnSortingPhotoType::IS_STARRED->value => __('lychee.SORT_PHOTO_SELECT_6'), - ColumnSortingPhotoType::TYPE->value => __('lychee.SORT_PHOTO_SELECT_7'), - ], - ImageOverlayType::class => [ - ImageOverlayType::EXIF->value => __('lychee.OVERLAY_EXIF'), - ImageOverlayType::DESC->value => __('lychee.OVERLAY_DESCRIPTION'), - ImageOverlayType::DATE->value => __('lychee.OVERLAY_DATE'), - ImageOverlayType::NONE->value => __('lychee.OVERLAY_NONE'), - ], - OrderSortingType::class => [ - OrderSortingType::ASC->value => __('lychee.SORT_ASCENDING'), - OrderSortingType::DESC->value => __('lychee.SORT_DESCENDING'), - ], - PhotoLayoutType::class => [ - PhotoLayoutType::SQUARE->value => __('lychee.LAYOUT_SQUARES'), - PhotoLayoutType::JUSTIFIED->value => __('lychee.LAYOUT_JUSTIFIED'), - PhotoLayoutType::MASONRY->value => __('lychee.LAYOUT_MASONRY'), - PhotoLayoutType::GRID->value => __('lychee.LAYOUT_GRID'), - ], - default => [], - }; - } -} \ No newline at end of file diff --git a/app/Legacy/V1/Controllers/IndexController.php b/app/Legacy/V1/Controllers/IndexController.php index b01a408d818..bc9d9048ace 100644 --- a/app/Legacy/V1/Controllers/IndexController.php +++ b/app/Legacy/V1/Controllers/IndexController.php @@ -89,15 +89,15 @@ public function show(): View * Cannot be tested. * * @return void + * + * @codeCoverageIgnore */ - // @codeCoverageIgnoreStart public function phpinfo(): void { Gate::authorize(SettingsPolicy::CAN_SEE_DIAGNOSTICS, Configs::class); phpinfo(); } - // @codeCoverageIgnoreEnd /** * Returns the frontend in "gallery mode". diff --git a/app/Metadata/Extractor.php b/app/Metadata/Extractor.php index 94f2bbec1ff..14359f9fdc9 100644 --- a/app/Metadata/Extractor.php +++ b/app/Metadata/Extractor.php @@ -96,6 +96,7 @@ public static function createFromFile(NativeLocalFile $file, int $fileLastModifi // as `application/octet-stream`, but this work-around only // succeeds if the file has a recognized extension. $exif = $reader->read($file->getRealPath()); + // @codeCoverageIgnoreStart } catch (PhpExifReaderException $e) { // thrown by $reader->read if EXIF could not be extracted, // don't give up yet, only log the event @@ -111,6 +112,7 @@ public static function createFromFile(NativeLocalFile $file, int $fileLastModifi throw new MediaFileOperationException('Could not even extract basic EXIF data with the native adapter', $e); } } + // @codeCoverageIgnoreEnd // Attempt to get sidecar metadata if it exists, make sure to check 'real' path in case of symlinks $sidecarData = []; @@ -118,6 +120,7 @@ public static function createFromFile(NativeLocalFile $file, int $fileLastModifi $sidecarFile = new NativeLocalFile($file->getPath() . '.xmp'); if (Configs::hasExiftool() && $sidecarFile->exists()) { + // @codeCoverageIgnoreStart try { // Don't use the same reader as the file in case it's a video $sidecarReader = Reader::factory(ReaderType::EXIFTOOL); @@ -135,6 +138,7 @@ public static function createFromFile(NativeLocalFile $file, int $fileLastModifi } catch (\Exception $e) { Handler::reportSafely($e); } + // @codeCoverageIgnoreEnd } $metadata->type = ($exif->getMimeType() !== false) ? $exif->getMimeType() : $file->getMimeType(); @@ -442,10 +446,12 @@ public static function createFromFile(NativeLocalFile $file, int $fileLastModifi if ($metadata->location !== null) { $metadata->location = substr($metadata->location, 0, self::MAX_LOCATION_STRING_LENGTH); } + // @codeCoverageIgnoreStart } catch (ExternalComponentFailedException|StringsException $e) { Handler::reportSafely($e); $metadata->location = null; } + // @codeCoverageIgnoreEnd return $metadata; } diff --git a/app/Metadata/RateLimiterStore.php b/app/Metadata/RateLimiterStore.php deleted file mode 100644 index 9a817d01db7..00000000000 --- a/app/Metadata/RateLimiterStore.php +++ /dev/null @@ -1,25 +0,0 @@ - - */ - public function get(): array - { - return Cache::get('rate-limiter', []); - } - - public function push(int $timestamp, int $limit): void - { - Cache::put('rate-limiter', array_merge($this->get(), [$timestamp])); - } -} diff --git a/app/Models/SizeVariant.php b/app/Models/SizeVariant.php index 338fcd3d675..ede9699683c 100644 --- a/app/Models/SizeVariant.php +++ b/app/Models/SizeVariant.php @@ -204,8 +204,9 @@ public function getUrlAttribute(): string * Retrieve the tempary url from AWS if possible. * * @return string + * + * @codeCoverageIgnore */ - // @codeCoverageIgnoreStart private function getAwsUrl(): string { // In order to allow a grace period, we create a new symbolic link, @@ -222,7 +223,6 @@ private function getAwsUrl(): string /** @disregard P1013 */ return $imageDisk->temporaryUrl($this->short_path, now()->addSeconds($maxLifetime)); } - // @codeCoverageIgnoreEnd /** * Get the symlink url if possible. diff --git a/codecov.yml b/codecov.yml index babd9503cd8..b6a4ef4f351 100644 --- a/codecov.yml +++ b/codecov.yml @@ -31,6 +31,7 @@ ignore: - "^app/Mail/.*" - "^app/Notifications/.*" # Legacy shit +- "^app/Legacy/Actions/Photo/.*" - "^app/Livewire/.*" - "^app/View/.*" parsers: