From 022289da72baeefd423498981ecc9ba445a921e1 Mon Sep 17 00:00:00 2001 From: Martin Zurowietz Date: Wed, 8 Jan 2025 15:15:36 +0100 Subject: [PATCH] Fix CS --- .../Api/ProjectReportController.php | 4 +- .../Projects/ProjectReportsController.php | 10 +- .../Controllers/Views/SearchController.php | 41 ++--- .../Views/Volumes/VolumeReportsController.php | 11 +- app/Http/Requests/StoreProjectReport.php | 5 +- app/Http/Requests/StoreReport.php | 3 - app/Jobs/GenerateReportJob.php | 2 - app/Observers/UserObserver.php | 4 +- .../VideoAnnotations/CsvReportGenerator.php | 1 - .../Reports/Volumes/IfdoReportGenerator.php | 9 +- .../AbundanceReportGenerator.php | 12 +- .../AnnotationLocationReportGenerator.php | 47 +++--- .../AnnotationReportGenerator.php | 8 +- .../ImageAnnotations/AreaReportGenerator.php | 3 +- .../ImageAnnotations/CocoReportGenerator.php | 10 +- .../ImageAnnotations/CsvReportGenerator.php | 3 +- .../ImageAnnotations/FullReportGenerator.php | 3 +- .../ImageLocationReportGenerator.php | 5 +- .../Volumes/ImageIfdoReportGenerator.php | 12 +- .../ImageLabels/BasicReportGenerator.php | 8 +- .../ImageLabels/CsvReportGenerator.php | 4 +- .../ImageLocationReportGenerator.php | 9 +- .../Reports/Volumes/PythonScriptRunner.php | 4 +- .../VideoAnnotations/CsvReportGenerator.php | 12 +- .../Volumes/VideoIfdoReportGenerator.php | 11 +- .../VideoLabels/CsvReportGenerator.php | 4 +- app/Traits/RestrictsToExportArea.php | 2 +- app/Traits/RestrictsToNewestLabels.php | 2 +- database/factories/ReportFactory.php | 4 +- ...2017_06_09_092100_create_reports_table.php | 12 +- ..._07_11_135400_rename_video_source_type.php | 2 - .../2020_07_31_155800_rename_report_types.php | 2 - ...4_07_111600_add_video_ifdo_report_type.php | 3 +- ...4_14_161000_add_report_file_extensions.php | 3 +- .../Api/ProjectReportControllerTest.php | 117 ++++++--------- .../Controllers/Api/ReportsControllerTest.php | 1 - .../Api/VolumeReportControllerTest.php | 141 +++++++----------- .../Api/Volumes/ExportAreaControllerTest.php | 6 +- .../Views/SearchControllerTest.php | 2 +- tests/php/Jobs/GenerateReportJobTest.php | 2 - tests/php/ReportTest.php | 3 - .../Projects/ProjectReportGeneratorTest.php | 10 +- .../CsvReportGeneratorTest.php | 1 - .../Projects/VideoIfdoReportGeneratorTest.php | 2 +- .../Services/Reports/ReportGeneratorTest.php | 2 +- .../AbundanceReportGeneratorTest.php | 21 +-- .../AnnotationLocationReportGeneratorTest.php | 56 ++----- .../AnnotationReportGeneratorTest.php | 2 - .../AreaReportGeneratorTest.php | 36 ++--- .../BasicReportGeneratorTest.php | 21 +-- .../CocoReportGeneratorTest.php | 38 ++--- .../CsvReportGeneratorTest.php | 38 ++--- .../ExtendedReportGeneratorTest.php | 13 +- .../FullReportGeneratorTest.php | 14 +- .../ImageLocationReportGeneratorTest.php | 32 +--- .../ImageLabels/BasicReportGeneratorTest.php | 12 +- .../ImageLabels/CsvReportGeneratorTest.php | 34 ++--- .../ImageLocationReportGeneratorTest.php | 32 +--- .../CsvReportGeneratorTest.php | 40 ++--- .../VideoLabels/CsvReportGeneratorTest.php | 36 ++--- 60 files changed, 329 insertions(+), 658 deletions(-) diff --git a/app/Http/Controllers/Api/ProjectReportController.php b/app/Http/Controllers/Api/ProjectReportController.php index 659837193..88ad7e8f3 100644 --- a/app/Http/Controllers/Api/ProjectReportController.php +++ b/app/Http/Controllers/Api/ProjectReportController.php @@ -27,12 +27,12 @@ class ProjectReportController extends Controller * @apiParam (Optional arguments) {Boolean} aggregate_child_labels If `true`, add the abundance of child labels to the abundance of their parent labels and omit the child labels. This is only valid for the abundance report. Labels that are excluded with `only_labels` are not counted. * @apiParam (Optional arguments) {Boolean} disable_notifications If `true`, suppress notification to the user on report completion. * @apiParam (Optional arguments) {Boolean} strip_ifdo If `true`, remove annotation information from the original iFDO file before it is populated with BIIGLE annotations. Only available for the iFDO report. - * + * * @apiPermission projectMember * * @param StoreProjectReport $request * @param int $id Project ID - * + * * @return mixed */ public function store(StoreProjectReport $request, $id) diff --git a/app/Http/Controllers/Views/Projects/ProjectReportsController.php b/app/Http/Controllers/Views/Projects/ProjectReportsController.php index 7bc166e4d..f3b891190 100644 --- a/app/Http/Controllers/Views/Projects/ProjectReportsController.php +++ b/app/Http/Controllers/Views/Projects/ProjectReportsController.php @@ -4,8 +4,8 @@ use Biigle\Http\Controllers\Views\Controller; use Biigle\Modules\MetadataIfdo\IfdoParser; -use Biigle\ReportType; use Biigle\Project; +use Biigle\ReportType; use Illuminate\Http\Request; use Illuminate\Http\Response; @@ -38,12 +38,8 @@ protected function show(Request $request, $id) ->wherePivot('pinned', true) ->count(); - $types = ReportType::when($hasImageVolume, function ($query) { - $query->where('name', 'like', 'Image%'); - }) - ->when($hasVideoVolume, function ($query) { - $query->orWhere('name', 'like', 'Video%'); - }) + $types = ReportType::when($hasImageVolume, fn ($q) => $q->where('name', 'like', 'Image%')) + ->when($hasVideoVolume, fn ($q) => $q->orWhere('name', 'like', 'Video%')) ->orderBy('name', 'asc') ->get(); diff --git a/app/Http/Controllers/Views/SearchController.php b/app/Http/Controllers/Views/SearchController.php index 17a2950f0..f464a1c58 100644 --- a/app/Http/Controllers/Views/SearchController.php +++ b/app/Http/Controllers/Views/SearchController.php @@ -367,26 +367,27 @@ public function searchReports(User $user, $query, $type) if ($query) { $queryBuilder = $queryBuilder ->where(function ($q) use ($query) { - $q->where(function ($q) use ($query) { - $q->where('reports.source_type', Volume::class) - ->whereExists(function ($q) use ($query) { - $q->select(DB::raw(1)) - ->from('volumes') - ->whereRaw('reports.source_id = volumes.id') - ->where('volumes.name', 'ilike', "%{$query}%"); - }); - }) - ->orWhere(function ($q) use ($query) { - $q->where('reports.source_type', Project::class) - ->whereExists(function ($q) use ($query) { - $q->select(DB::raw(1)) - ->from('projects') - ->whereRaw('reports.source_id = projects.id') - ->where('projects.name', 'ilike', "%{$query}%"); - }); - }) - // Kept for backwards compatibility of single video reports. - ->orWhere('reports.source_name', 'ilike', "%{$query}%"); + $q + ->where(function ($q) use ($query) { + $q->where('reports.source_type', Volume::class) + ->whereExists(function ($q) use ($query) { + $q->select(DB::raw(1)) + ->from('volumes') + ->whereRaw('reports.source_id = volumes.id') + ->where('volumes.name', 'ilike', "%{$query}%"); + }); + }) + ->orWhere(function ($q) use ($query) { + $q->where('reports.source_type', Project::class) + ->whereExists(function ($q) use ($query) { + $q->select(DB::raw(1)) + ->from('projects') + ->whereRaw('reports.source_id = projects.id') + ->where('projects.name', 'ilike', "%{$query}%"); + }); + }) + // Kept for backwards compatibility of single video reports. + ->orWhere('reports.source_name', 'ilike', "%{$query}%"); }); } diff --git a/app/Http/Controllers/Views/Volumes/VolumeReportsController.php b/app/Http/Controllers/Views/Volumes/VolumeReportsController.php index d74f8c48f..8c920f21d 100644 --- a/app/Http/Controllers/Views/Volumes/VolumeReportsController.php +++ b/app/Http/Controllers/Views/Volumes/VolumeReportsController.php @@ -5,9 +5,8 @@ use Biigle\Http\Controllers\Views\Controller; use Biigle\LabelTree; use Biigle\Modules\MetadataIfdo\IfdoParser; -use Biigle\ReportType; use Biigle\Project; -use Biigle\Role; +use Biigle\ReportType; use Biigle\Volume; use Illuminate\Http\Request; @@ -25,12 +24,8 @@ public function show(Request $request, $id) $volume = Volume::findOrFail($id); $this->authorize('access', $volume); $sessions = $volume->annotationSessions()->orderBy('starts_at', 'desc')->get(); - $types = ReportType::when($volume->isImageVolume(), function ($query) { - $query->where('name', 'like', 'Image%'); - }) - ->when($volume->isVideoVolume(), function ($query) { - $query->where('name', 'like', 'Video%'); - }) + $types = ReportType::when($volume->isImageVolume(), fn ($q) => $q->where('name', 'like', 'Image%')) + ->when($volume->isVideoVolume(), fn ($q) => $q->where('name', 'like', 'Video%')) ->orderBy('name', 'asc') ->get(); diff --git a/app/Http/Requests/StoreProjectReport.php b/app/Http/Requests/StoreProjectReport.php index 9a50fcc62..c1a403310 100644 --- a/app/Http/Requests/StoreProjectReport.php +++ b/app/Http/Requests/StoreProjectReport.php @@ -6,7 +6,6 @@ use Biigle\Modules\MetadataIfdo\IfdoParser; use Biigle\Project; use Biigle\ReportType; -use Illuminate\Validation\Rule; class StoreProjectReport extends StoreReport { @@ -112,9 +111,7 @@ protected function validateGeoInfo($validator) $hasGeoInfo = $this->project->imageVolumes() ->select('id') ->get() - ->reduce(function ($carry, $volume) { - return $carry && $volume->hasGeoInfo(); - }, true); + ->reduce(fn ($carry, $volume) => $carry && $volume->hasGeoInfo(), true); if (!$hasGeoInfo) { $validator->errors()->add('id', 'No volume has images with geo coordinates.'); diff --git a/app/Http/Requests/StoreReport.php b/app/Http/Requests/StoreReport.php index 68fd9a9d5..575e69048 100644 --- a/app/Http/Requests/StoreReport.php +++ b/app/Http/Requests/StoreReport.php @@ -2,11 +2,8 @@ namespace Biigle\Http\Requests; -use Biigle\MediaType; -use Biigle\Project; use Biigle\ReportType; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Validation\Rule; class StoreReport extends FormRequest { diff --git a/app/Jobs/GenerateReportJob.php b/app/Jobs/GenerateReportJob.php index 465a60b6e..8b37688fb 100644 --- a/app/Jobs/GenerateReportJob.php +++ b/app/Jobs/GenerateReportJob.php @@ -2,10 +2,8 @@ namespace Biigle\Jobs; -use Biigle\Jobs\Job; use Biigle\Notifications\ReportReady; use Biigle\Report; -use Biigle\User; use Carbon\Carbon; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; diff --git a/app/Observers/UserObserver.php b/app/Observers/UserObserver.php index 383c5eb57..47d32a5f3 100644 --- a/app/Observers/UserObserver.php +++ b/app/Observers/UserObserver.php @@ -17,8 +17,6 @@ class UserObserver public function deleting($user) { Report::where('user_id', $user->id) - ->eachById(function ($report) { - return $report->deleteFile(); - }); + ->eachById(fn ($report) => $report->deleteFile()); } } diff --git a/app/Services/Reports/Projects/VideoAnnotations/CsvReportGenerator.php b/app/Services/Reports/Projects/VideoAnnotations/CsvReportGenerator.php index 3c2bd7ac0..60ef37f84 100644 --- a/app/Services/Reports/Projects/VideoAnnotations/CsvReportGenerator.php +++ b/app/Services/Reports/Projects/VideoAnnotations/CsvReportGenerator.php @@ -2,7 +2,6 @@ namespace Biigle\Services\Reports\Projects\VideoAnnotations; -use Biigle\Services\Reports\File; use Biigle\Services\Reports\Projects\ProjectVideoReportGenerator; use Biigle\Services\Reports\Volumes\VideoAnnotations\CsvReportGenerator as ReportGenerator; diff --git a/app/Services/Reports/Volumes/IfdoReportGenerator.php b/app/Services/Reports/Volumes/IfdoReportGenerator.php index 21d9b724f..37e927cc4 100644 --- a/app/Services/Reports/Volumes/IfdoReportGenerator.php +++ b/app/Services/Reports/Volumes/IfdoReportGenerator.php @@ -9,9 +9,7 @@ use Biigle\LabelSource; use Biigle\Modules\MetadataIfdo\IfdoParser; use Biigle\Shape; -use Biigle\Video; use Biigle\Volume; -use DB; use Exception; use File; use Storage; @@ -95,8 +93,7 @@ public function generateReport($path) }, $this->imageAnnotationCreators); if ($this->options->get('stripIfdo', false)) { - unset($ifdo['image-set-header']['image-annotation-creators']); - unset($ifdo['image-set-header']['image-annotation-labels']); + unset($ifdo['image-set-header']['image-annotation-creators'], $ifdo['image-set-header']['image-annotation-labels']); if (array_key_exists('image-set-items', $ifdo)) { foreach ($ifdo['image-set-items'] as &$item) { if ($this->isArrayItem($item)) { @@ -246,9 +243,7 @@ protected function getWormsUrn($label) */ protected function isArrayItem($item) { - return !empty($item) && array_reduce(array_keys($item), function ($carry, $key) { - return $carry && is_numeric($key); - }, true); + return !empty($item) && array_reduce(array_keys($item), fn ($carry, $key) => $carry && is_numeric($key), true); } /** diff --git a/app/Services/Reports/Volumes/ImageAnnotations/AbundanceReportGenerator.php b/app/Services/Reports/Volumes/ImageAnnotations/AbundanceReportGenerator.php index b82dda72c..f451b54fa 100644 --- a/app/Services/Reports/Volumes/ImageAnnotations/AbundanceReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageAnnotations/AbundanceReportGenerator.php @@ -170,9 +170,7 @@ protected function aggregateChildLabels($rows, $labels) return in_array($value, $onlyLabels) ? $value : null; }); }) - ->reject(function ($value) { - return is_null($value); - }); + ->reject(fn ($value) => is_null($value)); // Determine the highest parent label for all child labels. do { @@ -213,16 +211,12 @@ protected function aggregateChildLabels($rows, $labels) // Remove rows of child labels so they are not counted twice. $rows[$filename] = $annotations->values() - ->reject(function ($annotation) use ($parentIdMap) { - return $parentIdMap->has($annotation->label_id); - }); + ->reject(fn ($annotation) => $parentIdMap->has($annotation->label_id)); } // Remove all labels that did not occur (as parent) in the rows. $presentLabels = $presentLabels->unique()->flip(); - $labels = $labels->filter(function ($label) use ($presentLabels) { - return $presentLabels->has($label->id); - }); + $labels = $labels->filter(fn ($label) => $presentLabels->has($label->id)); return [$rows, $labels]; } diff --git a/app/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGenerator.php b/app/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGenerator.php index 1fda4abfd..861e23f6a 100644 --- a/app/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGenerator.php @@ -2,7 +2,6 @@ namespace Biigle\Services\Reports\Volumes\ImageAnnotations; -use Biigle\ImageAnnotationLabel; use Biigle\LabelTree; use Biigle\Services\Reports\File; use Biigle\Services\Reports\MakesZipArchives; @@ -10,7 +9,6 @@ use Biigle\User; use DB; use GeoJson\Feature\Feature; -use GeoJson\Feature\FeatureCollection; use GeoJson\Geometry\LineString; use GeoJson\Geometry\Point; use GeoJson\Geometry\Polygon; @@ -95,28 +93,29 @@ public function generateReport($path) */ public function query() { - return $this->initQuery([ - 'image_annotation_labels.id as annotation_label_id', - 'image_annotation_labels.label_id', - 'image_annotations.image_id', - 'image_annotations.shape_id', - 'images.filename', - 'images.attrs->metadata->yaw as yaw', - 'images.attrs->metadata->distance_to_ground as distance_to_ground', - 'images.attrs->width as width', - 'images.attrs->height as height', - 'images.lat', - 'images.lng', - 'image_annotations.points', - 'image_annotation_labels.id as annotation_label_id', - 'labels.name as label_name', - ]) - ->whereNotNull('images.lat') - ->whereNotNull('images.lng') - ->whereNotNull('images.attrs->width') - ->whereNotNull('images.attrs->height') - ->whereNotNull('images.attrs->metadata->distance_to_ground') - ->whereNotNull('images.attrs->metadata->yaw'); + return $this + ->initQuery([ + 'image_annotation_labels.id as annotation_label_id', + 'image_annotation_labels.label_id', + 'image_annotations.image_id', + 'image_annotations.shape_id', + 'images.filename', + 'images.attrs->metadata->yaw as yaw', + 'images.attrs->metadata->distance_to_ground as distance_to_ground', + 'images.attrs->width as width', + 'images.attrs->height as height', + 'images.lat', + 'images.lng', + 'image_annotations.points', + 'image_annotation_labels.id as annotation_label_id', + 'labels.name as label_name', + ]) + ->whereNotNull('images.lat') + ->whereNotNull('images.lng') + ->whereNotNull('images.attrs->width') + ->whereNotNull('images.attrs->height') + ->whereNotNull('images.attrs->metadata->distance_to_ground') + ->whereNotNull('images.attrs->metadata->yaw'); } /** diff --git a/app/Services/Reports/Volumes/ImageAnnotations/AnnotationReportGenerator.php b/app/Services/Reports/Volumes/ImageAnnotations/AnnotationReportGenerator.php index b5b560195..0f0a6d67f 100644 --- a/app/Services/Reports/Volumes/ImageAnnotations/AnnotationReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageAnnotations/AnnotationReportGenerator.php @@ -112,12 +112,8 @@ public function initQuery($columns = []) ->where('images.volume_id', $this->source->id) ->when($this->isRestrictedToExportArea(), [$this, 'restrictToExportAreaQuery']) ->when($this->isRestrictedToAnnotationSession(), [$this, 'restrictToAnnotationSessionQuery']) - ->when($this->isRestrictedToNewestLabel(), function ($query) { - return $this->restrictToNewestLabelQuery($query, $this->source); - }) - ->when($this->isRestrictedToLabels(), function ($query) { - return $this->restrictToLabelsQuery($query, 'image_annotation_labels'); - }) + ->when($this->isRestrictedToNewestLabel(), fn ($query) => $this->restrictToNewestLabelQuery($query, $this->source)) + ->when($this->isRestrictedToLabels(), fn ($query) => $this->restrictToLabelsQuery($query, 'image_annotation_labels')) ->select($columns); if ($this->shouldSeparateLabelTrees()) { diff --git a/app/Services/Reports/Volumes/ImageAnnotations/AreaReportGenerator.php b/app/Services/Reports/Volumes/ImageAnnotations/AreaReportGenerator.php index 3c253c06e..ca23688e0 100644 --- a/app/Services/Reports/Volumes/ImageAnnotations/AreaReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageAnnotations/AreaReportGenerator.php @@ -85,7 +85,8 @@ public function generateReport($path) */ protected function query() { - $query = $this->initQuery([ + $query = $this + ->initQuery([ 'image_annotations.id as annotation_id', 'shapes.id as shape_id', 'shapes.name as shape_name', diff --git a/app/Services/Reports/Volumes/ImageAnnotations/CocoReportGenerator.php b/app/Services/Reports/Volumes/ImageAnnotations/CocoReportGenerator.php index 467c79e83..8d6f064fc 100644 --- a/app/Services/Reports/Volumes/ImageAnnotations/CocoReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageAnnotations/CocoReportGenerator.php @@ -4,9 +4,8 @@ use Biigle\LabelTree; use Biigle\Services\Reports\CsvFile; -use Biigle\User; - use Biigle\Services\Reports\MakesZipArchives; +use Biigle\User; use DB; class CocoReportGenerator extends AnnotationReportGenerator @@ -68,18 +67,19 @@ public function generateReport($path) $this->tmpFiles[] = $csv; $toZip[$csv->getPath()] = $this->sanitizeFilename("{$this->source->id}-{$this->source->name}", 'json'); } - $this->executeScript('to_coco',''); // the temporary csv files are overwritten with the respective json files therefore the argument is not needed + $this->executeScript('to_coco', ''); // the temporary csv files are overwritten with the respective json files therefore the argument is not needed $this->makeZip($toZip, $path); } -/** + /** * Assemble a new DB query for the volume of this report. * * @return \Illuminate\Database\Query\Builder */ protected function query() { - $query = $this->initQuery([ + $query = $this + ->initQuery([ 'image_annotation_labels.id as annotation_label_id', 'image_annotation_labels.label_id', 'labels.name as label_name', diff --git a/app/Services/Reports/Volumes/ImageAnnotations/CsvReportGenerator.php b/app/Services/Reports/Volumes/ImageAnnotations/CsvReportGenerator.php index b35532c0b..9a3d556ee 100644 --- a/app/Services/Reports/Volumes/ImageAnnotations/CsvReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageAnnotations/CsvReportGenerator.php @@ -87,7 +87,8 @@ public function generateReport($path) */ protected function query() { - $query = $this->initQuery([ + $query = $this + ->initQuery([ 'image_annotation_labels.id as annotation_label_id', 'image_annotation_labels.label_id', 'labels.name as label_name', diff --git a/app/Services/Reports/Volumes/ImageAnnotations/FullReportGenerator.php b/app/Services/Reports/Volumes/ImageAnnotations/FullReportGenerator.php index 4cda62d2e..778dc8b51 100644 --- a/app/Services/Reports/Volumes/ImageAnnotations/FullReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageAnnotations/FullReportGenerator.php @@ -70,7 +70,8 @@ public function generateReport($path) */ protected function query() { - $query = $this->initQuery([ + $query = $this + ->initQuery([ 'images.filename', 'image_annotations.id as annotation_id', 'image_annotation_labels.label_id', diff --git a/app/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGenerator.php b/app/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGenerator.php index 90b463e81..fd7908ba5 100644 --- a/app/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGenerator.php @@ -9,7 +9,6 @@ use Biigle\User; use DB; use GeoJson\Feature\Feature; -use GeoJson\Feature\FeatureCollection; use GeoJson\Geometry\Point; class ImageLocationReportGenerator extends AnnotationReportGenerator @@ -49,9 +48,7 @@ public function generateReport($path) ->join('images', 'image_annotations.image_id', '=', 'images.id') ->join('labels', 'image_annotation_labels.label_id', '=', 'labels.id') ->where('images.volume_id', $this->source->id) - ->when($this->isRestrictedToLabels(), function ($query) { - return $this->restrictToLabelsQuery($query, 'image_annotation_labels'); - }) + ->when($this->isRestrictedToLabels(), fn ($query) => $this->restrictToLabelsQuery($query, 'image_annotation_labels')) ->orderBy('labels.id') ->distinct(); diff --git a/app/Services/Reports/Volumes/ImageIfdoReportGenerator.php b/app/Services/Reports/Volumes/ImageIfdoReportGenerator.php index 7a63e7d71..199571a87 100644 --- a/app/Services/Reports/Volumes/ImageIfdoReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageIfdoReportGenerator.php @@ -6,9 +6,7 @@ use Biigle\Label; use Biigle\Traits\RestrictsToExportArea; use Biigle\Traits\RestrictsToNewestLabels; -use Biigle\Shape; use Biigle\User; -use Biigle\Video; use Biigle\Volume; class ImageIfdoReportGenerator extends IfdoReportGenerator @@ -81,7 +79,8 @@ protected function query() */ protected function getUsers() { - return User::whereIn('id', function ($query) { + return User::query() + ->whereIn('id', function ($query) { $query->select('user_id') ->from('image_annotation_labels') ->join('image_annotations', 'image_annotations.id', '=', 'image_annotation_labels.annotation_id') @@ -104,7 +103,8 @@ protected function getUsers() */ protected function getLabels() { - return Label::whereIn('id', function ($query) { + return Label::query() + ->whereIn('id', function ($query) { $query->select('label_id') ->from('image_annotation_labels') ->join('image_annotations', 'image_annotations.id', '=', 'image_annotation_labels.annotation_id') @@ -127,9 +127,7 @@ public function processFile(Image $image) { // Remove annotations that should not be included because of an "onlyLabels" // filter. - $annotations = $image->annotations->filter(function ($a) { - return $a->labels->isNotEmpty(); - }); + $annotations = $image->annotations->filter(fn ($a) => $a->labels->isNotEmpty()); $annotations = $annotations->map(function ($annotation) { $labels = $annotation->labels->map(function ($aLabel) { diff --git a/app/Services/Reports/Volumes/ImageLabels/BasicReportGenerator.php b/app/Services/Reports/Volumes/ImageLabels/BasicReportGenerator.php index 071136e2e..006c819a1 100644 --- a/app/Services/Reports/Volumes/ImageLabels/BasicReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageLabels/BasicReportGenerator.php @@ -74,9 +74,7 @@ public function query() ->join('images', 'image_labels.image_id', '=', 'images.id') ->select('images.id', 'images.filename', 'image_labels.label_id') ->where('images.volume_id', $this->source->id) - ->when($this->isRestrictedToLabels(), function ($query) { - return $this->restrictToLabelsQuery($query, 'image_labels'); - }) + ->when($this->isRestrictedToLabels(), fn ($query) => $this->restrictToLabelsQuery($query, 'image_labels')) ->orderBy('images.filename'); if ($this->shouldSeparateLabelTrees()) { @@ -106,9 +104,7 @@ protected function createCsv($rows, $title = '') $csv->putCsv([ $row[0]->id, $row[0]->filename, - $row->map(function ($row) { - return $this->expandLabelName($row->label_id); - })->implode(', '), + $row->map(fn ($row) => $this->expandLabelName($row->label_id))->implode(', '), ]); } diff --git a/app/Services/Reports/Volumes/ImageLabels/CsvReportGenerator.php b/app/Services/Reports/Volumes/ImageLabels/CsvReportGenerator.php index fbbe35641..14ee76be0 100644 --- a/app/Services/Reports/Volumes/ImageLabels/CsvReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageLabels/CsvReportGenerator.php @@ -98,9 +98,7 @@ public function query() 'image_labels.created_at', ]) ->where('images.volume_id', $this->source->id) - ->when($this->isRestrictedToLabels(), function ($query) { - return $this->restrictToLabelsQuery($query, 'image_labels'); - }) + ->when($this->isRestrictedToLabels(), fn ($query) => $this->restrictToLabelsQuery($query, 'image_labels')) ->orderBy('images.filename'); if ($this->shouldSeparateLabelTrees()) { diff --git a/app/Services/Reports/Volumes/ImageLabels/ImageLocationReportGenerator.php b/app/Services/Reports/Volumes/ImageLabels/ImageLocationReportGenerator.php index 42d7f07ab..d12069d61 100644 --- a/app/Services/Reports/Volumes/ImageLabels/ImageLocationReportGenerator.php +++ b/app/Services/Reports/Volumes/ImageLabels/ImageLocationReportGenerator.php @@ -10,7 +10,6 @@ use Biigle\User; use DB; use GeoJson\Feature\Feature; -use GeoJson\Feature\FeatureCollection; use GeoJson\Geometry\Point; class ImageLocationReportGenerator extends VolumeReportGenerator @@ -49,9 +48,7 @@ public function generateReport($path) $usedImageLabelsQuery = ImageLabel::join('images', 'image_labels.image_id', '=', 'images.id') ->join('labels', 'image_labels.label_id', '=', 'labels.id') ->where('images.volume_id', $this->source->id) - ->when($this->isRestrictedToLabels(), function ($query) { - return $this->restrictToLabelsQuery($query, 'image_labels'); - }) + ->when($this->isRestrictedToLabels(), fn ($query) => $this->restrictToLabelsQuery($query, 'image_labels')) ->orderBy('labels.id') ->distinct(); @@ -113,9 +110,7 @@ public function query() 'image_labels.label_id', ]) ->where('images.volume_id', $this->source->id) - ->when($this->isRestrictedToLabels(), function ($query) { - return $this->restrictToLabelsQuery($query, 'image_labels'); - }); + ->when($this->isRestrictedToLabels(), fn ($query) => $this->restrictToLabelsQuery($query, 'image_labels')); if ($this->shouldSeparateLabelTrees()) { $query->join('labels', 'labels.id', '=', 'image_labels.label_id') diff --git a/app/Services/Reports/Volumes/PythonScriptRunner.php b/app/Services/Reports/Volumes/PythonScriptRunner.php index b4dcd19a5..ce10cadc9 100644 --- a/app/Services/Reports/Volumes/PythonScriptRunner.php +++ b/app/Services/Reports/Volumes/PythonScriptRunner.php @@ -44,9 +44,7 @@ public function run($scriptName, $volumeName, $path, $csvs = []) $python = config('reports.python'); $script = config("reports.scripts.{$scriptName}"); - $csvs = implode(' ', array_map(function ($csv) { - return $csv->getPath(); - }, $csvs)); + $csvs = implode(' ', array_map(fn ($csv) => $csv->getPath(), $csvs)); $command = "{$python} {$script} \"{$volumeName}\" {$path} {$csvs} 2>&1"; diff --git a/app/Services/Reports/Volumes/VideoAnnotations/CsvReportGenerator.php b/app/Services/Reports/Volumes/VideoAnnotations/CsvReportGenerator.php index 26153c71b..07e2846a6 100644 --- a/app/Services/Reports/Volumes/VideoAnnotations/CsvReportGenerator.php +++ b/app/Services/Reports/Volumes/VideoAnnotations/CsvReportGenerator.php @@ -2,7 +2,6 @@ namespace Biigle\Services\Reports\Volumes\VideoAnnotations; -use Biigle\Label; use Biigle\LabelTree; use Biigle\Services\Reports\CsvFile; use Biigle\Services\Reports\MakesZipArchives; @@ -151,12 +150,8 @@ public function initQuery($columns = []) ->join('labels', 'video_annotation_labels.label_id', '=', 'labels.id') ->where('videos.volume_id', $this->source->id) ->when($this->isRestrictedToAnnotationSession(), [$this, 'restrictToAnnotationSessionQuery']) - ->when($this->isRestrictedToNewestLabel(), function ($query) { - return $this->restrictToNewestLabelQuery($query, $this->source); - }) - ->when($this->isRestrictedToLabels(), function ($query) { - return $this->restrictToLabelsQuery($query, 'video_annotation_labels'); - }) + ->when($this->isRestrictedToNewestLabel(), fn ($query) => $this->restrictToNewestLabelQuery($query, $this->source)) + ->when($this->isRestrictedToLabels(), fn ($query) => $this->restrictToLabelsQuery($query, 'video_annotation_labels')) ->select($columns); if ($this->shouldSeparateLabelTrees()) { @@ -198,7 +193,8 @@ public function restrictToAnnotationSessionQuery($query) */ protected function query() { - $query = $this->initQuery([ + $query = $this + ->initQuery([ 'video_annotation_labels.id as video_annotation_label_id', 'video_annotation_labels.label_id', 'labels.name as label_name', diff --git a/app/Services/Reports/Volumes/VideoIfdoReportGenerator.php b/app/Services/Reports/Volumes/VideoIfdoReportGenerator.php index c2516f22d..fd13ba0e2 100644 --- a/app/Services/Reports/Volumes/VideoIfdoReportGenerator.php +++ b/app/Services/Reports/Volumes/VideoIfdoReportGenerator.php @@ -5,7 +5,6 @@ use Biigle\Image; use Biigle\Label; use Biigle\Traits\RestrictsToNewestLabels; -use Biigle\Shape; use Biigle\User; use Biigle\Video; use Biigle\Volume; @@ -78,7 +77,8 @@ protected function query() */ protected function getUsers() { - return User::whereIn('id', function ($query) { + return User::query() + ->whereIn('id', function ($query) { $query->select('user_id') ->from('video_annotation_labels') ->join('video_annotations', 'video_annotations.id', '=', 'video_annotation_labels.annotation_id') @@ -101,7 +101,8 @@ protected function getUsers() */ protected function getLabels() { - return Label::whereIn('id', function ($query) { + return Label::query() + ->whereIn('id', function ($query) { $query->select('label_id') ->from('video_annotation_labels') ->join('video_annotations', 'video_annotations.id', '=', 'video_annotation_labels.annotation_id') @@ -124,9 +125,7 @@ public function processFile(Video $video) { // Remove annotations that should not be included because of an "onlyLabels" // filter. - $annotations = $video->annotations->filter(function ($a) { - return $a->labels->isNotEmpty(); - }); + $annotations = $video->annotations->filter(fn ($a) => $a->labels->isNotEmpty()); $annotations = $annotations->map(function ($annotation) { $labels = $annotation->labels->map(function ($aLabel) { diff --git a/app/Services/Reports/Volumes/VideoLabels/CsvReportGenerator.php b/app/Services/Reports/Volumes/VideoLabels/CsvReportGenerator.php index 6ddc152e3..d4d55c040 100644 --- a/app/Services/Reports/Volumes/VideoLabels/CsvReportGenerator.php +++ b/app/Services/Reports/Volumes/VideoLabels/CsvReportGenerator.php @@ -96,9 +96,7 @@ public function query() 'video_labels.created_at', ]) ->where('videos.volume_id', $this->source->id) - ->when($this->isRestrictedToLabels(), function ($query) { - return $this->restrictToLabelsQuery($query, 'video_labels'); - }) + ->when($this->isRestrictedToLabels(), fn ($query) => $this->restrictToLabelsQuery($query, 'video_labels')) ->orderBy('videos.filename'); if ($this->shouldSeparateLabelTrees()) { diff --git a/app/Traits/RestrictsToExportArea.php b/app/Traits/RestrictsToExportArea.php index be81a2ae8..6a8bd872a 100644 --- a/app/Traits/RestrictsToExportArea.php +++ b/app/Traits/RestrictsToExportArea.php @@ -1,6 +1,6 @@ User::factory(), - 'type_id' => function () { - return ReportType::imageAnnotationsCsvId(); - }, + 'type_id' => fn () => ReportType::imageAnnotationsCsvId(), 'source_id' => Volume::factory(), 'source_type' => Volume::class, ]; diff --git a/database/migrations/2017_06_09_092100_create_reports_table.php b/database/migrations/2017_06_09_092100_create_reports_table.php index 524837f8a..51b87293a 100644 --- a/database/migrations/2017_06_09_092100_create_reports_table.php +++ b/database/migrations/2017_06_09_092100_create_reports_table.php @@ -36,15 +36,15 @@ public function up() $table->unsignedInteger('user_id'); $table->foreign('user_id') - ->references('id') - ->on('users') - ->onDelete('cascade'); + ->references('id') + ->on('users') + ->onDelete('cascade'); $table->unsignedInteger('type_id'); $table->foreign('type_id') - ->references('id') - ->on('report_types') - ->onDelete('restrict'); + ->references('id') + ->on('report_types') + ->onDelete('restrict'); // Columns for the polymorphic relationship to either volumes or projects. $table->morphs('source'); diff --git a/database/migrations/2020_07_11_135400_rename_video_source_type.php b/database/migrations/2020_07_11_135400_rename_video_source_type.php index 0fd6cb9c7..06842bace 100644 --- a/database/migrations/2020_07_11_135400_rename_video_source_type.php +++ b/database/migrations/2020_07_11_135400_rename_video_source_type.php @@ -2,8 +2,6 @@ use Biigle\Report; use Illuminate\Database\Migrations\Migration; -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Facades\Schema; class RenameVideoSourceType extends Migration { diff --git a/database/migrations/2020_07_31_155800_rename_report_types.php b/database/migrations/2020_07_31_155800_rename_report_types.php index 9f8d07f9e..f7379c5bc 100644 --- a/database/migrations/2020_07_31_155800_rename_report_types.php +++ b/database/migrations/2020_07_31_155800_rename_report_types.php @@ -2,8 +2,6 @@ use Biigle\ReportType; use Illuminate\Database\Migrations\Migration; -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Facades\Schema; class RenameReportTypes extends Migration { diff --git a/database/migrations/2022_04_07_111600_add_video_ifdo_report_type.php b/database/migrations/2022_04_07_111600_add_video_ifdo_report_type.php index d9ca02df1..3c7a049a8 100644 --- a/database/migrations/2022_04_07_111600_add_video_ifdo_report_type.php +++ b/database/migrations/2022_04_07_111600_add_video_ifdo_report_type.php @@ -2,8 +2,7 @@ use Illuminate\Database\Migrations\Migration; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_04_14_161000_add_report_file_extensions.php b/database/migrations/2022_04_14_161000_add_report_file_extensions.php index 3be91bad5..23998b7dd 100644 --- a/database/migrations/2022_04_14_161000_add_report_file_extensions.php +++ b/database/migrations/2022_04_14_161000_add_report_file_extensions.php @@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration; use League\Flysystem\FilesystemOperationFailed; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/tests/php/Http/Controllers/Api/ProjectReportControllerTest.php b/tests/php/Http/Controllers/Api/ProjectReportControllerTest.php index d5b2af002..65f9f2b0b 100644 --- a/tests/php/Http/Controllers/Api/ProjectReportControllerTest.php +++ b/tests/php/Http/Controllers/Api/ProjectReportControllerTest.php @@ -3,9 +3,9 @@ namespace Biigle\Tests\Http\Controllers\Api; use ApiTestCase; +use Biigle\Jobs\GenerateReportJob; use Biigle\MediaType; use Biigle\Modules\MetadataIfdo\IfdoParser; -use Biigle\Jobs\GenerateReportJob; use Biigle\ReportType; use Biigle\Tests\ImageTest; use Biigle\Tests\LabelTest; @@ -33,7 +33,8 @@ public function testStore() $response = $this->json('POST', "api/v1/projects/{$projectId}/reports") ->assertStatus(422); - $response = $this->json('POST', "api/v1/projects/{$projectId}/reports", [ + $response = $this + ->json('POST', "api/v1/projects/{$projectId}/reports", [ 'type_id' => $typeId, ]) ->assertStatus(201); @@ -58,7 +59,8 @@ public function testStoreOptions() $typeId = ReportType::imageAnnotationsBasicId(); $this->beGuest(); - $response = $this->json('POST', "api/v1/projects/{$projectId}/reports", [ + $response = $this + ->json('POST', "api/v1/projects/{$projectId}/reports", [ 'type_id' => $typeId, 'export_area' => true, 'newest_label' => true, @@ -86,9 +88,8 @@ public function testStoreVideoVolume() $this->beGuest(); $this->json('POST', "api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + ])->assertStatus(201); Queue::assertPushed(function (GenerateReportJob $job) { $report = $job->report; @@ -113,9 +114,8 @@ public function testStoreNoVideoVolumes() $this->beGuest(); foreach ($types as $typeId) { $this->json('POST', "api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(422); + 'type_id' => $typeId, + ])->assertStatus(422); } } @@ -143,9 +143,8 @@ public function testStoreNoImageVolumes() $this->beGuest(); foreach ($types as $typeId) { $this->json('POST', "api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(422); + 'type_id' => $typeId, + ])->assertStatus(422); } } @@ -158,16 +157,14 @@ public function testStoreOnlyLabels() $this->volume(); $typeId = ReportType::first()->id; $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - 'only_labels' => [999], - ]) - ->assertStatus(422); + 'type_id' => $typeId, + 'only_labels' => [999], + ])->assertStatus(422); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - 'only_labels' => [$label->id], - ]) - ->assertStatus(201); + 'type_id' => $typeId, + 'only_labels' => [$label->id], + ])->assertStatus(201); } public function testStoreImageLabelImageLocationWithoutLatLng() @@ -178,9 +175,8 @@ public function testStoreImageLabelImageLocationWithoutLatLng() $image = ImageTest::create(['volume_id' => $this->volume()->id]); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => ReportType::imageLabelsImageLocationId(), - ]) - ->assertStatus(422); + 'type_id' => ReportType::imageLabelsImageLocationId(), + ])->assertStatus(422); $image->lat = 1; $image->lng = 1; @@ -188,9 +184,8 @@ public function testStoreImageLabelImageLocationWithoutLatLng() $this->volume()->flushGeoInfoCache(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => ReportType::imageLabelsImageLocationId(), - ]) - ->assertStatus(201); + 'type_id' => ReportType::imageLabelsImageLocationId(), + ])->assertStatus(201); } public function testStoreImageAnnotationImageLocationWithoutLatLng() @@ -201,9 +196,8 @@ public function testStoreImageAnnotationImageLocationWithoutLatLng() $image = ImageTest::create(['volume_id' => $this->volume()->id]); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => ReportType::imageAnnotationsImageLocationId(), - ]) - ->assertStatus(422); + 'type_id' => ReportType::imageAnnotationsImageLocationId(), + ])->assertStatus(422); $image->lat = 1; $image->lng = 1; @@ -211,9 +205,8 @@ public function testStoreImageAnnotationImageLocationWithoutLatLng() $this->volume()->flushGeoInfoCache(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => ReportType::imageAnnotationsImageLocationId(), - ]) - ->assertStatus(201); + 'type_id' => ReportType::imageAnnotationsImageLocationId(), + ])->assertStatus(201); } public function testStoreImageAnnotationAnnotationLocationWithoutLatLngYawDistance() @@ -224,10 +217,8 @@ public function testStoreImageAnnotationAnnotationLocationWithoutLatLngYawDistan $image = ImageTest::create(['volume_id' => $this->volume()->id]); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), - ]) - // Metadata missing. - ->assertStatus(422); + 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), + ])->assertStatus(422); // Metadata missing. $image->lat = 1; $image->lng = 1; @@ -239,19 +230,16 @@ public function testStoreImageAnnotationAnnotationLocationWithoutLatLngYawDistan $this->volume()->flushGeoInfoCache(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), - ]) - // Width/height missing. - ->assertStatus(422); + 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), + ])->assertStatus(422); // Width/height missing. $image->width = 1; $image->height = 1; $image->save(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), - ]) - ->assertStatus(201); + 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), + ])->assertStatus(201); } public function testStoreSeparateLabelTreesUsersConflict() @@ -264,11 +252,10 @@ public function testStoreSeparateLabelTreesUsersConflict() $this->beGuest(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - 'separate_label_trees' => true, - 'separate_users' => true, - ]) - ->assertStatus(422); + 'type_id' => $typeId, + 'separate_label_trees' => true, + 'separate_users' => true, + ])->assertStatus(422); Queue::assertNotPushed(GenerateReportJob::class); } @@ -282,10 +269,9 @@ public function testStoreSeparateLabelTrees() $this->beGuest(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - 'separate_label_trees' => true, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + 'separate_label_trees' => true, + ])->assertStatus(201); Queue::assertPushed(function (GenerateReportJob $job) { $this->assertTrue($job->report->options['separateLabelTrees']); @@ -303,10 +289,9 @@ public function testStoreSeparateUsers() $this->beGuest(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - 'separate_users' => true, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + 'separate_users' => true, + ])->assertStatus(201); Queue::assertPushed(function (GenerateReportJob $job) { $this->assertTrue($job->report->options['separateUsers']); @@ -324,9 +309,8 @@ public function testStoreImageIfdo() $this->beGuest(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(422); + 'type_id' => $typeId, + ])->assertStatus(422); $volume->update([ 'metadata_file_path' => 'mymeta.json', @@ -337,9 +321,8 @@ public function testStoreImageIfdo() Cache::flush(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + ])->assertStatus(201); Queue::assertPushed(GenerateReportJob::class); } @@ -355,9 +338,8 @@ public function testStoreVideoIfdo() $this->beGuest(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(422); + 'type_id' => $typeId, + ])->assertStatus(422); $volume->update([ 'metadata_file_path' => 'mymeta.json', @@ -368,9 +350,8 @@ public function testStoreVideoIfdo() Cache::flush(); $this->postJson("api/v1/projects/{$projectId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + ])->assertStatus(201); Queue::assertPushed(GenerateReportJob::class); } } diff --git a/tests/php/Http/Controllers/Api/ReportsControllerTest.php b/tests/php/Http/Controllers/Api/ReportsControllerTest.php index d282bf5df..8e1c5fb9c 100644 --- a/tests/php/Http/Controllers/Api/ReportsControllerTest.php +++ b/tests/php/Http/Controllers/Api/ReportsControllerTest.php @@ -5,7 +5,6 @@ use ApiTestCase; use Biigle\ReportType; use Biigle\Tests\ReportTest; -use Response; use Storage; class ReportsControllerTest extends ApiTestCase diff --git a/tests/php/Http/Controllers/Api/VolumeReportControllerTest.php b/tests/php/Http/Controllers/Api/VolumeReportControllerTest.php index 1ee39b83b..61bc13dad 100644 --- a/tests/php/Http/Controllers/Api/VolumeReportControllerTest.php +++ b/tests/php/Http/Controllers/Api/VolumeReportControllerTest.php @@ -3,13 +3,12 @@ namespace Biigle\Tests\Http\Controllers\Api; use ApiTestCase; +use Biigle\Jobs\GenerateReportJob; use Biigle\MediaType; use Biigle\Modules\MetadataIfdo\IfdoParser; -use Biigle\Jobs\GenerateReportJob; use Biigle\ReportType; use Biigle\Tests\ImageTest; use Biigle\Tests\LabelTest; -use Biigle\Volume; use Cache; use Queue; use Storage; @@ -32,9 +31,8 @@ public function testStore() ->assertStatus(422); $response = $this->json('POST', "api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + ])->assertStatus(201); Queue::assertPushedOn('high', function (GenerateReportJob $job) use ($typeId, $volumeId, $response) { $report = $job->report; @@ -55,11 +53,10 @@ public function testStoreOptions() $this->beGuest(); $response = $this->json('POST', "api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - 'export_area' => true, - 'newest_label' => true, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + 'export_area' => true, + 'newest_label' => true, + ])->assertStatus(201); Queue::assertPushedOn('high', function (GenerateReportJob $job) use ($typeId, $volumeId, $response) { $report = $job->report; @@ -96,9 +93,8 @@ public function testStoreImageVolumeTypes() $this->beGuest(); foreach ($types as $typeId) { $this->json('POST', "api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + ])->assertStatus(201); } } @@ -132,25 +128,21 @@ public function testStoreVideoVolume() ->assertStatus(422); $this->json('POST', "api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - 'export_area' => true, - ]) - ->assertStatus(422); + 'type_id' => $typeId, + 'export_area' => true, + ])->assertStatus(422); $this->json('POST', "api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - 'aggregate_child_labels' => true, - ]) - ->assertStatus(422); + 'type_id' => $typeId, + 'aggregate_child_labels' => true, + ])->assertStatus(422); $this->json('POST', "api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + ])->assertStatus(201); Queue::assertPushed(GenerateReportJob::class); } - public function testStoreVideoVolumeTypes() { $volumeId = $this->volume(['media_type_id' => MediaType::videoId()])->id; @@ -164,9 +156,8 @@ public function testStoreVideoVolumeTypes() $this->beGuest(); foreach ($types as $typeId) { $this->json('POST', "api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + ])->assertStatus(201); } } @@ -197,16 +188,14 @@ public function testStoreOnlyLabels() $volumeId = $this->volume()->id; $typeId = ReportType::first()->id; $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - 'only_labels' => [-1], - ]) - ->assertStatus(422); + 'type_id' => $typeId, + 'only_labels' => [-1], + ])->assertStatus(422); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - 'only_labels' => [$label->id], - ]) - ->assertStatus(201); + 'type_id' => $typeId, + 'only_labels' => [$label->id], + ])->assertStatus(201); } public function testStoreImageLabelImageLocationWithoutLatLng() @@ -217,9 +206,8 @@ public function testStoreImageLabelImageLocationWithoutLatLng() $image = ImageTest::create(['volume_id' => $volumeId]); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => ReportType::imageLabelsImageLocationId(), - ]) - ->assertStatus(422); + 'type_id' => ReportType::imageLabelsImageLocationId(), + ])->assertStatus(422); $image->lat = 1; $image->lng = 1; @@ -227,9 +215,8 @@ public function testStoreImageLabelImageLocationWithoutLatLng() $this->volume()->flushGeoInfoCache(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => ReportType::imageLabelsImageLocationId(), - ]) - ->assertStatus(201); + 'type_id' => ReportType::imageLabelsImageLocationId(), + ])->assertStatus(201); } public function testStoreImageAnnotationImageLocationWithoutLatLng() @@ -240,9 +227,8 @@ public function testStoreImageAnnotationImageLocationWithoutLatLng() $image = ImageTest::create(['volume_id' => $volumeId]); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => ReportType::imageAnnotationsImageLocationId(), - ]) - ->assertStatus(422); + 'type_id' => ReportType::imageAnnotationsImageLocationId(), + ])->assertStatus(422); $image->lat = 1; $image->lng = 1; @@ -250,9 +236,8 @@ public function testStoreImageAnnotationImageLocationWithoutLatLng() $this->volume()->flushGeoInfoCache(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => ReportType::imageAnnotationsImageLocationId(), - ]) - ->assertStatus(201); + 'type_id' => ReportType::imageAnnotationsImageLocationId(), + ])->assertStatus(201); } public function testStoreImageAnnotationAnnotationLocationWithoutLatLngYawDistance() @@ -263,10 +248,8 @@ public function testStoreImageAnnotationAnnotationLocationWithoutLatLngYawDistan $image = ImageTest::create(['volume_id' => $volumeId]); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), - ]) - // Metadata missing. - ->assertStatus(422); + 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), + ])->assertStatus(422); // Metadata missing. $image->lat = 1; $image->lng = 1; @@ -278,19 +261,16 @@ public function testStoreImageAnnotationAnnotationLocationWithoutLatLngYawDistan $this->volume()->flushGeoInfoCache(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), - ]) - // Width/height missing. - ->assertStatus(422); + 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), + ])->assertStatus(422); // Width/height missing. $image->width = 1; $image->height = 1; $image->save(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), - ]) - ->assertStatus(201); + 'type_id' => ReportType::imageAnnotationsAnnotationLocationId(), + ])->assertStatus(201); } public function testStoreSeparateLabelTreesUsersConflict() @@ -301,11 +281,10 @@ public function testStoreSeparateLabelTreesUsersConflict() $this->beGuest(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - 'separate_label_trees' => true, - 'separate_users' => true, - ]) - ->assertStatus(422); + 'type_id' => $typeId, + 'separate_label_trees' => true, + 'separate_users' => true, + ])->assertStatus(422); Queue::assertNotPushed(GenerateReportJob::class); } @@ -317,10 +296,9 @@ public function testStoreSeparateLabelTrees() $this->beGuest(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - 'separate_label_trees' => true, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + 'separate_label_trees' => true, + ])->assertStatus(201); Queue::assertPushed(function (GenerateReportJob $job) { $this->assertTrue($job->report->options['separateLabelTrees']); @@ -336,10 +314,9 @@ public function testStoreSeparateUsers() $this->beGuest(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - 'separate_users' => true, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + 'separate_users' => true, + ])->assertStatus(201); Queue::assertPushed(function (GenerateReportJob $job) { $this->assertTrue($job->report->options['separateUsers']); @@ -356,9 +333,8 @@ public function testStoreImageIfdo() $this->beGuest(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(422); + 'type_id' => $typeId, + ])->assertStatus(422); $volume->update([ 'metadata_file_path' => 'mymeta.json', @@ -369,9 +345,8 @@ public function testStoreImageIfdo() Cache::flush(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + ])->assertStatus(201); Queue::assertPushed(GenerateReportJob::class); } @@ -386,9 +361,8 @@ public function testStoreVideoIfdo() $this->beGuest(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(422); + 'type_id' => $typeId, + ])->assertStatus(422); $volume->update([ 'metadata_file_path' => 'mymeta.json', @@ -399,9 +373,8 @@ public function testStoreVideoIfdo() Cache::flush(); $this->postJson("api/v1/volumes/{$volumeId}/reports", [ - 'type_id' => $typeId, - ]) - ->assertStatus(201); + 'type_id' => $typeId, + ])->assertStatus(201); Queue::assertPushed(GenerateReportJob::class); } } diff --git a/tests/php/Http/Controllers/Api/Volumes/ExportAreaControllerTest.php b/tests/php/Http/Controllers/Api/Volumes/ExportAreaControllerTest.php index 2d13d2e96..51e07e02f 100644 --- a/tests/php/Http/Controllers/Api/Volumes/ExportAreaControllerTest.php +++ b/tests/php/Http/Controllers/Api/Volumes/ExportAreaControllerTest.php @@ -4,7 +4,6 @@ use ApiTestCase; use Biigle\MediaType; -use Biigle\Volume; class ExportAreaControllerTest extends ApiTestCase { @@ -70,9 +69,8 @@ public function testStoreVideoVolume() $this->beAdmin(); $this->postJson("/api/v1/volumes/{$volume->id}/export-area", [ - 'coordinates' => [10, 20, 30, 40], - ]) - ->assertStatus(422); + 'coordinates' => [10, 20, 30, 40], + ])->assertStatus(422); } public function testDestroy() diff --git a/tests/php/Http/Controllers/Views/SearchControllerTest.php b/tests/php/Http/Controllers/Views/SearchControllerTest.php index 22c3aea04..f033713c8 100644 --- a/tests/php/Http/Controllers/Views/SearchControllerTest.php +++ b/tests/php/Http/Controllers/Views/SearchControllerTest.php @@ -6,7 +6,6 @@ use Biigle\Project; use Biigle\ReportType; use Biigle\Role; -use Biigle\Video; use Biigle\Tests\FederatedSearchModelTest; use Biigle\Tests\ImageTest; use Biigle\Tests\LabelTreeTest; @@ -16,6 +15,7 @@ use Biigle\Tests\UserTest; use Biigle\Tests\VideoTest; use Biigle\Tests\VolumeTest; +use Biigle\Video; use Biigle\Visibility; use Biigle\Volume; use TestCase; diff --git a/tests/php/Jobs/GenerateReportJobTest.php b/tests/php/Jobs/GenerateReportJobTest.php index cb17beaa5..2e34a817a 100644 --- a/tests/php/Jobs/GenerateReportJobTest.php +++ b/tests/php/Jobs/GenerateReportJobTest.php @@ -12,7 +12,6 @@ class GenerateReportJobTest extends TestCase { - public function testHandleWithoutNotifications() { $opts = []; @@ -90,5 +89,4 @@ public function testHandleWithNotificationsFalse() $report->options = $opts; with(new GenerateReportJob($report))->handle(); } - } diff --git a/tests/php/ReportTest.php b/tests/php/ReportTest.php index 88d488127..7afd5e2d2 100644 --- a/tests/php/ReportTest.php +++ b/tests/php/ReportTest.php @@ -4,10 +4,7 @@ use Biigle\Report; use Biigle\Services\Reports\ReportGenerator; -use Biigle\Tests\ProjectTest; -use Biigle\Tests\VolumeTest; use Carbon\Carbon; -use File; use Mockery; use ModelTestCase; use Storage; diff --git a/tests/php/Services/Reports/Projects/ProjectReportGeneratorTest.php b/tests/php/Services/Reports/Projects/ProjectReportGeneratorTest.php index ceace4b8c..e97c12432 100644 --- a/tests/php/Services/Reports/Projects/ProjectReportGeneratorTest.php +++ b/tests/php/Services/Reports/Projects/ProjectReportGeneratorTest.php @@ -3,7 +3,6 @@ namespace Biigle\Tests\Services\Reports\Projects; use App; -use Biigle\Services\Reports\File; use Biigle\Services\Reports\Projects\ProjectReportGenerator; use Biigle\Tests\LabelTest; use Biigle\Tests\ProjectTest; @@ -46,9 +45,7 @@ public function testGenerate() $mock = Mockery::mock(); $mock->shouldReceive('generate') - ->with(Mockery::on(function ($v) use ($volume) { - return $v instanceof Volume && $volume->id === $v->id; - })) + ->with(Mockery::on(fn ($v) => $v instanceof Volume && $volume->id === $v->id)) ->once() ->andReturn('my_tmp_file_path'); @@ -63,9 +60,7 @@ public function testGenerate() ->with('my_tmp_file_path', '123_my_download_filename.pdf'); $mock->shouldReceive('close')->once(); - App::bind(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::bind(ZipArchive::class, fn () => $mock); $generator->generate($project, 'dir'); } @@ -74,6 +69,7 @@ public function testGenerate() class ProjectReportStub extends ProjectReportGenerator { public $mock; + protected function getReportGenerator() { return $this->mock; diff --git a/tests/php/Services/Reports/Projects/VideoAnnotations/CsvReportGeneratorTest.php b/tests/php/Services/Reports/Projects/VideoAnnotations/CsvReportGeneratorTest.php index 8d004613e..eeb0d0e5b 100644 --- a/tests/php/Services/Reports/Projects/VideoAnnotations/CsvReportGeneratorTest.php +++ b/tests/php/Services/Reports/Projects/VideoAnnotations/CsvReportGeneratorTest.php @@ -3,7 +3,6 @@ namespace Biigle\Tests\Services\Reports\Projects\VideoAnnotations; use Biigle\Services\Reports\Projects\VideoAnnotations\CsvReportGenerator; -use Biigle\VideosServiceProvider; use TestCase; class CsvReportGeneratorTest extends TestCase diff --git a/tests/php/Services/Reports/Projects/VideoIfdoReportGeneratorTest.php b/tests/php/Services/Reports/Projects/VideoIfdoReportGeneratorTest.php index ecbcff5b3..091983d15 100644 --- a/tests/php/Services/Reports/Projects/VideoIfdoReportGeneratorTest.php +++ b/tests/php/Services/Reports/Projects/VideoIfdoReportGeneratorTest.php @@ -2,8 +2,8 @@ namespace Biigle\Tests\Services\Reports\Projects; -use Biigle\Modules\MetadataIfdo\IfdoParser; use Biigle\MediaType; +use Biigle\Modules\MetadataIfdo\IfdoParser; use Biigle\Services\Reports\Projects\VideoIfdoReportGenerator; use Biigle\Tests\ProjectTest; use Biigle\Volume; diff --git a/tests/php/Services/Reports/ReportGeneratorTest.php b/tests/php/Services/Reports/ReportGeneratorTest.php index 150d0539f..0248a17cd 100644 --- a/tests/php/Services/Reports/ReportGeneratorTest.php +++ b/tests/php/Services/Reports/ReportGeneratorTest.php @@ -2,10 +2,10 @@ namespace Biigle\Tests\Services\Reports; +use Biigle\Project; use Biigle\ReportType; use Biigle\Services\Reports\ReportGenerator; use Biigle\Services\Reports\Volumes\ImageAnnotations\BasicReportGenerator; -use Biigle\Project; use Biigle\Tests\LabelTest; use Biigle\Tests\VolumeTest; use Biigle\Video; diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/AbundanceReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/AbundanceReportGeneratorTest.php index 8b5f97265..6c44df812 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/AbundanceReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/AbundanceReportGeneratorTest.php @@ -5,7 +5,6 @@ use App; use Biigle\Services\Reports\CsvFile; use Biigle\Services\Reports\Volumes\ImageAnnotations\AbundanceReportGenerator; -use Biigle\Volume; use Biigle\Tests\ImageAnnotationLabelTest; use Biigle\Tests\ImageAnnotationTest; use Biigle\Tests\ImageTest; @@ -73,9 +72,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AbundanceReportGenerator; $generator->setSource($volume); @@ -134,9 +131,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AbundanceReportGenerator([ 'separateLabelTrees' => true, @@ -193,9 +188,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AbundanceReportGenerator([ 'separateUsers' => true, @@ -265,9 +258,7 @@ public function testGenerateReportAggregateChildLabels() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AbundanceReportGenerator([ 'aggregateChildLabels' => true, @@ -391,9 +382,7 @@ public function testGenerateReportOnlyLabelsAggregateChildLabels() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AbundanceReportGenerator([ 'aggregateChildLabels' => true, diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGeneratorTest.php index 2eebf0c1e..7d0a4414d 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationLocationReportGeneratorTest.php @@ -94,9 +94,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -110,9 +108,7 @@ public function testGenerateReport() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new AnnotationLocationReportGenerator; $generator->setSource($volume); @@ -184,9 +180,7 @@ public function testGenerateReportCircle() $mock->shouldReceive('close') ->once(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -199,9 +193,7 @@ public function testGenerateReportCircle() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new AnnotationLocationReportGenerator; $generator->setSource($volume); @@ -276,9 +268,7 @@ public function testGenerateReportLineString() $mock->shouldReceive('close') ->once(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -291,9 +281,7 @@ public function testGenerateReportLineString() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new AnnotationLocationReportGenerator; $generator->setSource($volume); @@ -370,9 +358,7 @@ public function testGenerateReportPolygon() $mock->shouldReceive('close') ->once(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -385,9 +371,7 @@ public function testGenerateReportPolygon() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new AnnotationLocationReportGenerator; $generator->setSource($volume); @@ -411,9 +395,7 @@ public function testGenerateReportNoCoordinates() $mock->shouldReceive('close') ->once(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -424,9 +406,7 @@ public function testGenerateReportNoCoordinates() $mock->shouldReceive('addFile')->once(); $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new AnnotationLocationReportGenerator; $generator->setSource($volume); @@ -506,9 +486,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -526,9 +504,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new AnnotationLocationReportGenerator([ 'separateLabelTrees' => true, @@ -614,9 +590,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -634,9 +608,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new AnnotationLocationReportGenerator([ 'separateUsers' => true, diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationReportGeneratorTest.php index 779da03c0..954187378 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/AnnotationReportGeneratorTest.php @@ -2,8 +2,6 @@ namespace Biigle\Tests\Services\Reports\Volumes\ImageAnnotations; -use Biigle\ImageAnnotation; -use Biigle\ImageAnnotationLabel; use Biigle\Services\Reports\Volumes\ImageAnnotations\AnnotationReportGenerator; use Biigle\Shape; use Biigle\Tests\AnnotationSessionTest; diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/AreaReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/AreaReportGeneratorTest.php index a8ff69d59..fad3750d9 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/AreaReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/AreaReportGeneratorTest.php @@ -74,9 +74,7 @@ public function testGenerateReportPoint() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AreaReportGenerator; $generator->setSource($volume); @@ -133,9 +131,7 @@ public function testGenerateReportCirlce() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AreaReportGenerator; $generator->setSource($volume); @@ -188,9 +184,7 @@ public function testGenerateReportRectangle() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AreaReportGenerator; $generator->setSource($volume); @@ -244,9 +238,7 @@ public function testGenerateReportPolygon() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AreaReportGenerator; $generator->setSource($volume); @@ -300,9 +292,7 @@ public function testGenerateReportEllipse() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AreaReportGenerator; $generator->setSource($volume); @@ -360,9 +350,7 @@ public function testGenerateReportSqm() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AreaReportGenerator; $generator->setSource($volume); @@ -432,9 +420,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AreaReportGenerator([ 'separateLabelTrees' => true, @@ -501,9 +487,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AreaReportGenerator([ 'separateUsers' => true, @@ -559,9 +543,7 @@ public function testGenerateReportLineString() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new AreaReportGenerator; $generator->setSource($volume); diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/BasicReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/BasicReportGeneratorTest.php index fe349a3ca..f2c613bd0 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/BasicReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/BasicReportGeneratorTest.php @@ -5,7 +5,6 @@ use App; use Biigle\Services\Reports\CsvFile; use Biigle\Services\Reports\Volumes\ImageAnnotations\BasicReportGenerator; -use Biigle\Volume; use Biigle\Tests\ImageAnnotationLabelTest; use Biigle\Tests\ImageAnnotationTest; use Biigle\Tests\ImageTest; @@ -55,9 +54,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new BasicReportGenerator; $generator->setSource($volume); @@ -109,15 +106,11 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); $mock->code = 0; - App::singleton(Exec::class, function () use ($mock) { - return $mock; - }); + App::singleton(Exec::class, fn () => $mock); $generator = new BasicReportGenerator([ 'separateLabelTrees' => true, @@ -165,15 +158,11 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); $mock->code = 0; - App::singleton(Exec::class, function () use ($mock) { - return $mock; - }); + App::singleton(Exec::class, fn () => $mock); $generator = new BasicReportGenerator([ 'separateUsers' => true, diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/CocoReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/CocoReportGeneratorTest.php index eaf9624ef..45d49ed58 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/CocoReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/CocoReportGeneratorTest.php @@ -87,9 +87,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -103,9 +101,7 @@ public function testGenerateReport() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CocoReportGenerator; $generator->setSource($volume); @@ -180,9 +176,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -200,9 +194,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CocoReportGenerator([ 'separateLabelTrees' => true, @@ -283,9 +275,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -303,9 +293,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CocoReportGenerator([ 'separateUsers' => true, @@ -331,11 +319,11 @@ public function testGenerateReportWithDeletedUser() $annotation = ImageAnnotationTest::create(['image_id' => $image->id]); $al1 = ImageAnnotationLabelTest::create([ - 'annotation_id' => $annotation->id, + 'annotation_id' => $annotation->id, 'user_id' => null // deleted user ]); $al2 = ImageAnnotationLabelTest::create([ - 'annotation_id' => $annotation->id, + 'annotation_id' => $annotation->id, 'user_id' => $user->id ]); @@ -364,7 +352,7 @@ public function testGenerateReportWithDeletedUser() null ]); - $mock->shouldReceive('putCsv') + $mock->shouldReceive('putCsv') ->once() ->with([ $al2->id, @@ -381,9 +369,7 @@ public function testGenerateReportWithDeletedUser() $mock->shouldReceive('close')->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -397,9 +383,7 @@ public function testGenerateReportWithDeletedUser() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CocoReportGenerator(); $generator->setSource($image->volume); diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/CsvReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/CsvReportGeneratorTest.php index ab29f3dac..5a97ac09d 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/CsvReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/CsvReportGeneratorTest.php @@ -101,9 +101,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -117,9 +115,7 @@ public function testGenerateReport() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator; $generator->setSource($volume); @@ -205,9 +201,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -225,9 +219,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator([ 'separateLabelTrees' => true, @@ -319,9 +311,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -339,9 +329,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator([ 'separateUsers' => true, @@ -364,11 +352,11 @@ public function testGenerateReportWithDeletedUser() $annotation = ImageAnnotationTest::create(['image_id' => $image->id]); $al1 = ImageAnnotationLabelTest::create([ - 'annotation_id' => $annotation->id, + 'annotation_id' => $annotation->id, 'user_id' => null // deleted user ]); $al2 = ImageAnnotationLabelTest::create([ - 'annotation_id' => $annotation->id, + 'annotation_id' => $annotation->id, 'user_id' => $user->id ]); @@ -404,7 +392,7 @@ public function testGenerateReportWithDeletedUser() $al1->created_at, ]); - $mock->shouldReceive('putCsv') + $mock->shouldReceive('putCsv') ->once() ->with([ $al2->id, @@ -428,9 +416,7 @@ public function testGenerateReportWithDeletedUser() $mock->shouldReceive('close')->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -444,9 +430,7 @@ public function testGenerateReportWithDeletedUser() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator(); $generator->setSource($image->volume); diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/ExtendedReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/ExtendedReportGeneratorTest.php index 4b340e24a..6b5ca2b05 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/ExtendedReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/ExtendedReportGeneratorTest.php @@ -5,7 +5,6 @@ use App; use Biigle\Services\Reports\CsvFile; use Biigle\Services\Reports\Volumes\ImageAnnotations\ExtendedReportGenerator; -use Biigle\Volume; use Biigle\Tests\ImageAnnotationLabelTest; use Biigle\Tests\ImageAnnotationTest; use Biigle\Tests\ImageTest; @@ -70,9 +69,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new ExtendedReportGenerator; $generator->setSource($volume); @@ -127,9 +124,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new ExtendedReportGenerator([ 'separateLabelTrees' => true, @@ -181,9 +176,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new ExtendedReportGenerator([ 'separateUsers' => true, diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/FullReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/FullReportGeneratorTest.php index cbe93e5d0..dbe875625 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/FullReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/FullReportGeneratorTest.php @@ -5,8 +5,6 @@ use App; use Biigle\Services\Reports\CsvFile; use Biigle\Services\Reports\Volumes\ImageAnnotations\FullReportGenerator; -use Biigle\Volume; -use Biigle\Shape; use Biigle\Tests\ImageAnnotationLabelTest; use Biigle\Tests\ImageAnnotationTest; use Biigle\Tests\ImageTest; @@ -66,9 +64,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new FullReportGenerator; $generator->setSource($volume); @@ -139,9 +135,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new FullReportGenerator([ 'separateLabelTrees' => true, @@ -209,9 +203,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new FullReportGenerator([ 'separateUsers' => true, diff --git a/tests/php/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGeneratorTest.php index 681babb1e..cde1f5b7d 100644 --- a/tests/php/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageAnnotations/ImageLocationReportGeneratorTest.php @@ -78,9 +78,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -94,9 +92,7 @@ public function testGenerateReport() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new ImageLocationReportGenerator; $generator->setSource($volume); @@ -120,9 +116,7 @@ public function testGenerateReportNoCoordinates() $mock->shouldReceive('close') ->once(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -133,9 +127,7 @@ public function testGenerateReportNoCoordinates() $mock->shouldReceive('addFile')->once(); $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new ImageLocationReportGenerator; $generator->setSource($volume); @@ -210,9 +202,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -230,9 +220,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new ImageLocationReportGenerator([ 'separateLabelTrees' => true, @@ -315,9 +303,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -335,9 +321,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new ImageLocationReportGenerator([ 'separateUsers' => true, diff --git a/tests/php/Services/Reports/Volumes/ImageLabels/BasicReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageLabels/BasicReportGeneratorTest.php index ffa46bc0e..b04b852a3 100644 --- a/tests/php/Services/Reports/Volumes/ImageLabels/BasicReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageLabels/BasicReportGeneratorTest.php @@ -74,9 +74,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new BasicReportGenerator; $generator->setSource($volume); @@ -126,9 +124,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new BasicReportGenerator([ 'separateLabelTrees' => true, @@ -175,9 +171,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $generator = new BasicReportGenerator([ 'separateUsers' => true, diff --git a/tests/php/Services/Reports/Volumes/ImageLabels/CsvReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageLabels/CsvReportGeneratorTest.php index 156d3ad80..605a0ecd1 100644 --- a/tests/php/Services/Reports/Volumes/ImageLabels/CsvReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageLabels/CsvReportGeneratorTest.php @@ -89,9 +89,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -102,9 +100,7 @@ public function testGenerateReport() $mock->shouldReceive('addFile')->once(); $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator; $generator->setSource($volume); @@ -176,9 +172,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -196,9 +190,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator([ 'separateLabelTrees' => true, @@ -276,9 +268,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -296,9 +286,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator([ 'separateUsers' => true, @@ -369,7 +357,7 @@ public function testGenerateReportWithDeletedUser() $il1->created_at, ]); - $mock->shouldReceive('putCsv') + $mock->shouldReceive('putCsv') ->once() ->with([ $il2->id, @@ -388,9 +376,7 @@ public function testGenerateReportWithDeletedUser() $mock->shouldReceive('close')->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -404,9 +390,7 @@ public function testGenerateReportWithDeletedUser() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator(); $generator->setSource($image->volume); diff --git a/tests/php/Services/Reports/Volumes/ImageLabels/ImageLocationReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/ImageLabels/ImageLocationReportGeneratorTest.php index a22271536..c28a1e204 100644 --- a/tests/php/Services/Reports/Volumes/ImageLabels/ImageLocationReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/ImageLabels/ImageLocationReportGeneratorTest.php @@ -71,9 +71,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -86,9 +84,7 @@ public function testGenerateReport() ->with('abc', "{$volume->id}-{$volume->name}.ndjson"); $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new ImageLocationReportGenerator; $generator->setSource($volume); @@ -115,9 +111,7 @@ public function testGenerateReportNoCoordinates() $mock->shouldReceive('close')->once(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -128,9 +122,7 @@ public function testGenerateReportNoCoordinates() $mock->shouldReceive('addFile')->once(); $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new ImageLocationReportGenerator; $generator->setSource($volume); @@ -201,9 +193,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -221,9 +211,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new ImageLocationReportGenerator([ 'separateLabelTrees' => true, @@ -302,9 +290,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(File::class, function () use ($mock) { - return $mock; - }); + App::singleton(File::class, fn () => $mock); $mock = Mockery::mock(); @@ -322,9 +308,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new ImageLocationReportGenerator([ 'separateUsers' => true, diff --git a/tests/php/Services/Reports/Volumes/VideoAnnotations/CsvReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/VideoAnnotations/CsvReportGeneratorTest.php index 7df233cc1..54fca943d 100644 --- a/tests/php/Services/Reports/Volumes/VideoAnnotations/CsvReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/VideoAnnotations/CsvReportGeneratorTest.php @@ -104,9 +104,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -120,9 +118,7 @@ public function testGenerateReport() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator; $generator->setSource($volume); @@ -204,9 +200,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -224,9 +218,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator([ 'separateLabelTrees' => true, @@ -314,9 +306,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -334,9 +324,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator([ 'separateUsers' => true, @@ -455,11 +443,11 @@ public function testGenerateReportWithDeletedUser() $annotation = VideoAnnotationTest::create(['video_id' => $video->id]); $al1 = VideoAnnotationLabelTest::create([ - 'annotation_id' => $annotation->id, + 'annotation_id' => $annotation->id, 'user_id' => null // deleted user ]); $al2 = VideoAnnotationLabelTest::create([ - 'annotation_id' => $annotation->id, + 'annotation_id' => $annotation->id, 'user_id' => $user->id ]); @@ -494,7 +482,7 @@ public function testGenerateReportWithDeletedUser() json_encode($video->attrs), ]); - $mock->shouldReceive('putCsv') + $mock->shouldReceive('putCsv') ->once() ->with([ $al2->id, @@ -517,9 +505,7 @@ public function testGenerateReportWithDeletedUser() $mock->shouldReceive('close')->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -533,14 +519,10 @@ public function testGenerateReportWithDeletedUser() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator; $generator->setSource($video->volume); $generator->generateReport('my/path'); } - - } diff --git a/tests/php/Services/Reports/Volumes/VideoLabels/CsvReportGeneratorTest.php b/tests/php/Services/Reports/Volumes/VideoLabels/CsvReportGeneratorTest.php index 185be5591..e304e8bec 100644 --- a/tests/php/Services/Reports/Volumes/VideoLabels/CsvReportGeneratorTest.php +++ b/tests/php/Services/Reports/Volumes/VideoLabels/CsvReportGeneratorTest.php @@ -85,9 +85,7 @@ public function testGenerateReport() $mock->shouldReceive('close') ->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -98,9 +96,7 @@ public function testGenerateReport() $mock->shouldReceive('addFile')->once(); $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator; $generator->setSource($volume); @@ -168,9 +164,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -188,9 +182,7 @@ public function testGenerateReportSeparateLabelTrees() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator([ 'separateLabelTrees' => true, @@ -264,9 +256,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close') ->twice(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -284,9 +274,7 @@ public function testGenerateReportSeparateUsers() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator([ 'separateUsers' => true, @@ -346,7 +334,7 @@ public function testGenerateReportWithDeletedUser() $il1->id, $video->id, $video->filename, - null, + null, null, null, $il1->label->id, @@ -355,7 +343,7 @@ public function testGenerateReportWithDeletedUser() $il1->created_at, ]); - $mock->shouldReceive('putCsv') + $mock->shouldReceive('putCsv') ->once() ->with([ $il2->id, @@ -372,9 +360,7 @@ public function testGenerateReportWithDeletedUser() $mock->shouldReceive('close')->once(); - App::singleton(CsvFile::class, function () use ($mock) { - return $mock; - }); + App::singleton(CsvFile::class, fn () => $mock); $mock = Mockery::mock(); @@ -388,9 +374,7 @@ public function testGenerateReportWithDeletedUser() $mock->shouldReceive('close')->once(); - App::singleton(ZipArchive::class, function () use ($mock) { - return $mock; - }); + App::singleton(ZipArchive::class, fn () => $mock); $generator = new CsvReportGenerator(); $generator->setSource($video->volume);