Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Oct 11, 2024
1 parent 3e37a45 commit 265a5f6
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ abstract class AbstractUpdateInstallerPipe
* @param \Closure(array<int,string> $output): array<int,string> $next
*
* @return array<int,string>
*
* @codeCoverageIgnore
*/
// @codeCoverageIgnoreStart
abstract public function handle(array &$output, \Closure $next): array;
// @codeCoverageIgnoreEnd

/**
* Arrayify a string and append it to $output.
Expand Down
4 changes: 2 additions & 2 deletions app/Contracts/Models/AbstractSizeVariantNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions app/DTO/AbstractDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function jsonSerialize(): array

/**
* {@inheritDoc}
*
* @codeCoverageIgnore
*/
abstract public function toArray(): array;
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/DiagnosticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/Maintenance/Optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
6 changes: 2 additions & 4 deletions app/Http/Middleware/Checks/IsInstalled.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class IsInstalled implements MiddlewareCheck
{
/**
* @throws InternalLycheeException
*
* @codeCoverageIgnore
*/
public function assert(): bool
{
Expand All @@ -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,
Expand All @@ -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
}
2 changes: 2 additions & 0 deletions app/Legacy/AdminAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/Legacy/BaseConfigMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ abstract class BaseConfigMigration extends Migration

/**
* @return array<int,array{key:string,value:string,confidentiality:string,cat:string,type_range:string,description:string}>
*
* @codeCoverageIgnore
*/
abstract public function getConfigs(): array;

Expand All @@ -29,6 +31,8 @@ final public function up(): void

/**
* Reverse the migrations.
*
* @codeCoverageIgnore
*/
final public function down(): void
{
Expand Down
82 changes: 0 additions & 82 deletions app/Legacy/EnumLocalization.php

This file was deleted.

4 changes: 2 additions & 2 deletions app/Legacy/V1/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
6 changes: 6 additions & 0 deletions app/Metadata/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -111,13 +112,15 @@ 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 = [];

$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);
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
25 changes: 0 additions & 25 deletions app/Metadata/RateLimiterStore.php

This file was deleted.

4 changes: 2 additions & 2 deletions app/Models/SizeVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ignore:
- "^app/Mail/.*"
- "^app/Notifications/.*"
# Legacy shit
- "^app/Legacy/Actions/Photo/.*"
- "^app/Livewire/.*"
- "^app/View/.*"
parsers:
Expand Down

0 comments on commit 265a5f6

Please sign in to comment.