Skip to content

Commit

Permalink
more coverage (#1605)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Nov 28, 2022
1 parent 1aa57e0 commit 7b8eaed
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/Actions/Diagnostics/Pipes/Checks/GDSupportCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
6 changes: 6 additions & 0 deletions app/Actions/Diagnostics/Pipes/Checks/IniSettingsCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Diagnostics/Pipes/Checks/TimezoneCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions app/Actions/Photo/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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
}

/**
Expand All @@ -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
}

/**
Expand All @@ -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
}

/**
Expand Down Expand Up @@ -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
}
}
2 changes: 2 additions & 0 deletions app/Actions/SizeVariant/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 7b8eaed

Please sign in to comment.