From 3a6146dbc3bd83897094a3eb6e3fb142992a2cd7 Mon Sep 17 00:00:00 2001 From: ildyria Date: Sun, 27 Nov 2022 14:46:01 +0100 Subject: [PATCH] more coverage --- .../Diagnostics/Pipes/Checks/GDSupportCheck.php | 6 ++++++ .../Pipes/Checks/IniSettingsCheck.php | 6 ++++++ .../Diagnostics/Pipes/Checks/TimezoneCheck.php | 2 ++ app/Actions/Photo/Delete.php | 17 +++++++++++++++++ app/Actions/SizeVariant/Delete.php | 2 ++ 5 files changed, 33 insertions(+) diff --git a/app/Actions/Diagnostics/Pipes/Checks/GDSupportCheck.php b/app/Actions/Diagnostics/Pipes/Checks/GDSupportCheck.php index f52dcedd8ed..17d7f33c415 100644 --- a/app/Actions/Diagnostics/Pipes/Checks/GDSupportCheck.php +++ b/app/Actions/Diagnostics/Pipes/Checks/GDSupportCheck.php @@ -11,16 +11,22 @@ public function handle(array &$data, \Closure $next): array if (function_exists('gd_info')) { $gdVersion = gd_info(); if (!$gdVersion['JPEG Support']) { + // @codeCoverageIgnoreStart $data[] = 'Error: PHP gd extension without jpeg support'; + // @codeCoverageIgnoreEnd } if (!$gdVersion['PNG Support']) { + // @codeCoverageIgnoreStart $data[] = 'Error: PHP gd extension without png support'; + // @codeCoverageIgnoreEnd } if ( !$gdVersion['GIF Read Support'] || !$gdVersion['GIF Create Support'] ) { + // @codeCoverageIgnoreStart $data[] = 'Error: PHP gd extension without full gif support'; + // @codeCoverageIgnoreEnd } } diff --git a/app/Actions/Diagnostics/Pipes/Checks/IniSettingsCheck.php b/app/Actions/Diagnostics/Pipes/Checks/IniSettingsCheck.php index 1c0630be905..ae14a47aca5 100644 --- a/app/Actions/Diagnostics/Pipes/Checks/IniSettingsCheck.php +++ b/app/Actions/Diagnostics/Pipes/Checks/IniSettingsCheck.php @@ -24,10 +24,14 @@ public function handle(array &$data, \Closure $next): array } $max_execution_time = intval(ini_get('max_execution_time')); if (0 < $max_execution_time && $max_execution_time < 200) { + // @codeCoverageIgnoreStart $data[] = 'Warning: You may experience problems when uploading a photo of large size or handling many/large albums. Take a look in the FAQ for details.'; + // @codeCoverageIgnoreEnd } if (filter_var(ini_get('allow_url_fopen'), FILTER_VALIDATE_BOOLEAN) !== true) { + // @codeCoverageIgnoreStart $data[] = 'Warning: You may experience problems with the Dropbox- and URL-Import. Edit your php.ini and set allow_url_fopen to 1.'; + // @codeCoverageIgnoreEnd } // Check imagick @@ -62,7 +66,9 @@ public function handle(array &$data, \Closure $next): array } if (ini_get('zend.assertions') !== '-1' && config('app.debug') !== true) { + // @codeCoverageIgnoreStart $data[] = 'Warning: zend.assertions is enabled although Lychee is not in debug mode. Outside of debugging, code generation for assertions is recommended to be disabled for efficiency reasons'; + // @codeCoverageIgnoreEnd } if (ini_get('zend.assertions') !== '1' && config('app.debug') === true) { diff --git a/app/Actions/Diagnostics/Pipes/Checks/TimezoneCheck.php b/app/Actions/Diagnostics/Pipes/Checks/TimezoneCheck.php index 9f797493a56..856cc61d0a2 100644 --- a/app/Actions/Diagnostics/Pipes/Checks/TimezoneCheck.php +++ b/app/Actions/Diagnostics/Pipes/Checks/TimezoneCheck.php @@ -11,10 +11,12 @@ public function handle(array &$data, \Closure $next): array { $timezone = CarbonTimeZone::create(); if ($timezone === false) { + // @codeCoverageIgnoreStart $data[] = 'Error: Could not retrieve timezone; you might experience strange results when importing photos without explicit EXIF timezone'; return $next($data); + // @codeCoverageIgnoreEnd } $timezoneName = $timezone->getName(); $tzArray = explode('/', $timezoneName); diff --git a/app/Actions/Photo/Delete.php b/app/Actions/Photo/Delete.php index 634571f4187..2ee33c7d16f 100644 --- a/app/Actions/Photo/Delete.php +++ b/app/Actions/Photo/Delete.php @@ -70,6 +70,7 @@ public function __construct() */ public function do(array $photoIDs, array $albumIDs = []): FileDeleter { + // TODO: replace this with pipelines, This is typically the kind of pattern. try { $this->collectSizeVariantPathsByPhotoID($photoIDs); $this->collectSizeVariantPathsByAlbumID($albumIDs); @@ -78,9 +79,11 @@ public function do(array $photoIDs, array $albumIDs = []): FileDeleter $this->collectSymLinksByPhotoID($photoIDs); $this->collectSymLinksByAlbumID($albumIDs); $this->deleteDBRecords($photoIDs, $albumIDs); + // @codeCoverageIgnoreStart } catch (QueryBuilderException $e) { throw ModelDBException::create('photos', 'deleting', $e); } + // @codeCoverageIgnoreEnd return $this->fileDeleter; } @@ -118,9 +121,11 @@ private function collectSizeVariantPathsByPhotoID(array $photoIDs): void ->whereNull('dup.id') ->pluck('sv.short_path'); $this->fileDeleter->addRegularFilesOrSymbolicLinks($svShortPaths); + // @codeCoverageIgnoreStart } catch (\InvalidArgumentException $e) { throw LycheeAssertionError::createFromUnexpectedException($e); } + // @codeCoverageIgnoreEnd } /** @@ -156,9 +161,11 @@ private function collectSizeVariantPathsByAlbumID(array $albumIDs): void ->whereNull('dup.id') ->pluck('sv.short_path'); $this->fileDeleter->addRegularFilesOrSymbolicLinks($svShortPaths); + // @codeCoverageIgnoreStart } catch (\InvalidArgumentException $e) { throw LycheeAssertionError::createFromUnexpectedException($e); } + // @codeCoverageIgnoreEnd } /** @@ -194,9 +201,11 @@ private function collectLivePhotoPathsByPhotoID(array $photoIDs) ->whereNotNull('p.live_photo_short_path') ->pluck('p.live_photo_short_path'); $this->fileDeleter->addRegularFilesOrSymbolicLinks($livePhotoShortPaths); + // @codeCoverageIgnoreStart } catch (\InvalidArgumentException $e) { throw LycheeAssertionError::createFromUnexpectedException($e); } + // @codeCoverageIgnoreEnd } /** @@ -232,9 +241,11 @@ private function collectLivePhotoPathsByAlbumID(array $albumIDs) ->whereNotNull('p.live_photo_short_path') ->pluck('p.live_photo_short_path'); $this->fileDeleter->addRegularFilesOrSymbolicLinks($livePhotoShortPaths); + // @codeCoverageIgnoreStart } catch (\InvalidArgumentException $e) { throw LycheeAssertionError::createFromUnexpectedException($e); } + // @codeCoverageIgnoreEnd } /** @@ -260,9 +271,11 @@ private function collectSymLinksByPhotoID(array $photoIDs): void ->whereIn('sv.photo_id', $photoIDs) ->pluck('sl.short_path'); $this->fileDeleter->addSymbolicLinks($symLinkPaths); + // @codeCoverageIgnoreStart } catch (\InvalidArgumentException $e) { throw LycheeAssertionError::createFromUnexpectedException($e); } + // @codeCoverageIgnoreEnd } /** @@ -289,9 +302,11 @@ private function collectSymLinksByAlbumID(array $albumIDs): void ->whereIn('p.album_id', $albumIDs) ->pluck('sl.short_path'); $this->fileDeleter->addSymbolicLinks($symLinkPaths); + // @codeCoverageIgnoreStart } catch (\InvalidArgumentException $e) { throw LycheeAssertionError::createFromUnexpectedException($e); } + // @codeCoverageIgnoreEnd } /** @@ -352,8 +367,10 @@ private function deleteDBRecords(array $photoIDs, array $albumIDs): void if (count($albumIDs) !== 0) { Photo::query()->whereIn('album_id', $albumIDs)->delete(); } + // @codeCoverageIgnoreStart } catch (\InvalidArgumentException $e) { throw LycheeAssertionError::createFromUnexpectedException($e); } + // @codeCoverageIgnoreEnd } } diff --git a/app/Actions/SizeVariant/Delete.php b/app/Actions/SizeVariant/Delete.php index a972c6ee36a..28894433d19 100644 --- a/app/Actions/SizeVariant/Delete.php +++ b/app/Actions/SizeVariant/Delete.php @@ -90,10 +90,12 @@ public function do(array $svIDs): FileDeleter ->delete(); return $fileDeleter; + // @codeCoverageIgnoreStart } catch (QueryBuilderException $e) { throw ModelDBException::create('size variants', 'deleting', $e); } catch (\InvalidArgumentException $e) { throw LycheeAssertionError::createFromUnexpectedException($e); } + // @codeCoverageIgnoreEnd } }