diff --git a/.gitignore b/.gitignore index 291b997ec..de7c717d3 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,5 @@ npm-debug.log yarn-error.log /*.sublime-* /*.phar -/*.php_cs.cache +/*.php-cs-fixer.cache /.idea -/.vscode diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 000000000..45a52dcba --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,34 @@ +files() + ->in([ + __DIR__.'/app', + __DIR__.'/tests', + __DIR__.'/config', + __DIR__.'/database', + // __DIR__.'/vendor/biigle', + ]) + ->name('*.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PSR2' => true, + 'ordered_imports' => true, + 'single_space_around_construct' => true, + 'array_indentation' => true, + 'array_syntax' => ['syntax' => 'short'], + 'combine_consecutive_unsets' => true, + 'class_attributes_separation' => ['elements' => ['method' => 'one', ]], + 'no_whitespace_before_comma_in_array' => true, + 'unary_operator_spaces' => true, + 'whitespace_after_comma_in_array' => true, + 'method_chaining_indentation' => true, + 'use_arrow_functions' => true, + 'no_unused_imports' => true + ]) + ->setFinder($finder) + ->setRiskyAllowed(true) + ->setUsingCache(true); diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 68b51e4e9..000000000 --- a/.php_cs +++ /dev/null @@ -1,16 +0,0 @@ -files() - ->in([__DIR__.'/app', __DIR__.'/tests', __DIR__.'/config', __DIR__.'/database', __DIR__.'/vendor/biigle']) - ->name('*.php') - ->ignoreDotFiles(true) - ->ignoreVCS(true); - -return PhpCsFixer\Config::create() - ->setRules([ - '@PSR2' => true, - 'ordered_imports' => true, - ]) - ->setFinder($finder) - ->setUsingCache(true); diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ebf74e96e..e7aa99d7a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,6 +26,6 @@ The default development setup of BIIGLE uses the `dev-modules` branch of the cor BIIGLE uses readable and meaningful commit messages. Please follow [this guide](https://chris.beams.io/posts/git-commit/) for your commits to BIIGLE. -BIIGLE also defines a PHP coding style in [`.php_cs`](.php_cs). Use the [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) to apply the coding style to your source code. +BIIGLE also defines a PHP coding style in [`.php-cs-fixer.php`](.php-cs-fixer.php). Use the [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) to apply the coding style to your source code. All changes or new features that affect the API or backend PHP code should be thoroughly tested. diff --git a/app/AnnotationSession.php b/app/AnnotationSession.php index 7b7595114..f583681ed 100644 --- a/app/AnnotationSession.php +++ b/app/AnnotationSession.php @@ -93,11 +93,12 @@ public function getVolumeFileAnnotations(VolumeFile $file, User $user) $query->with(['labels' => function ($query) use ($user) { // wrap this in a where because the default query already has a where $query->where(function ($query) use ($user) { - $query->where(function ($query) { - $query->where('created_at', '>=', $this->starts_at) - ->where('created_at', '<', $this->ends_at); - }) - ->orWhere('user_id', '!=', $user->id); + $query + ->where(function ($query) { + $query->where('created_at', '>=', $this->starts_at) + ->where('created_at', '<', $this->ends_at); + }) + ->orWhere('user_id', '!=', $user->id); }); }]); } else { @@ -205,25 +206,26 @@ public function imageAnnotations() { return ImageAnnotation::where(function ($query) { // all annotations of the associated volume - return $query->whereIn('image_id', function ($query) { - $query->select('id') + return $query + ->whereIn('image_id', function ($query) { + $query->select('id') ->from('images') ->where('volume_id', $this->volume_id); - }) - // that were created between the start and end date - ->where('created_at', '>=', $this->starts_at) - ->where('created_at', '<', $this->ends_at) - // and have a label by one of the members of this session - ->whereExists(function ($query) { - $query->select(DB::raw(1)) - ->from('image_annotation_labels') - ->whereRaw('image_annotation_labels.annotation_id = image_annotations.id') - ->whereIn('image_annotation_labels.user_id', function ($query) { - $query->select('user_id') - ->from('annotation_session_user') - ->where('annotation_session_id', $this->id); - }); - }); + }) + // that were created between the start and end date + ->where('created_at', '>=', $this->starts_at) + ->where('created_at', '<', $this->ends_at) + // and have a label by one of the members of this session + ->whereExists(function ($query) { + $query->select(DB::raw(1)) + ->from('image_annotation_labels') + ->whereRaw('image_annotation_labels.annotation_id = image_annotations.id') + ->whereIn('image_annotation_labels.user_id', function ($query) { + $query->select('user_id') + ->from('annotation_session_user') + ->where('annotation_session_id', $this->id); + }); + }); }); } @@ -238,25 +240,26 @@ public function videoAnnotations() { return VideoAnnotation::where(function ($query) { // all annotations of the associated volume - return $query->whereIn('video_id', function ($query) { - $query->select('id') + return $query + ->whereIn('video_id', function ($query) { + $query->select('id') ->from('videos') ->where('volume_id', $this->volume_id); - }) - // that were created between the start and end date - ->where('created_at', '>=', $this->starts_at) - ->where('created_at', '<', $this->ends_at) - // and have a label by one of the members of this session - ->whereExists(function ($query) { - $query->select(DB::raw(1)) - ->from('video_annotation_labels') - ->whereRaw('video_annotation_labels.annotation_id = video_annotations.id') - ->whereIn('video_annotation_labels.user_id', function ($query) { - $query->select('user_id') - ->from('annotation_session_user') - ->where('annotation_session_id', $this->id); - }); - }); + }) + // that were created between the start and end date + ->where('created_at', '>=', $this->starts_at) + ->where('created_at', '<', $this->ends_at) + // and have a label by one of the members of this session + ->whereExists(function ($query) { + $query->select(DB::raw(1)) + ->from('video_annotation_labels') + ->whereRaw('video_annotation_labels.annotation_id = video_annotations.id') + ->whereIn('video_annotation_labels.user_id', function ($query) { + $query->select('user_id') + ->from('annotation_session_user') + ->where('annotation_session_id', $this->id); + }); + }); }); } } diff --git a/app/Console/Commands/MigrateTiledImages.php b/app/Console/Commands/MigrateTiledImages.php index 99d4940f8..c1b014910 100644 --- a/app/Console/Commands/MigrateTiledImages.php +++ b/app/Console/Commands/MigrateTiledImages.php @@ -4,7 +4,6 @@ use Biigle\Image; use Biigle\Jobs\MigrateTiledImage; -use Biigle\Volume; use Illuminate\Console\Command; use Queue; diff --git a/app/Console/Commands/UpdateVideoMetadata.php b/app/Console/Commands/UpdateVideoMetadata.php index dccbd227e..feeb1588d 100644 --- a/app/Console/Commands/UpdateVideoMetadata.php +++ b/app/Console/Commands/UpdateVideoMetadata.php @@ -65,7 +65,7 @@ public function processVolume(Volume $volume) $query = $volume->videos() ->where(function ($query) { $query->whereNull('attrs->width') - ->orWhereNull('attrs->height'); + ->orWhereNull('attrs->height'); }); if ($volume->isRemote()) { diff --git a/app/Console/Commands/UpdateVolumeUrls.php b/app/Console/Commands/UpdateVolumeUrls.php index 9f019117a..1b808c054 100644 --- a/app/Console/Commands/UpdateVolumeUrls.php +++ b/app/Console/Commands/UpdateVolumeUrls.php @@ -65,9 +65,7 @@ protected function updateVolumes($volumes) $url = $volumes->first(); $prefix = $this->ask('Please enter the volume URL prefix that you want to replace with a storage disk.', dirname($url)); - $matches = $volumes->filter(function ($url) use ($prefix) { - return strpos($url, $prefix) === 0; - }); + $matches = $volumes->filter(fn ($url) => strpos($url, $prefix) === 0); $matchesCount = $matches->count(); if ($matchesCount > 0) { diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 64e0a7e45..19b62a5aa 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -27,7 +27,8 @@ protected function schedule(Schedule $schedule): void ->daily() ->onOneServer(); - $schedule->call(function () { + $schedule + ->call(function () { if (FederatedSearchInstance::withLocalToken()->exists()) { GenerateFederatedSearchIndex::dispatch(); } @@ -38,7 +39,8 @@ protected function schedule(Schedule $schedule): void ->hourlyAt(55) ->onOneServer(); - $schedule->call(function () { + $schedule + ->call(function () { FederatedSearchInstance::withRemoteToken() ->eachById([UpdateFederatedSearchIndex::class, 'dispatch']); }) diff --git a/app/Events/ObjectTrackingFailed.php b/app/Events/ObjectTrackingFailed.php index 7d5898ad5..05c109fb0 100644 --- a/app/Events/ObjectTrackingFailed.php +++ b/app/Events/ObjectTrackingFailed.php @@ -5,10 +5,7 @@ use Biigle\Broadcasting\UserChannel; use Biigle\User; use Biigle\VideoAnnotation; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; diff --git a/app/Events/ObjectTrackingSucceeded.php b/app/Events/ObjectTrackingSucceeded.php index b67a2315a..3c5afb4fa 100644 --- a/app/Events/ObjectTrackingSucceeded.php +++ b/app/Events/ObjectTrackingSucceeded.php @@ -5,10 +5,7 @@ use Biigle\Broadcasting\UserChannel; use Biigle\User; use Biigle\VideoAnnotation; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; diff --git a/app/Http/Controllers/Api/AnnotationSessionController.php b/app/Http/Controllers/Api/AnnotationSessionController.php index 9a3552e01..424e94a7d 100644 --- a/app/Http/Controllers/Api/AnnotationSessionController.php +++ b/app/Http/Controllers/Api/AnnotationSessionController.php @@ -2,7 +2,6 @@ namespace Biigle\Http\Controllers\Api; -use Biigle\AnnotationSession; use Biigle\Http\Requests\DestroyAnnotationSession; use Biigle\Http\Requests\UpdateAnnotationSession; use Biigle\Volume; diff --git a/app/Http/Controllers/Api/Annotations/Filters/AnnotationUserController.php b/app/Http/Controllers/Api/Annotations/Filters/AnnotationUserController.php index 8071e78ec..19af1e5ff 100644 --- a/app/Http/Controllers/Api/Annotations/Filters/AnnotationUserController.php +++ b/app/Http/Controllers/Api/Annotations/Filters/AnnotationUserController.php @@ -54,12 +54,13 @@ public function index(Request $request, $tid, $uid) $ownerKeyName = $fileRelation->getQualifiedOwnerKeyName(); $labelsRelation = $model->labels(); - return $query->join($labelsRelation->getRelated()->getTable(), $labelsRelation->getQualifiedParentKeyName(), '=', $labelsRelation->getQualifiedForeignKeyName()) - ->where($labelsRelation->getRelated()->user()->getQualifiedForeignKeyName(), $uid) - ->join($fileRelation->getRelated()->getTable(), $fileRelation->getQualifiedForeignKeyName(), '=', $ownerKeyName) - ->where($fileRelation->getRelated()->volume()->getQualifiedForeignKeyName(), $tid) - ->select($ownerKeyName) - ->distinct() - ->pluck($ownerKeyName); + return $query + ->join($labelsRelation->getRelated()->getTable(), $labelsRelation->getQualifiedParentKeyName(), '=', $labelsRelation->getQualifiedForeignKeyName()) + ->where($labelsRelation->getRelated()->user()->getQualifiedForeignKeyName(), $uid) + ->join($fileRelation->getRelated()->getTable(), $fileRelation->getQualifiedForeignKeyName(), '=', $ownerKeyName) + ->where($fileRelation->getRelated()->volume()->getQualifiedForeignKeyName(), $tid) + ->select($ownerKeyName) + ->distinct() + ->pluck($ownerKeyName); } } diff --git a/app/Http/Controllers/Api/AnnouncementController.php b/app/Http/Controllers/Api/AnnouncementController.php index 601675279..2156e071a 100644 --- a/app/Http/Controllers/Api/AnnouncementController.php +++ b/app/Http/Controllers/Api/AnnouncementController.php @@ -2,9 +2,8 @@ namespace Biigle\Http\Controllers\Api; -use Biigle\Http\Requests\StoreAnnouncement; use Biigle\Announcement; -use Illuminate\Http\Request; +use Biigle\Http\Requests\StoreAnnouncement; class AnnouncementController extends Controller { diff --git a/app/Http/Controllers/Api/ImageAnnotationBulkController.php b/app/Http/Controllers/Api/ImageAnnotationBulkController.php index 27fcff427..c22472999 100644 --- a/app/Http/Controllers/Api/ImageAnnotationBulkController.php +++ b/app/Http/Controllers/Api/ImageAnnotationBulkController.php @@ -100,8 +100,8 @@ public function store(StoreImageAnnotations $request) $annotations->each(function ($annotation) use ($request) { $label = $request->labels[$annotation->label_id]; $confidence = $annotation->confidence; - unset($annotation->label_id); - unset($annotation->confidence); + unset($annotation->label_id, $annotation->confidence); + $this->authorize('attach-label', [$annotation, $label]); $annotation->save(); diff --git a/app/Http/Controllers/Api/ImageController.php b/app/Http/Controllers/Api/ImageController.php index 4aecfe09c..2d5e32e1e 100644 --- a/app/Http/Controllers/Api/ImageController.php +++ b/app/Http/Controllers/Api/ImageController.php @@ -42,7 +42,6 @@ public function show($id) return $image; } - /** * Shows the specified image file. * diff --git a/app/Http/Controllers/Api/LabelTreeMergeController.php b/app/Http/Controllers/Api/LabelTreeMergeController.php index 5c1af8efa..f92611947 100644 --- a/app/Http/Controllers/Api/LabelTreeMergeController.php +++ b/app/Http/Controllers/Api/LabelTreeMergeController.php @@ -2,7 +2,6 @@ namespace Biigle\Http\Controllers\Api; -use Biigle\Http\Controllers\Api\Controller; use Biigle\Http\Requests\StoreLabelTreeMerge; use Biigle\Label; use DB; diff --git a/app/Http/Controllers/Api/LabelTreeVersionController.php b/app/Http/Controllers/Api/LabelTreeVersionController.php index a2d97135b..43ec57a74 100644 --- a/app/Http/Controllers/Api/LabelTreeVersionController.php +++ b/app/Http/Controllers/Api/LabelTreeVersionController.php @@ -5,14 +5,12 @@ use Biigle\Http\Requests\DestroyLabelTreeVersion; use Biigle\Http\Requests\StoreLabelTreeVersion; use Biigle\Http\Requests\UpdateLabelTreeVersion; -use Biigle\LabelTree; use Biigle\LabelTreeVersion; use DB; use Ramsey\Uuid\Uuid; class LabelTreeVersionController extends Controller { - /** * Creates a new label tree version. * diff --git a/app/Http/Controllers/Api/LinkVideoAnnotationController.php b/app/Http/Controllers/Api/LinkVideoAnnotationController.php index f1ab334a1..08b885328 100644 --- a/app/Http/Controllers/Api/LinkVideoAnnotationController.php +++ b/app/Http/Controllers/Api/LinkVideoAnnotationController.php @@ -2,10 +2,8 @@ namespace Biigle\Http\Controllers\Api; -use Biigle\Http\Controllers\Api\Controller; use Biigle\Http\Requests\LinkVideoAnnotation; use Biigle\VideoAnnotation; -use Biigle\VideoAnnotationLabel; use DB; class LinkVideoAnnotationController extends Controller diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index 4b580f6d4..635ab0dcb 100644 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -6,7 +6,6 @@ use Biigle\Http\Requests\UpdateProject; use Biigle\Project; use Illuminate\Http\Request; -use Route; use Symfony\Component\HttpKernel\Exception\HttpException; class ProjectController extends Controller diff --git a/app/Http/Controllers/Api/ProjectLabelTreeController.php b/app/Http/Controllers/Api/ProjectLabelTreeController.php index caa7887ce..2db28f374 100644 --- a/app/Http/Controllers/Api/ProjectLabelTreeController.php +++ b/app/Http/Controllers/Api/ProjectLabelTreeController.php @@ -5,8 +5,6 @@ use Biigle\Http\Requests\StoreProjectLabelTree; use Biigle\LabelTree; use Biigle\Project; -use Biigle\Visibility; -use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Http\Request; class ProjectLabelTreeController extends Controller diff --git a/app/Http/Controllers/Api/ProjectVolumeController.php b/app/Http/Controllers/Api/ProjectVolumeController.php index 41fbdbab4..47e1e53e2 100644 --- a/app/Http/Controllers/Api/ProjectVolumeController.php +++ b/app/Http/Controllers/Api/ProjectVolumeController.php @@ -4,7 +4,6 @@ use Biigle\Http\Requests\StoreVolume; use Biigle\Jobs\CreateNewImagesOrVideos; -use Biigle\MediaType; use Biigle\Project; use Biigle\Volume; use DB; diff --git a/app/Http/Controllers/Api/ProjectsAttachableVolumesController.php b/app/Http/Controllers/Api/ProjectsAttachableVolumesController.php index d8b16efae..94bccbd0e 100644 --- a/app/Http/Controllers/Api/ProjectsAttachableVolumesController.php +++ b/app/Http/Controllers/Api/ProjectsAttachableVolumesController.php @@ -2,7 +2,6 @@ namespace Biigle\Http\Controllers\Api; -use Biigle\Http\Controllers\Api\Controller; use Biigle\Project; use Biigle\Role; use Biigle\Volume; diff --git a/app/Http/Controllers/Api/SplitVideoAnnotationController.php b/app/Http/Controllers/Api/SplitVideoAnnotationController.php index 3a6a0db75..10537f8b7 100644 --- a/app/Http/Controllers/Api/SplitVideoAnnotationController.php +++ b/app/Http/Controllers/Api/SplitVideoAnnotationController.php @@ -2,7 +2,6 @@ namespace Biigle\Http\Controllers\Api; -use Biigle\Http\Controllers\Api\Controller; use Biigle\Http\Requests\SplitVideoAnnotation; use Biigle\Shape; use Biigle\VideoAnnotation; diff --git a/app/Http/Controllers/Api/UserRegistrationController.php b/app/Http/Controllers/Api/UserRegistrationController.php index 64bc85b10..03b0fe15d 100644 --- a/app/Http/Controllers/Api/UserRegistrationController.php +++ b/app/Http/Controllers/Api/UserRegistrationController.php @@ -8,7 +8,6 @@ use Biigle\User; use Illuminate\Http\Request; use Illuminate\Http\Response; -use Illuminate\Validation\ValidationException; class UserRegistrationController extends Controller { diff --git a/app/Http/Controllers/Api/UserSettingsController.php b/app/Http/Controllers/Api/UserSettingsController.php index 6edbc362e..2603a44bc 100644 --- a/app/Http/Controllers/Api/UserSettingsController.php +++ b/app/Http/Controllers/Api/UserSettingsController.php @@ -3,7 +3,6 @@ namespace Biigle\Http\Controllers\Api; use Biigle\Http\Requests\UpdateUserSettings; -use Illuminate\Http\Request; class UserSettingsController extends Controller { diff --git a/app/Http/Controllers/Api/VideoAnnotationController.php b/app/Http/Controllers/Api/VideoAnnotationController.php index fff60e043..8e2972122 100644 --- a/app/Http/Controllers/Api/VideoAnnotationController.php +++ b/app/Http/Controllers/Api/VideoAnnotationController.php @@ -2,7 +2,6 @@ namespace Biigle\Http\Controllers\Api; -use Biigle\Http\Controllers\Api\Controller; use Biigle\Http\Requests\StoreVideoAnnotation; use Biigle\Http\Requests\UpdateVideoAnnotation; use Biigle\Jobs\TrackObject; diff --git a/app/Http/Controllers/Api/VideoAnnotationLabelController.php b/app/Http/Controllers/Api/VideoAnnotationLabelController.php index 0a688db04..c949988c7 100644 --- a/app/Http/Controllers/Api/VideoAnnotationLabelController.php +++ b/app/Http/Controllers/Api/VideoAnnotationLabelController.php @@ -2,7 +2,6 @@ namespace Biigle\Http\Controllers\Api; -use Biigle\Http\Controllers\Api\Controller; use Biigle\Http\Requests\DestroyVideoAnnotationLabel; use Biigle\Http\Requests\StoreVideoAnnotationLabel; use Biigle\VideoAnnotationLabel; diff --git a/app/Http/Controllers/Api/VideoController.php b/app/Http/Controllers/Api/VideoController.php index 1ee89af32..a38813e8a 100644 --- a/app/Http/Controllers/Api/VideoController.php +++ b/app/Http/Controllers/Api/VideoController.php @@ -2,12 +2,8 @@ namespace Biigle\Http\Controllers\Api; -use Biigle\Http\Controllers\Api\Controller; use Biigle\Http\Requests\DestroyVideo; -use Biigle\Http\Requests\UpdateVideo; -use Biigle\Jobs\ProcessNewVideo; use Biigle\Video; -use Queue; class VideoController extends Controller { diff --git a/app/Http/Controllers/Api/VideoFileController.php b/app/Http/Controllers/Api/VideoFileController.php index 80b031a17..ab3b5ccf5 100644 --- a/app/Http/Controllers/Api/VideoFileController.php +++ b/app/Http/Controllers/Api/VideoFileController.php @@ -2,7 +2,6 @@ namespace Biigle\Http\Controllers\Api; -use Biigle\Http\Controllers\Api\Controller; use Biigle\Video; use Exception; use FileCache; diff --git a/app/Http/Controllers/Api/VolumeController.php b/app/Http/Controllers/Api/VolumeController.php index 37d615f59..2ced33713 100644 --- a/app/Http/Controllers/Api/VolumeController.php +++ b/app/Http/Controllers/Api/VolumeController.php @@ -15,8 +15,6 @@ class VolumeController extends Controller { - - /** * Shows all volumes the user has access to. * @@ -151,7 +149,6 @@ public function update(UpdateVolume $request) } } - /** * Clones volume to destination project. * diff --git a/app/Http/Controllers/Api/VolumeFileController.php b/app/Http/Controllers/Api/VolumeFileController.php index 8b855ed9e..ef3af4d85 100644 --- a/app/Http/Controllers/Api/VolumeFileController.php +++ b/app/Http/Controllers/Api/VolumeFileController.php @@ -5,7 +5,6 @@ use Biigle\Http\Requests\StoreVolumeFile; use Biigle\Jobs\CreateNewImagesOrVideos; use Biigle\Volume; -use DB; class VolumeFileController extends Controller { diff --git a/app/Http/Controllers/Api/VolumeFileLabelController.php b/app/Http/Controllers/Api/VolumeFileLabelController.php index 1ed2da6c3..9ae82f02d 100644 --- a/app/Http/Controllers/Api/VolumeFileLabelController.php +++ b/app/Http/Controllers/Api/VolumeFileLabelController.php @@ -3,8 +3,6 @@ namespace Biigle\Http\Controllers\Api; use Biigle\Http\Requests\StoreVolumeFileLabel; -use Biigle\Image; -use Biigle\ImageLabel; use Biigle\Label; abstract class VolumeFileLabelController extends Controller diff --git a/app/Http/Controllers/Api/Volumes/BrowserController.php b/app/Http/Controllers/Api/Volumes/BrowserController.php index d1a926cd1..0eba09873 100644 --- a/app/Http/Controllers/Api/Volumes/BrowserController.php +++ b/app/Http/Controllers/Api/Volumes/BrowserController.php @@ -164,8 +164,6 @@ protected function removePrefix($prefix, $list) $prefix = preg_quote($prefix); $regex = "!^{$prefix}/?!"; - return array_map(function ($item) use ($regex) { - return preg_replace($regex, '', $item); - }, $list); + return array_map(fn ($item) => preg_replace($regex, '', $item), $list); } } diff --git a/app/Http/Controllers/Api/Volumes/FileLabelsController.php b/app/Http/Controllers/Api/Volumes/FileLabelsController.php index 46bb3e155..b6b8277c9 100644 --- a/app/Http/Controllers/Api/Volumes/FileLabelsController.php +++ b/app/Http/Controllers/Api/Volumes/FileLabelsController.php @@ -56,8 +56,6 @@ public function index($id) ->select('id') ->get() ->keyBy('id') - ->map(function ($image) { - return $image->labels; - }); + ->map(fn ($image) => $image->labels); } } diff --git a/app/Http/Controllers/Api/Volumes/Filters/AnnotationLabelController.php b/app/Http/Controllers/Api/Volumes/Filters/AnnotationLabelController.php index 3f294fa68..080258eda 100644 --- a/app/Http/Controllers/Api/Volumes/Filters/AnnotationLabelController.php +++ b/app/Http/Controllers/Api/Volumes/Filters/AnnotationLabelController.php @@ -53,12 +53,13 @@ public function index(Request $request, $tid, $lid) $ownerKeyName = $fileRelation->getQualifiedOwnerKeyName(); $labelsRelation = $model->labels(); - return $query->join($labelsRelation->getRelated()->getTable(), $labelsRelation->getQualifiedParentKeyName(), '=', $labelsRelation->getQualifiedForeignKeyName()) - ->where($labelsRelation->getRelated()->label()->getQualifiedForeignKeyName(), $lid) - ->join($fileRelation->getRelated()->getTable(), $fileRelation->getQualifiedForeignKeyName(), '=', $ownerKeyName) - ->where($fileRelation->getRelated()->volume()->getQualifiedForeignKeyName(), $tid) - ->select($ownerKeyName) - ->distinct() - ->pluck($ownerKeyName); + return $query + ->join($labelsRelation->getRelated()->getTable(), $labelsRelation->getQualifiedParentKeyName(), '=', $labelsRelation->getQualifiedForeignKeyName()) + ->where($labelsRelation->getRelated()->label()->getQualifiedForeignKeyName(), $lid) + ->join($fileRelation->getRelated()->getTable(), $fileRelation->getQualifiedForeignKeyName(), '=', $ownerKeyName) + ->where($fileRelation->getRelated()->volume()->getQualifiedForeignKeyName(), $tid) + ->select($ownerKeyName) + ->distinct() + ->pluck($ownerKeyName); } } diff --git a/app/Http/Controllers/Api/Volumes/MetadataController.php b/app/Http/Controllers/Api/Volumes/MetadataController.php index 6b266d4ab..7ba285721 100644 --- a/app/Http/Controllers/Api/Volumes/MetadataController.php +++ b/app/Http/Controllers/Api/Volumes/MetadataController.php @@ -122,9 +122,7 @@ protected function updateVideoMetadata(StoreVolumeMetadata $request) $columns = collect(array_shift($metadata)); $rowsByFile = collect($metadata) - ->map(function ($row) use ($columns) { - return $columns->combine($row); - }) + ->map(fn ($row) => $columns->combine($row)) ->map(function ($row) { if ($row->has('taken_at')) { $row['taken_at'] = Carbon::parse($row['taken_at']); @@ -164,25 +162,25 @@ protected function mergeVideoMetadata(Video $video, Collection $rows) { $metadata = collect(); // Everything will be indexed by the timestamps below. - $origTakenAt = collect($video->taken_at)->map(function ($time) { - return $time->getTimestamp(); - }); - $newTakenAt = $rows->pluck('taken_at')->filter()->map(function ($time) { - return $time->getTimestamp(); - }); + $origTakenAt = collect($video->taken_at)->map(fn ($time) => $time->getTimestamp()); + $newTakenAt = $rows->pluck('taken_at')->filter()->map(fn ($time) => $time->getTimestamp()); if ($origTakenAt->isEmpty() && $this->hasMetadata($video)) { if ($rows->count() > 1 || $newTakenAt->isNotEmpty()) { - throw ValidationException::withMessages([ - 'metadata' => ["Metadata of video '{$video->filename}' has no 'taken_at' timestamps and cannot be updated with new metadata that has timestamps."], - ]); + throw ValidationException::withMessages( + [ + 'metadata' => ["Metadata of video '{$video->filename}' has no 'taken_at' timestamps and cannot be updated with new metadata that has timestamps."], + ] + ); } return $rows->first(); } elseif ($newTakenAt->isEmpty()) { - throw ValidationException::withMessages([ + throw ValidationException::withMessages( + [ 'metadata' => ["Metadata of video '{$video->filename}' has 'taken_at' timestamps and cannot be updated with new metadata that has no timestamps."], - ]); + ] + ); } // These are used to fill missing values with null. @@ -190,14 +188,10 @@ protected function mergeVideoMetadata(Video $video, Collection $rows) $newTakenAtNull = $newTakenAt->combine($newTakenAt->map(fn ($x) => null)); $originalAttributes = collect(VideoMetadata::ALLOWED_ATTRIBUTES) - ->mapWithKeys(function ($key) use ($video) { - return [$key => $video->$key]; - }); + ->mapWithKeys(fn ($key) => [$key => $video->$key]); $originalMetadata = collect(VideoMetadata::ALLOWED_METADATA) - ->mapWithKeys(function ($key) use ($video) { - return [$key => null]; - }) + ->mapWithKeys(fn ($key) => [$key => null]) ->merge($video->metadata); $originalData = $originalMetadata->merge($originalAttributes); diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 5c2200640..fbc67397e 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -6,6 +6,7 @@ use Biigle\Http\Requests\StoreUser; use Biigle\Notifications\RegistrationConfirmation; use Biigle\Role; +use Biigle\Services\Modules; use Biigle\User; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Http\Request; @@ -13,7 +14,6 @@ use Illuminate\Support\Facades\Hash; use Notification; use Ramsey\Uuid\Uuid; -use Biigle\Services\Modules; use Validator; use View; diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index a4b1962f0..02e30c16d 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -3,7 +3,6 @@ namespace Biigle\Http\Controllers\Auth; use Biigle\Http\Controllers\Controller; -use Biigle\User; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\Request; diff --git a/app/Http/Controllers/Views/Admin/AnnouncementsController.php b/app/Http/Controllers/Views/Admin/AnnouncementsController.php index 0f802bd58..3e3cfb0fe 100644 --- a/app/Http/Controllers/Views/Admin/AnnouncementsController.php +++ b/app/Http/Controllers/Views/Admin/AnnouncementsController.php @@ -2,8 +2,8 @@ namespace Biigle\Http\Controllers\Views\Admin; -use Biigle\Http\Controllers\Controller; use Biigle\Announcement; +use Biigle\Http\Controllers\Controller; class AnnouncementsController extends Controller { diff --git a/app/Http/Controllers/Views/Admin/IndexController.php b/app/Http/Controllers/Views/Admin/IndexController.php index 5e10a3639..c775d0a9b 100644 --- a/app/Http/Controllers/Views/Admin/IndexController.php +++ b/app/Http/Controllers/Views/Admin/IndexController.php @@ -29,16 +29,14 @@ public function get(Modules $modules) $installedModules = $modules->getInstalledModules(); $days = collect([7, 6, 5, 4, 3, 2, 1, 0]) - ->map(fn($item) => Carbon::today()->subDays($item)); + ->map(fn ($item) => Carbon::today()->subDays($item)); $imageData = ImageAnnotation::selectRaw('created_at::date as day, count(id)') ->where('created_at', '>=', Carbon::today()->subWeek()) ->groupBy('day') ->pluck('count', 'day'); - $imageAnnotationWeek = $days->map(function ($day) use ($imageData) { - return $imageData->get($day->toDateString(), 0); - }); + $imageAnnotationWeek = $days->map(fn ($day) => $imageData->get($day->toDateString(), 0)); $totalAnnotations = number_format(ImageAnnotation::count()); $videoData = VideoAnnotation::selectRaw('created_at::date as day, count(id)') @@ -46,12 +44,10 @@ public function get(Modules $modules) ->groupBy('day') ->pluck('count', 'day'); - $videoAnnotationWeek = $days->map(function ($day) use ($videoData) { - return $videoData->get($day->toDateString(), 0); - }); + $videoAnnotationWeek = $days->map(fn ($day) => $videoData->get($day->toDateString(), 0)); $totalVideoAnnotations = number_format(VideoAnnotation::count()); - $dayNames = $days->map(fn($day) => $day->format('D')); + $dayNames = $days->map(fn ($day) => $day->format('D')); return view('admin.index', compact( 'activeUsersLastDay', diff --git a/app/Http/Controllers/Views/Admin/LogsController.php b/app/Http/Controllers/Views/Admin/LogsController.php index 0fb3861f1..59ee8efa0 100644 --- a/app/Http/Controllers/Views/Admin/LogsController.php +++ b/app/Http/Controllers/Views/Admin/LogsController.php @@ -4,8 +4,6 @@ use Biigle\Http\Controllers\Controller; use Biigle\Logging\LogManager; -use Carbon\Carbon; -use File; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Pagination\LengthAwarePaginator; diff --git a/app/Http/Controllers/Views/Admin/UsersController.php b/app/Http/Controllers/Views/Admin/UsersController.php index 7556c737f..8bd7a75cf 100644 --- a/app/Http/Controllers/Views/Admin/UsersController.php +++ b/app/Http/Controllers/Views/Admin/UsersController.php @@ -5,14 +5,11 @@ use Biigle\Http\Controllers\Controller; use Biigle\Image; use Biigle\ImageAnnotation; -use Biigle\ImageAnnotationLabel; use Biigle\Project; use Biigle\Role; use Biigle\Services\Modules; use Biigle\User; -use Biigle\Video; use Biigle\VideoAnnotation; -use Biigle\VideoAnnotationLabel; use Biigle\Volume; use Illuminate\Http\Request; diff --git a/app/Http/Controllers/Views/DashboardController.php b/app/Http/Controllers/Views/DashboardController.php index d07b8f92b..00c209ea3 100644 --- a/app/Http/Controllers/Views/DashboardController.php +++ b/app/Http/Controllers/Views/DashboardController.php @@ -3,8 +3,6 @@ namespace Biigle\Http\Controllers\Views; use Biigle\Image; -use Biigle\ImageLabel; -use Biigle\Services\Modules; use Biigle\User; use Biigle\Video; use Biigle\Volume; diff --git a/app/Http/Controllers/Views/LabelTrees/LabelTreeMembersController.php b/app/Http/Controllers/Views/LabelTrees/LabelTreeMembersController.php index 6f1236827..eec802c05 100644 --- a/app/Http/Controllers/Views/LabelTrees/LabelTreeMembersController.php +++ b/app/Http/Controllers/Views/LabelTrees/LabelTreeMembersController.php @@ -38,9 +38,7 @@ public function show(Request $request, $id) $members = $tree->members() ->select('id', 'firstname', 'lastname', 'label_tree_user.role_id', 'affiliation') ->get() - ->sort(function ($a, $b) use ($roleOrder) { - return array_search($b->role_id, $roleOrder) - array_search($a->role_id, $roleOrder); - }) + ->sort(fn ($a, $b) => array_search($b->role_id, $roleOrder) - array_search($a->role_id, $roleOrder)) ->values(); diff --git a/app/Http/Controllers/Views/LabelTrees/LabelTreeMergeController.php b/app/Http/Controllers/Views/LabelTrees/LabelTreeMergeController.php index b603985a3..5d7c855c0 100644 --- a/app/Http/Controllers/Views/LabelTrees/LabelTreeMergeController.php +++ b/app/Http/Controllers/Views/LabelTrees/LabelTreeMergeController.php @@ -4,10 +4,6 @@ use Biigle\Http\Controllers\Views\Controller; use Biigle\LabelTree; -use Biigle\LabelTreeVersion; -use Biigle\Project; -use Biigle\Visibility; -use DB; use Illuminate\Http\Request; class LabelTreeMergeController extends Controller diff --git a/app/Http/Controllers/Views/LabelTrees/LabelTreeVersionsController.php b/app/Http/Controllers/Views/LabelTrees/LabelTreeVersionsController.php index 6063070ab..dafbd5ce8 100644 --- a/app/Http/Controllers/Views/LabelTrees/LabelTreeVersionsController.php +++ b/app/Http/Controllers/Views/LabelTrees/LabelTreeVersionsController.php @@ -5,8 +5,6 @@ use Biigle\Http\Controllers\Views\Controller; use Biigle\LabelTree; use Biigle\LabelTreeVersion; -use Biigle\Project; -use Biigle\Visibility; use Illuminate\Http\Request; class LabelTreeVersionsController extends Controller diff --git a/app/Http/Controllers/Views/LabelTrees/LabelTreesController.php b/app/Http/Controllers/Views/LabelTrees/LabelTreesController.php index d07e686de..2e1385d3c 100644 --- a/app/Http/Controllers/Views/LabelTrees/LabelTreesController.php +++ b/app/Http/Controllers/Views/LabelTrees/LabelTreesController.php @@ -6,7 +6,6 @@ use Biigle\LabelSource; use Biigle\LabelTree; use Biigle\Project; -use Biigle\Role; use Biigle\User; use Biigle\Visibility; use Illuminate\Http\Request; diff --git a/app/Http/Controllers/Views/Projects/ProjectInvitationController.php b/app/Http/Controllers/Views/Projects/ProjectInvitationController.php index 9e0420b7c..150262729 100644 --- a/app/Http/Controllers/Views/Projects/ProjectInvitationController.php +++ b/app/Http/Controllers/Views/Projects/ProjectInvitationController.php @@ -5,7 +5,6 @@ use Biigle\Http\Controllers\Views\Controller; use Biigle\ProjectInvitation; use Illuminate\Http\Request; -use Illuminate\Http\Response; class ProjectInvitationController extends Controller { diff --git a/app/Http/Controllers/Views/Projects/ProjectLabelTreeController.php b/app/Http/Controllers/Views/Projects/ProjectLabelTreeController.php index d0b826fa5..cbff19415 100644 --- a/app/Http/Controllers/Views/Projects/ProjectLabelTreeController.php +++ b/app/Http/Controllers/Views/Projects/ProjectLabelTreeController.php @@ -4,10 +4,7 @@ use Biigle\Http\Controllers\Views\Controller; use Biigle\Project; -use Biigle\Role; -use Biigle\Video; use Illuminate\Http\Request; -use Illuminate\Http\Response; class ProjectLabelTreeController extends Controller { diff --git a/app/Http/Controllers/Views/Projects/ProjectStatisticsController.php b/app/Http/Controllers/Views/Projects/ProjectStatisticsController.php index 8917a49b6..04e70c4a8 100644 --- a/app/Http/Controllers/Views/Projects/ProjectStatisticsController.php +++ b/app/Http/Controllers/Views/Projects/ProjectStatisticsController.php @@ -4,14 +4,11 @@ use Biigle\Http\Controllers\Views\Controller; use Biigle\Image; -use Biigle\ImageAnnotation; use Biigle\MediaType; use Biigle\Project; use Biigle\Video; -use Biigle\VideoAnnotation; use DB; use Illuminate\Http\Request; -use Illuminate\Http\Response; class ProjectStatisticsController extends Controller { diff --git a/app/Http/Controllers/Views/Projects/ProjectUserController.php b/app/Http/Controllers/Views/Projects/ProjectUserController.php index 2c9cc8e58..a474218e3 100644 --- a/app/Http/Controllers/Views/Projects/ProjectUserController.php +++ b/app/Http/Controllers/Views/Projects/ProjectUserController.php @@ -5,9 +5,7 @@ use Biigle\Http\Controllers\Views\Controller; use Biigle\Project; use Biigle\Role; -use Biigle\Video; use Illuminate\Http\Request; -use Illuminate\Http\Response; class ProjectUserController extends Controller { @@ -40,9 +38,7 @@ public function show(Request $request, $id) $members = $project->users() ->select('id', 'firstname', 'lastname', 'project_role_id as role_id', 'affiliation') ->get() - ->sort(function ($a, $b) use ($roleOrder) { - return array_search($b->role_id, $roleOrder) - array_search($a->role_id, $roleOrder); - }) + ->sort(fn ($a, $b) => array_search($b->role_id, $roleOrder) - array_search($a->role_id, $roleOrder)) ->values(); $userProject = $request->user()->projects()->where('id', $id)->first(); diff --git a/app/Http/Controllers/Views/Projects/ProjectsController.php b/app/Http/Controllers/Views/Projects/ProjectsController.php index 5edb2d5c5..e04d206ef 100644 --- a/app/Http/Controllers/Views/Projects/ProjectsController.php +++ b/app/Http/Controllers/Views/Projects/ProjectsController.php @@ -4,8 +4,6 @@ use Biigle\Http\Controllers\Views\Controller; use Biigle\Project; -use Biigle\Role; -use Biigle\Video; use Illuminate\Http\Request; class ProjectsController extends Controller diff --git a/app/Http/Controllers/Views/Volumes/VolumeCloneController.php b/app/Http/Controllers/Views/Volumes/VolumeCloneController.php index 53e5bfc23..5d7b5ebe7 100644 --- a/app/Http/Controllers/Views/Volumes/VolumeCloneController.php +++ b/app/Http/Controllers/Views/Volumes/VolumeCloneController.php @@ -2,17 +2,16 @@ namespace Biigle\Http\Controllers\Views\Volumes; +use \Illuminate\Contracts\View\View; use Biigle\Http\Controllers\Views\Controller; use Biigle\LabelTree; use Biigle\Project; use Biigle\Role; use Biigle\Volume; use Illuminate\Http\Request; -use \Illuminate\Contracts\View\View; class VolumeCloneController extends Controller { - /** * Shows the volume clone page. * @param Request $request @@ -20,7 +19,7 @@ class VolumeCloneController extends Controller * * @return View **/ - function clone(Request $request, $id) + public function clone(Request $request, $id) { $volume = Volume::findOrFail($id); $this->authorize('update', $volume); @@ -56,5 +55,4 @@ function clone(Request $request, $id) 'labelTrees' => $labelTrees ]); } - } diff --git a/app/Http/Controllers/Views/Volumes/VolumeController.php b/app/Http/Controllers/Views/Volumes/VolumeController.php index f4f62687c..17266ecea 100644 --- a/app/Http/Controllers/Views/Volumes/VolumeController.php +++ b/app/Http/Controllers/Views/Volumes/VolumeController.php @@ -13,7 +13,6 @@ use Biigle\Volume; use Carbon\Carbon; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Storage; class VolumeController extends Controller { diff --git a/app/Http/Requests/CloneVolume.php b/app/Http/Requests/CloneVolume.php index e181f297a..729aed84f 100644 --- a/app/Http/Requests/CloneVolume.php +++ b/app/Http/Requests/CloneVolume.php @@ -2,9 +2,9 @@ namespace Biigle\Http\Requests; +use \Illuminate\Foundation\Http\FormRequest; use Biigle\Project; use Biigle\Volume; -use \Illuminate\Foundation\Http\FormRequest; class CloneVolume extends FormRequest { @@ -73,12 +73,12 @@ public function withValidator($validator) if (!empty($fileIds)) { $intersection = array_intersect($fileIds, $this->volume->files()->pluck('id')->toArray()); if (count($intersection) !== count($fileIds)) { - $validator->errors()->add('only_files', - 'Cloning volume failed. Unauthorized access to files that do not belong to the volume'); + $validator->errors()->add( + 'only_files', + 'Cloning volume failed. Unauthorized access to files that do not belong to the volume' + ); } } }); } - - } diff --git a/app/Http/Requests/JoinProjectInvitation.php b/app/Http/Requests/JoinProjectInvitation.php index 02974de68..7a7508c8e 100644 --- a/app/Http/Requests/JoinProjectInvitation.php +++ b/app/Http/Requests/JoinProjectInvitation.php @@ -3,7 +3,6 @@ namespace Biigle\Http\Requests; use Biigle\ProjectInvitation; -use Biigle\Role; use Illuminate\Foundation\Http\FormRequest; class JoinProjectInvitation extends FormRequest diff --git a/app/Http/Requests/StoreImageAnnotation.php b/app/Http/Requests/StoreImageAnnotation.php index b2f7867af..b47d39670 100644 --- a/app/Http/Requests/StoreImageAnnotation.php +++ b/app/Http/Requests/StoreImageAnnotation.php @@ -4,7 +4,6 @@ use Biigle\Image; use Biigle\Shape; -use Illuminate\Foundation\Http\FormRequest; class StoreImageAnnotation extends StoreImageAnnotationLabel { diff --git a/app/Http/Requests/StoreImageAnnotations.php b/app/Http/Requests/StoreImageAnnotations.php index 1db16b1de..221db9e4c 100644 --- a/app/Http/Requests/StoreImageAnnotations.php +++ b/app/Http/Requests/StoreImageAnnotations.php @@ -60,9 +60,7 @@ public function authorize() $this->labels = Label::findMany($labelIds)->keyBy('id'); - return $this->images->reduce(function ($carry, $image) { - return $carry && $this->user()->can('add-annotation', $image); - }, true); + return $this->images->reduce(fn ($carry, $image) => $carry && $this->user()->can('add-annotation', $image), true); } /** diff --git a/app/Http/Requests/StoreLabelTreeMerge.php b/app/Http/Requests/StoreLabelTreeMerge.php index 2be6d47cc..8933db230 100644 --- a/app/Http/Requests/StoreLabelTreeMerge.php +++ b/app/Http/Requests/StoreLabelTreeMerge.php @@ -2,12 +2,8 @@ namespace Biigle\Http\Requests; -use Biigle\ImageAnnotationLabel; -use Biigle\ImageLabel; use Biigle\Label; use Biigle\LabelTree; -use Biigle\VideoAnnotationLabel; -use Biigle\VideoLabel; use Illuminate\Foundation\Http\FormRequest; use Validator; diff --git a/app/Http/Requests/StoreLabelTreeVersion.php b/app/Http/Requests/StoreLabelTreeVersion.php index 1a283fe0c..3911a14e4 100644 --- a/app/Http/Requests/StoreLabelTreeVersion.php +++ b/app/Http/Requests/StoreLabelTreeVersion.php @@ -3,7 +3,6 @@ namespace Biigle\Http\Requests; use Biigle\LabelTree; -use Biigle\Project; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; @@ -39,9 +38,7 @@ public function rules() 'name' => [ 'required', 'max:256', - Rule::unique('label_tree_versions')->where(function ($query) { - return $query->where('label_tree_id', $this->tree->id); - }), + Rule::unique('label_tree_versions')->where(fn ($query) => $query->where('label_tree_id', $this->tree->id)), ], 'doi' => 'nullable|min:10', ]; diff --git a/app/Http/Requests/StoreProjectLabelTree.php b/app/Http/Requests/StoreProjectLabelTree.php index c34bf226f..c09440aeb 100644 --- a/app/Http/Requests/StoreProjectLabelTree.php +++ b/app/Http/Requests/StoreProjectLabelTree.php @@ -5,7 +5,6 @@ use Biigle\LabelTree; use Biigle\Project; use Biigle\Visibility; -use DB; use Illuminate\Foundation\Http\FormRequest; class StoreProjectLabelTree extends FormRequest diff --git a/app/Http/Requests/StoreVideoAnnotation.php b/app/Http/Requests/StoreVideoAnnotation.php index 243f7dc7a..1a9d18ff1 100644 --- a/app/Http/Requests/StoreVideoAnnotation.php +++ b/app/Http/Requests/StoreVideoAnnotation.php @@ -68,7 +68,7 @@ public function withValidator($validator) } $points = $this->input('points', []); - $allArrays = array_reduce($points, fn($c, $i) => $c && is_array($i), true); + $allArrays = array_reduce($points, fn ($c, $i) => $c && is_array($i), true); if (!$allArrays) { $validator->errors()->add('points', 'The points must be an array of arrays.'); diff --git a/app/Http/Requests/StoreVolume.php b/app/Http/Requests/StoreVolume.php index 1bf1b70f1..0536b53b0 100644 --- a/app/Http/Requests/StoreVolume.php +++ b/app/Http/Requests/StoreVolume.php @@ -14,7 +14,6 @@ use Exception; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; -use Illuminate\Validation\ValidationException; class StoreVolume extends FormRequest { diff --git a/app/Http/Requests/UpdateLabelTreeVersion.php b/app/Http/Requests/UpdateLabelTreeVersion.php index 7dc96704c..92fcbb02f 100644 --- a/app/Http/Requests/UpdateLabelTreeVersion.php +++ b/app/Http/Requests/UpdateLabelTreeVersion.php @@ -4,7 +4,6 @@ use Biigle\LabelTreeVersion; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Validation\Rule; class UpdateLabelTreeVersion extends FormRequest { diff --git a/app/ImageAnnotation.php b/app/ImageAnnotation.php index 664bcd0b7..b25e16443 100644 --- a/app/ImageAnnotation.php +++ b/app/ImageAnnotation.php @@ -2,8 +2,6 @@ namespace Biigle; -use DB; - /** * An image annotation is a region of an image that can be labeled by the users. * It consists of one or many points and has a specific shape. diff --git a/app/Jobs/CloneImagesOrVideos.php b/app/Jobs/CloneImagesOrVideos.php index 2a1d2d191..b2ef17123 100644 --- a/app/Jobs/CloneImagesOrVideos.php +++ b/app/Jobs/CloneImagesOrVideos.php @@ -2,7 +2,7 @@ namespace Biigle\Jobs; -use Illuminate\Http\Request; +use \Illuminate\Contracts\Queue\ShouldQueue; use Biigle\Http\Requests\CloneVolume; use Biigle\Image; use Biigle\ImageAnnotation; @@ -17,7 +17,7 @@ use Biigle\VideoAnnotationLabel; use Biigle\VideoLabel; use Biigle\Volume; -use \Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Http\Request; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\DB; @@ -94,7 +94,7 @@ class CloneImagesOrVideos extends Job implements ShouldQueue * * @return void */ - public function __construct($request,$copy) + public function __construct($request, $copy) { $this->project = $request->project; $this->copy = $copy; @@ -195,9 +195,7 @@ private function copyImages($volume, $copy, $selectedImageIds) // copy image references $volume->images() ->orderBy('id') - ->when(!empty($selectedImageIds), function ($query) use ($selectedImageIds) { - return $query->whereIn('id', $selectedImageIds); - }) + ->when(!empty($selectedImageIds), fn ($query) => $query->whereIn('id', $selectedImageIds)) ->get()->map(function ($image) use ($copy) { $original = $image->getRawOriginal(); $original['volume_id'] = $copy->id; @@ -224,12 +222,15 @@ private function copyImageAnnotation($volume, $copy, $selectedFileIds, $selected $selectedFileIds = empty($selectedFileIds) ? $volume->images()->pluck('id')->sortBy('id') : $selectedFileIds; - $annotationJoinLabel = ImageAnnotation::join('image_annotation_labels', - 'image_annotation_labels.annotation_id', '=', 'image_annotations.id') - ->when(!empty($selectedLabelIds), function ($query) use ($selectedLabelIds) { - return $query->whereIn('image_annotation_labels.label_id', $selectedLabelIds); - }) - ->whereIn('image_annotations.image_id', $selectedFileIds); + $annotationJoinLabel = + ImageAnnotation::join( + 'image_annotation_labels', + 'image_annotation_labels.annotation_id', + '=', + 'image_annotations.id' + ) + ->when(!empty($selectedLabelIds), fn ($query) => $query->whereIn('image_annotation_labels.label_id', $selectedLabelIds)) + ->whereIn('image_annotations.image_id', $selectedFileIds); // use unique ids, because an annotation with multiple labels would be duplicated @@ -251,18 +252,18 @@ private function copyImageAnnotation($volume, $copy, $selectedFileIds, $selected $newImageIds = $copy->images()->orderBy('id')->pluck('id'); $volume->images() ->with([ - 'annotations' => fn($q) => $q->whereIn('id', $usedAnnotationIds)->orderBy('id'), - 'annotations.labels' => fn($q) => $q->whereIn('label_id', $imageAnnotationLabelIds)->orderBy('id'), + 'annotations' => fn ($q) => $q->whereIn('id', $usedAnnotationIds)->orderBy('id'), + 'annotations.labels' => fn ($q) => $q->whereIn('label_id', $imageAnnotationLabelIds)->orderBy('id'), ]) - ->when($volume->images->count() !== count($selectedFileIds), function ($query) use ($selectedFileIds) { - return $query->whereIn('id', $selectedFileIds); - }) + ->when($volume->images->count() !== count($selectedFileIds), fn ($query) => $query->whereIn('id', $selectedFileIds)) ->orderBy('id') // This is an optimized implementation to clone the annotations with only few database // queries. There are simpler ways to implement this, but they can be ridiculously inefficient. ->chunkById($chunkSize, function ($chunk, $page) use ( - $newImageIds, $chunkSize, - $usedAnnotationIds, $selectedLabelIds + $newImageIds, + $chunkSize, + $usedAnnotationIds, + $selectedLabelIds ) { $insertData = []; $chunkNewImageIds = []; @@ -314,15 +315,15 @@ private function copyImageLabels($volume, $copy, $selectedFileIds, $selectedLabe $newImageIds = $copy->images()->orderBy('id')->pluck('id'); $volume->images() - ->when(!empty($selectedFileIds), - function ($q) use ($selectedFileIds) { - return $q->whereIn('id', $selectedFileIds); - }) - ->when(!empty($selectedLabelIds), - function ($q) use ($selectedLabelIds) { - return $q->with(['labels' => fn($q) => $q->whereIn('label_id', $selectedLabelIds)]); - }, - fn($q) => $q->with('labels')) + ->when( + !empty($selectedFileIds), + fn ($q) => $q->whereIn('id', $selectedFileIds) + ) + ->when( + !empty($selectedLabelIds), + fn ($q) => $q->with(['labels' => fn ($q) => $q->whereIn('label_id', $selectedLabelIds)]), + fn ($q) => $q->with('labels') + ) ->orderBy('id') ->get()->map(function ($oldImage) use ($newImageIds) { $newImageId = $newImageIds->shift(); @@ -349,9 +350,7 @@ private function copyVideos($volume, $copy, $selectedVideoIds) // copy video references $volume->videos() ->orderBy('id') - ->when(!empty($selectedVideoIds), function ($query) use ($selectedVideoIds) { - return $query->whereIn('id', $selectedVideoIds); - }) + ->when(!empty($selectedVideoIds), fn ($query) => $query->whereIn('id', $selectedVideoIds)) ->get()->map(function ($video) use ($copy) { $original = $video->getRawOriginal(); $original['volume_id'] = $copy->id; @@ -378,13 +377,16 @@ private function copyVideoAnnotation($volume, $copy, $selectedFileIds, $selected $selectedFileIds = empty($selectedFileIds) ? $volume->videos()->pluck('id')->sortBy('id') : $selectedFileIds; - $annotationJoinLabel = VideoAnnotation::join('video_annotation_labels', - 'video_annotation_labels.annotation_id', '=', 'video_annotations.id') - ->when(!empty($selectedLabelIds), function ($query) use ($selectedLabelIds) { - return $query->whereIn('video_annotation_labels.label_id', $selectedLabelIds); - }) - ->whereIn('video_annotations.video_id', $selectedFileIds) - ->distinct(); + $annotationJoinLabel = + VideoAnnotation::join( + 'video_annotation_labels', + 'video_annotation_labels.annotation_id', + '=', + 'video_annotations.id' + ) + ->when(!empty($selectedLabelIds), fn ($query) => $query->whereIn('video_annotation_labels.label_id', $selectedLabelIds)) + ->whereIn('video_annotations.video_id', $selectedFileIds) + ->distinct(); // use unique ids, because an annotation with multiple labels would be duplicated $usedAnnotationIds = $annotationJoinLabel @@ -405,18 +407,18 @@ private function copyVideoAnnotation($volume, $copy, $selectedFileIds, $selected $newVideoIds = $copy->videos()->orderBy('id')->pluck('id'); $volume->videos() ->with([ - 'annotations' => fn($q) => $q->whereIn('id', $usedAnnotationIds)->orderBy('id'), - 'annotations.labels' => fn($q) => $q->whereIn('label_id', $videoAnnotationLabelIds)->orderBy('id'), + 'annotations' => fn ($q) => $q->whereIn('id', $usedAnnotationIds)->orderBy('id'), + 'annotations.labels' => fn ($q) => $q->whereIn('label_id', $videoAnnotationLabelIds)->orderBy('id'), ]) - ->when($volume->videos->count() !== count($selectedFileIds), function ($query) use ($selectedFileIds) { - return $query->whereIn('id', $selectedFileIds); - }) + ->when($volume->videos->count() !== count($selectedFileIds), fn ($query) => $query->whereIn('id', $selectedFileIds)) ->orderBy('id') // This is an optimized implementation to clone the annotations with only few database // queries. There are simpler ways to implement this, but they can be ridiculously inefficient. ->chunkById($chunkSize, function ($chunk, $page) use ( - $newVideoIds, $chunkSize, - $usedAnnotationIds, $selectedLabelIds + $newVideoIds, + $chunkSize, + $usedAnnotationIds, + $selectedLabelIds ) { $insertData = []; $chunkNewVideoIds = []; @@ -468,17 +470,18 @@ private function copyVideoLabels($volume, $copy, $selectedFileIds, $selectedLabe $newVideoIds = $copy->videos()->orderBy('id')->pluck('id'); $volume->videos() - ->when(!empty($selectedFileIds), - function ($q) use ($selectedFileIds) { - return $q->whereIn('id', $selectedFileIds); - }) - ->when(!empty($selectedLabelIds), - function ($q) use ($selectedLabelIds) { - return $q->with(['labels' => fn($q) => $q->whereIn('label_id', $selectedLabelIds)]); - }, - fn($q) => $q->with('labels')) + ->when( + !empty($selectedFileIds), + fn ($q) => $q->whereIn('id', $selectedFileIds) + ) + ->when( + !empty($selectedLabelIds), + fn ($q) => $q->with(['labels' => fn ($q) => $q->whereIn('label_id', $selectedLabelIds)]), + fn ($q) => $q->with('labels') + ) ->orderBy('id') - ->get()->map(function ($oldVideo) use ($newVideoIds) { + ->get() + ->map(function ($oldVideo) use ($newVideoIds) { $newVideoId = $newVideoIds->shift(); $oldVideo->labels->map(function ($oldLabel) use ($newVideoId) { $origin = $oldLabel->getRawOriginal(); @@ -503,5 +506,4 @@ private function copyIfdoFile($volumeId, $copyId) $copyIFdoFilename = $copyId.".yaml"; $disk->copy($iFdoFilename, $copyIFdoFilename); } - } diff --git a/app/Jobs/CreateNewImagesOrVideos.php b/app/Jobs/CreateNewImagesOrVideos.php index f2eb36d4e..c266698b2 100644 --- a/app/Jobs/CreateNewImagesOrVideos.php +++ b/app/Jobs/CreateNewImagesOrVideos.php @@ -3,7 +3,6 @@ namespace Biigle\Jobs; use Biigle\Image; -use Biigle\Jobs\ProcessNewVolumeFiles; use Biigle\Rules\ImageMetadata; use Biigle\Traits\ChecksMetadataStrings; use Biigle\Video; @@ -163,9 +162,7 @@ protected function generateImageMetadataMap() $columns = $this->metadata[0]; $map = collect(array_slice($this->metadata, 1)) - ->map(function ($row) use ($columns) { - return array_combine($columns, $row); - }) + ->map(fn ($row) => array_combine($columns, $row)) ->map(function ($row) { if (array_key_exists('taken_at', $row)) { $row['taken_at'] = Carbon::parse($row['taken_at']); @@ -194,9 +191,7 @@ protected function generateVideoMetadataMap() $columns = $this->metadata[0]; $map = collect(array_slice($this->metadata, 1)) - ->map(function ($row) use ($columns) { - return array_combine($columns, $row); - }) + ->map(fn ($row) => array_combine($columns, $row)) ->map(function ($row) { if (array_key_exists('taken_at', $row)) { $row['taken_at'] = Carbon::parse($row['taken_at']); @@ -208,9 +203,7 @@ protected function generateVideoMetadataMap() }) ->sortBy('taken_at') ->groupBy('filename') - ->map(function ($entries) use ($columns) { - return $this->processVideoColumns($entries, $columns); - }); + ->map(fn ($entries) => $this->processVideoColumns($entries, $columns)); return $map; } diff --git a/app/Jobs/ProcessNewImage.php b/app/Jobs/ProcessNewImage.php index d893248a2..65f953733 100644 --- a/app/Jobs/ProcessNewImage.php +++ b/app/Jobs/ProcessNewImage.php @@ -126,9 +126,7 @@ protected function makeThumbnail(Image $image, $path) { $prefix = fragment_uuid_path($image->uuid); $format = config('thumbnails.format'); - $buffer = VipsImage::thumbnail($path, $this->width, [ - 'height' => $this->height, - ]) + $buffer = VipsImage::thumbnail($path, $this->width, ['height' => $this->height]) // Strip EXIF information to not auto rotate thumbnails because // the orientation of AUV captured images is not reliable. ->writeToBuffer(".{$format}", [ @@ -137,7 +135,7 @@ protected function makeThumbnail(Image $image, $path) ]); Storage::disk(config('thumbnails.storage_disk')) - ->put("{$prefix}.{$format}", $buffer); + ->put("{$prefix}.{$format}", $buffer); } /** diff --git a/app/Jobs/ProcessNewVideo.php b/app/Jobs/ProcessNewVideo.php index c2e0a7899..0c830c4da 100644 --- a/app/Jobs/ProcessNewVideo.php +++ b/app/Jobs/ProcessNewVideo.php @@ -3,7 +3,6 @@ namespace Biigle\Jobs; use App; -use Biigle\Jobs\Job; use Biigle\Video; use Exception; use FFMpeg\Coordinate\Dimension; diff --git a/app/Jobs/ProcessNewVolumeFiles.php b/app/Jobs/ProcessNewVolumeFiles.php index 86e354db4..5a023e38f 100644 --- a/app/Jobs/ProcessNewVolumeFiles.php +++ b/app/Jobs/ProcessNewVolumeFiles.php @@ -56,9 +56,7 @@ public function __construct(Volume $volume, array $only = []) public function handle() { $query = $this->volume->files() - ->when($this->only, function ($query) { - return $query->whereIn('id', $this->only); - }); + ->when($this->only, fn ($query) => $query->whereIn('id', $this->only)); if ($this->volume->isImageVolume()) { $query->eachById([ProcessNewImage::class, 'dispatch']); diff --git a/app/Jobs/TileSingleImage.php b/app/Jobs/TileSingleImage.php index 3cc31ed5f..a6c8cda11 100644 --- a/app/Jobs/TileSingleImage.php +++ b/app/Jobs/TileSingleImage.php @@ -13,7 +13,6 @@ use Illuminate\Support\Facades\Storage; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; -use SplFileInfo; use VipsImage; class TileSingleImage extends Job implements ShouldQueue diff --git a/app/Jobs/TrackObject.php b/app/Jobs/TrackObject.php index 0e18b3f52..be4a8ff15 100644 --- a/app/Jobs/TrackObject.php +++ b/app/Jobs/TrackObject.php @@ -4,7 +4,6 @@ use Biigle\Events\ObjectTrackingFailed; use Biigle\Events\ObjectTrackingSucceeded; -use Biigle\Jobs\Job; use Biigle\Shape; use Biigle\User; use Biigle\VideoAnnotation; diff --git a/app/Jobs/UpdateFederatedSearchIndex.php b/app/Jobs/UpdateFederatedSearchIndex.php index 48d17e909..b87783a6f 100644 --- a/app/Jobs/UpdateFederatedSearchIndex.php +++ b/app/Jobs/UpdateFederatedSearchIndex.php @@ -275,7 +275,6 @@ protected function updateVolumeIndex($index) return array_combine($volumeIds, $modelIds); } - /** * Update which user may access which federated search model that was created in * this job. diff --git a/app/Label.php b/app/Label.php index a3a70ae9b..2090550fe 100644 --- a/app/Label.php +++ b/app/Label.php @@ -55,7 +55,8 @@ class Label extends Model public function scopeUsed($query) { return $query->where(function ($query) { - return $query->whereExists(function ($query) { + return $query + ->whereExists(function ($query) { return $query->select(DB::raw(1)) ->from('image_annotation_labels') ->whereRaw('labels.id = image_annotation_labels.label_id'); diff --git a/app/LabelTree.php b/app/LabelTree.php index a2895a4c8..f27efaaba 100644 --- a/app/LabelTree.php +++ b/app/LabelTree.php @@ -3,7 +3,6 @@ namespace Biigle; use DB; -use Exception; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Ramsey\Uuid\Uuid; diff --git a/app/Logging/CreateRedisLogger.php b/app/Logging/CreateRedisLogger.php index c90afb0c1..25d223b07 100644 --- a/app/Logging/CreateRedisLogger.php +++ b/app/Logging/CreateRedisLogger.php @@ -43,5 +43,4 @@ protected function getFallbackChannelName() { return config('app.env'); } - } diff --git a/app/Logging/LogManager.php b/app/Logging/LogManager.php index 2ee3baa6a..f85db288b 100644 --- a/app/Logging/LogManager.php +++ b/app/Logging/LogManager.php @@ -63,9 +63,7 @@ public function getLogFilenames() $logs = File::glob("{$path}/*.log"); - return array_map(function ($path) { - return File::name($path); - }, $logs); + return array_map(fn ($path) => File::name($path), $logs); } /** @@ -107,12 +105,8 @@ public function getRedisLogMessages($level = 'debug') $client = Redis::connection($connection)->client(); return collect($client->lrange('log', 0, -1)) - ->map(function ($message) { - return json_decode($message, true); - }) - ->filter(function ($message) use ($level) { - return $message['level'] >= $level; - }); + ->map(fn ($message) => json_decode($message, true)) + ->filter(fn ($message) => $message['level'] >= $level); } /** @@ -136,9 +130,7 @@ public function getRecentCount($level = 'debug', $subDays = 1) return array_reduce($filenames, function ($carry, $filename) use ($days) { $content = $this->getLogFileContent($filename); - return array_reduce($days, function ($carry, $day) use ($content) { - return $carry + substr_count($content, "[{$day}"); - }, $carry); + return array_reduce($days, fn ($carry, $day) => $carry + substr_count($content, "[{$day}"), $carry); }, 0); } elseif ($this->isRedis()) { return $this->getRedisLogMessages($level) diff --git a/app/Notifications/RegistrationConfirmation.php b/app/Notifications/RegistrationConfirmation.php index 51e7f610c..29f11b8e1 100644 --- a/app/Notifications/RegistrationConfirmation.php +++ b/app/Notifications/RegistrationConfirmation.php @@ -8,7 +8,6 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; use Illuminate\Queue\SerializesModels; -use View; class RegistrationConfirmation extends Notification implements ShouldQueue { diff --git a/app/Policies/AnnotationPolicy.php b/app/Policies/AnnotationPolicy.php index df0bbe9bd..9a4fb6958 100644 --- a/app/Policies/AnnotationPolicy.php +++ b/app/Policies/AnnotationPolicy.php @@ -3,9 +3,7 @@ namespace Biigle\Policies; use Biigle\Annotation; -use Biigle\AnnotationLabel; use Biigle\Label; -use Biigle\Policies\CachedPolicy; use Biigle\Project; use Biigle\Role; use Biigle\User; diff --git a/app/Policies/LabelTreePolicy.php b/app/Policies/LabelTreePolicy.php index a91025ae6..cc79a5dc0 100644 --- a/app/Policies/LabelTreePolicy.php +++ b/app/Policies/LabelTreePolicy.php @@ -148,9 +148,7 @@ public function addMember(User $user, LabelTree $tree) */ public function updateMember(User $user, LabelTree $tree, User $member) { - return $this->remember("label-tree-can-update-member-{$user->id}-{$tree->id}-{$member->id}", function () use ($user, $tree, $member) { - return $user->id !== $member->id && $this->update($user, $tree); - }); + return $this->remember("label-tree-can-update-member-{$user->id}-{$tree->id}-{$member->id}", fn () => $user->id !== $member->id && $this->update($user, $tree)); } /** diff --git a/app/Policies/ProjectInvitationPolicy.php b/app/Policies/ProjectInvitationPolicy.php index be5c17dbf..c574a06b5 100644 --- a/app/Policies/ProjectInvitationPolicy.php +++ b/app/Policies/ProjectInvitationPolicy.php @@ -2,9 +2,9 @@ namespace Biigle\Policies; +use Biigle\ProjectInvitation; use Biigle\Role; use Biigle\User; -use Biigle\ProjectInvitation; use DB; use Illuminate\Auth\Access\HandlesAuthorization; diff --git a/app/Policies/ProjectPolicy.php b/app/Policies/ProjectPolicy.php index 2d71deb5e..d28aa5091 100644 --- a/app/Policies/ProjectPolicy.php +++ b/app/Policies/ProjectPolicy.php @@ -48,9 +48,7 @@ public function create(User $user) */ public function access(User $user, Project $project) { - return $this->remember("project-can-access-{$user->id}-{$project->id}", function () use ($user, $project) { - return $this->getBaseQuery($user, $project)->exists(); - }); + return $this->remember("project-can-access-{$user->id}-{$project->id}", fn () => $this->getBaseQuery($user, $project)->exists()); } /** diff --git a/app/Policies/VolumeFilePolicy.php b/app/Policies/VolumeFilePolicy.php index 799af16ba..58b964633 100644 --- a/app/Policies/VolumeFilePolicy.php +++ b/app/Policies/VolumeFilePolicy.php @@ -41,9 +41,7 @@ public function before($user, $ability) public function access(User $user, VolumeFile $file) { // put this to permanent cache for rapid querying of file thumbnails - return Cache::remember("volume-file-can-access-{$user->id}-{$file->volume_id}", 30, function () use ($user, $file) { - return Project::inCommon($user, $file->volume_id)->exists(); - }); + return Cache::remember("volume-file-can-access-{$user->id}-{$file->volume_id}", 30, fn () => Project::inCommon($user, $file->volume_id)->exists()); } /** diff --git a/app/Policies/VolumePolicy.php b/app/Policies/VolumePolicy.php index 45449310e..ecb4c5f52 100644 --- a/app/Policies/VolumePolicy.php +++ b/app/Policies/VolumePolicy.php @@ -37,9 +37,7 @@ public function before($user, $ability) */ public function access(User $user, Volume $volume) { - return $this->remember("volume-can-access-{$user->id}-{$volume->id}", function () use ($user, $volume) { - return $this->getBaseQuery($user, $volume)->exists(); - }); + return $this->remember("volume-can-access-{$user->id}-{$volume->id}", fn () => $this->getBaseQuery($user, $volume)->exists()); } /** diff --git a/app/Project.php b/app/Project.php index 3bedc6942..4098402ff 100644 --- a/app/Project.php +++ b/app/Project.php @@ -39,9 +39,7 @@ public function scopeInCommon($query, User $user, $volumeId, $roles = null) ->join('project_volume', 'project_user.project_id', '=', 'project_volume.project_id') ->whereRaw('project_user.project_id = projects.id') ->where('project_user.user_id', $user->id) - ->when(is_array($roles), function ($query) use ($roles) { - return $query->whereIn('project_user.project_role_id', $roles); - }) + ->when(is_array($roles), fn ($query) => $query->whereIn('project_user.project_role_id', $roles)) ->where('project_volume.volume_id', $volumeId); }); } @@ -211,7 +209,6 @@ public function videoVolumes() return $this->volumes()->where('media_type_id', MediaType::videoId()); } - /** * Adds a volume to this project if it wasn't already. * @@ -331,14 +328,10 @@ public function getThumbnailUrlAttribute() public function hasGeoInfo() { return Cache::remember("project-{$this->id}-has-geo-info", 3600, function () { - return Image::whereIn('volume_id', function ($query) { - return $query->select('volume_id') - ->from('project_volume') - ->where('project_id', $this->id); - }) - ->whereNotNull('lng') - ->whereNotNull('lat') - ->exists(); + return Image::whereIn('volume_id', fn ($q) => $q->select('volume_id')->from('project_volume')->where('project_id', $this->id)) + ->whereNotNull('lng') + ->whereNotNull('lat') + ->exists(); }); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index eda781f11..35f5a25f5 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -14,22 +14,17 @@ class AppServiceProvider extends ServiceProvider { - /** * Register any application services. */ public function register(): void { - $this->app->singleton('modules', function () { - return new \Biigle\Services\Modules; - }); + $this->app->singleton('modules', fn () => new \Biigle\Services\Modules); // Use the singleton in any instances where the modules service should be used // via dependency injection. $this->app->alias('modules', \Biigle\Services\Modules::class); - $this->app->bind('vips-image', function () { - return new \Jcupitt\Vips\Image(null); - }); + $this->app->bind('vips-image', fn () => new \Jcupitt\Vips\Image(null)); // The custom implementation allows "config resolvers" which are required by // the user-storage and user-disks modules, for example. diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 3aac12b81..cc3d3aded 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -3,9 +3,8 @@ namespace Biigle\Providers; use Biigle\Role; -use Biigle\User; use Biigle\Services\Auth\ApiGuard; -use Biigle\Services\Auth\FederatedSearchGuard; +use Biigle\User; use Illuminate\Auth\TokenGuard; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Auth; @@ -35,14 +34,10 @@ class AuthServiceProvider extends ServiceProvider public function boot(): void { // Ability of a global admin. - Gate::define('sudo', function (User $user) { - return $user->isInSuperUserMode; - }); + Gate::define('sudo', fn (User $user) => $user->isInSuperUserMode); // Ability of a reviewer (e.g. for new registrations). - Gate::define('review', function (User $user) { - return $user->canReview; - }); + Gate::define('review', fn (User $user) => $user->canReview); // Ability to create or update a volume with a certain storage disk. // Merge with possible logic defined by modules. diff --git a/app/Rules/VolumeFiles.php b/app/Rules/VolumeFiles.php index 3837731ef..3edf67d9e 100644 --- a/app/Rules/VolumeFiles.php +++ b/app/Rules/VolumeFiles.php @@ -82,9 +82,7 @@ public function passes($attribute, $value) $count = count($value); if ($count !== count(array_unique($value))) { - $dupes = array_keys(array_filter(array_count_values($value), function ($v) { - return $v > 1; - })); + $dupes = array_keys(array_filter(array_count_values($value), fn ($v) => $v > 1)); $this->message = 'A volume must not have the same file twice. Duplicate files: '.implode(', ', $dupes); @@ -93,9 +91,7 @@ public function passes($attribute, $value) } $lengths = array_map('strlen', $value); - $tooLong = array_filter($lengths, function ($l) { - return $l > self::FILENAME_MAX_LENGTH; - }); + $tooLong = array_filter($lengths, fn ($l) => $l > self::FILENAME_MAX_LENGTH); if (!empty($tooLong)) { $this->message = 'A filename must not be longer than '.self::FILENAME_MAX_LENGTH.' characters.'; diff --git a/app/Rules/VolumeUrl.php b/app/Rules/VolumeUrl.php index 893fd252e..8c2fa9a9e 100644 --- a/app/Rules/VolumeUrl.php +++ b/app/Rules/VolumeUrl.php @@ -3,7 +3,6 @@ namespace Biigle\Rules; use App; -use Biigle\User; use Exception; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; diff --git a/app/Services/Modules.php b/app/Services/Modules.php index 97b0e141f..0041f4272 100644 --- a/app/Services/Modules.php +++ b/app/Services/Modules.php @@ -160,9 +160,7 @@ public function getInstalledModules() { $installed = json_decode(File::get(base_path('vendor/composer/installed.json')), true); - return array_filter($installed['packages'], function ($item) { - return strpos($item['name'], 'biigle/') === 0; - }); + return array_filter($installed['packages'], fn ($item) => strpos($item['name'], 'biigle/') === 0); } /** diff --git a/app/Traits/HasConstantInstances.php b/app/Traits/HasConstantInstances.php index 5a0948090..660522a39 100644 --- a/app/Traits/HasConstantInstances.php +++ b/app/Traits/HasConstantInstances.php @@ -44,9 +44,7 @@ public static function __callStatic($key, $arguments): mixed $name = static::INSTANCES[$key]; $cacheKey = static::class.'::'.$key; - $instance = Cache::rememberForever($cacheKey, function () use ($name) { - return static::whereName($name)->first(); - }); + $instance = Cache::rememberForever($cacheKey, fn () => static::whereName($name)->first()); return $wantsId ? $instance->id : $instance; } diff --git a/app/Traits/HasPointsAttribute.php b/app/Traits/HasPointsAttribute.php index 279ec9f70..3cc130122 100644 --- a/app/Traits/HasPointsAttribute.php +++ b/app/Traits/HasPointsAttribute.php @@ -16,9 +16,7 @@ trait HasPointsAttribute public function validatePoints(array $points) { // check if all elements are integer - $valid = array_reduce($points, function ($carry, $point) { - return $carry && (is_float($point) || is_int($point)); - }, true); + $valid = array_reduce($points, fn ($carry, $point) => $carry && (is_float($point) || is_int($point)), true); if (!$valid) { throw new Exception('Point coordinates must be of type float or integer.'); @@ -63,9 +61,7 @@ public function validatePoints(array $points) */ public function setPointsAttribute(array $points) { - $points = array_map(function ($coordinate) { - return round($coordinate, 2); - }, $points); + $points = array_map(fn ($coordinate) => round($coordinate, 2), $points); $this->attributes['points'] = json_encode($points); } diff --git a/app/Video.php b/app/Video.php index 821005c7a..4247b6ba5 100644 --- a/app/Video.php +++ b/app/Video.php @@ -2,9 +2,7 @@ namespace Biigle; -use Biigle\User; use Carbon\Carbon; -use DB; class Video extends VolumeFile { @@ -144,9 +142,7 @@ public function getThumbnailUrlAttribute() public function getThumbnailsAttribute() { return collect(range(0, config('videos.thumbnail_count') - 1)) - ->map(function ($i) { - return "{$this->uuid}/{$i}"; - }); + ->map(fn ($i) => "{$this->uuid}/{$i}"); } /** @@ -156,9 +152,7 @@ public function getThumbnailsAttribute() */ public function getThumbnailsUrlAttribute() { - return $this->thumbnails->map(function ($item) { - return thumbnail_url($item, config('videos.thumbnail_storage_disk')); - }); + return $this->thumbnails->map(fn ($item) => thumbnail_url($item, config('videos.thumbnail_storage_disk'))); } /** diff --git a/app/VideoAnnotation.php b/app/VideoAnnotation.php index 6dc265fa0..f3bde3df5 100644 --- a/app/VideoAnnotation.php +++ b/app/VideoAnnotation.php @@ -80,11 +80,7 @@ public function labels() */ public function setPointsAttribute(array $points) { - $points = array_map(function ($points) { - return array_map(function ($value) { - return round($value, 2); - }, $points); - }, $points); + $points = array_map(fn ($points) => array_map(fn ($value) => round($value, 2), $points), $points); $this->attributes['points'] = json_encode($points); } @@ -209,9 +205,7 @@ protected function getInterpolationPoints() */ protected function interpolateNaive($from, $to, $progress) { - return array_map(function ($index, $value) use ($to, $progress) { - return $value + ($to[$index] - $value) * $progress; - }, array_keys($from), $from); + return array_map(fn ($index, $value) => $value + ($to[$index] - $value) * $progress, array_keys($from), $from); } /** diff --git a/app/Volume.php b/app/Volume.php index f055edf75..c99b9d686 100644 --- a/app/Volume.php +++ b/app/Volume.php @@ -9,7 +9,6 @@ use Exception; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\QueryException; use Illuminate\Http\Response; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; @@ -260,9 +259,7 @@ public function getActiveAnnotationSession(User $user) public function hasConflictingAnnotationSession(AnnotationSession $session) { return $this->annotationSessions() - ->when(!is_null($session->id), function ($query) use ($session) { - return $query->where('id', '!=', $session->id); - }) + ->when(!is_null($session->id), fn ($query) => $query->where('id', '!=', $session->id)) ->where(function ($query) use ($session) { $query->where(function ($query) use ($session) { $query->where('starts_at', '<=', $session->starts_at) @@ -344,9 +341,7 @@ public function getThumbnailsAttribute() */ public function getThumbnailsUrlAttribute() { - return $this->thumbnails->map(function ($file) { - return $file->thumbnailUrl; - }); + return $this->thumbnails->map(fn ($file) => $file->thumbnailUrl); } /** @@ -364,9 +359,7 @@ public function flushThumbnailCache() */ public function hasGeoInfo() { - return Cache::remember($this->getGeoInfoCacheKey(), 3600, function () { - return $this->images()->whereNotNull('lng')->whereNotNull('lat')->exists(); - }); + return Cache::remember($this->getGeoInfoCacheKey(), 3600, fn () => $this->images()->whereNotNull('lng')->whereNotNull('lat')->exists()); } /** @@ -425,9 +418,7 @@ public function getCreatingAsyncAttribute() public function hasTiledImages() { // Cache this for a single request because it may be called lots of times. - return Cache::store('array')->remember("volume-{$this->id}-has-tiled", 60, function () { - return $this->images()->where('tiled', true)->exists(); - }); + return Cache::store('array')->remember("volume-{$this->id}-has-tiled", 60, fn () => $this->images()->where('tiled', true)->exists()); } /** @@ -472,9 +463,7 @@ public function saveIfdo(UploadedFile $file) public function hasIfdo($ignoreErrors = false) { try { - return Cache::remember($this->getIfdoCacheKey(), 3600, function () { - return Storage::disk(config('volumes.ifdo_storage_disk'))->exists($this->getIfdoFilename()); - }); + return Cache::remember($this->getIfdoCacheKey(), 3600, fn () => Storage::disk(config('volumes.ifdo_storage_disk'))->exists($this->getIfdoFilename())); } catch (Exception $e) { if (!$ignoreErrors) { throw $e; diff --git a/app/VolumeFile.php b/app/VolumeFile.php index 86f1bdc42..146ee5e73 100644 --- a/app/VolumeFile.php +++ b/app/VolumeFile.php @@ -36,6 +36,7 @@ public function getUrl() { return $this->url; } + /** * The volume this video belongs to. * diff --git a/composer.json b/composer.json index b6610a045..a39d52966 100644 --- a/composer.json +++ b/composer.json @@ -96,7 +96,7 @@ "docker compose run --rm worker php -d memory_limit=1G vendor/bin/phpunit --colors=always --filter" ], "fix": [ - "@php vendor/bin/php-cs-fixer fix --config='.php_cs'" + "@php vendor/bin/php-cs-fixer fix --config='.php-cs-fixer.php'" ], "doc": [ "rm -rf public/doc/server", diff --git a/config/app.php b/config/app.php index 323efda46..331a3756c 100644 --- a/config/app.php +++ b/config/app.php @@ -69,7 +69,7 @@ | */ - 'proxy' => env('HTTP_PROXY', null), + 'proxy' => env('HTTP_PROXY', null), /* |-------------------------------------------------------------------------- diff --git a/config/thumbnails.php b/config/thumbnails.php index 702f3c772..7a8657e55 100644 --- a/config/thumbnails.php +++ b/config/thumbnails.php @@ -19,7 +19,7 @@ | Thumbnail file format. Depending on your thumbnail service, different formats are | supported. Usually fine are 'jpg' or 'png'. */ - 'format' => 'jpg', + 'format' => 'jpg', /* | Image URL to use if a thumbnail was not yet generated. diff --git a/database/factories/AnnotationLabelFactory.php b/database/factories/AnnotationLabelFactory.php index e87b199ad..11b3c89d7 100644 --- a/database/factories/AnnotationLabelFactory.php +++ b/database/factories/AnnotationLabelFactory.php @@ -2,7 +2,6 @@ namespace Database\Factories; -use Biigle\ImageAnnotation; use Biigle\Label; use Biigle\User; use Illuminate\Database\Eloquent\Factories\Factory; diff --git a/database/factories/ImageAnnotationLabelFactory.php b/database/factories/ImageAnnotationLabelFactory.php index fa86384e3..d8dbf4884 100644 --- a/database/factories/ImageAnnotationLabelFactory.php +++ b/database/factories/ImageAnnotationLabelFactory.php @@ -3,8 +3,6 @@ namespace Database\Factories; use Biigle\ImageAnnotation; -use Biigle\Label; -use Biigle\User; class ImageAnnotationLabelFactory extends AnnotationLabelFactory { diff --git a/database/factories/LabelSourceFactory.php b/database/factories/LabelSourceFactory.php index 2d17b8951..79df5661b 100644 --- a/database/factories/LabelSourceFactory.php +++ b/database/factories/LabelSourceFactory.php @@ -2,7 +2,6 @@ namespace Database\Factories; -use Biigle\Volume; use Illuminate\Database\Eloquent\Factories\Factory; class LabelSourceFactory extends Factory diff --git a/database/factories/LabelTreeFactory.php b/database/factories/LabelTreeFactory.php index 6f7b37413..54f4a2d9c 100644 --- a/database/factories/LabelTreeFactory.php +++ b/database/factories/LabelTreeFactory.php @@ -17,9 +17,7 @@ public function definition() return [ 'name' => $this->faker->username(), 'description' => $this->faker->sentence(), - 'visibility_id' => function () { - return Visibility::publicId(); - }, + 'visibility_id' => fn () => Visibility::publicId(), 'uuid' => $this->faker->unique()->uuid(), ]; } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 4124e7ee9..7e40765c4 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -24,9 +24,7 @@ public function definition(): array 'remember_token' => Str::random(10), 'uuid' => $this->faker->unique()->uuid(), 'affiliation' => $this->faker->company(), - 'role_id' => function () { - return Role::editorId(); - }, + 'role_id' => fn () => Role::editorId(), ]; } } diff --git a/database/factories/VolumeFactory.php b/database/factories/VolumeFactory.php index 1af4a0d68..c9a43b66c 100644 --- a/database/factories/VolumeFactory.php +++ b/database/factories/VolumeFactory.php @@ -17,9 +17,7 @@ public function definition() { return [ 'name' => $this->faker->company(), - 'media_type_id' => function () { - return MediaType::imageId(); - }, + 'media_type_id' => fn () => MediaType::imageId(), 'creator_id' => User::factory(), 'url' => 'test://files', ]; diff --git a/database/migrations/2015_01_27_154541_initialize.php b/database/migrations/2015_01_27_154541_initialize.php index e4432c49b..8ff9b0c3a 100644 --- a/database/migrations/2015_01_27_154541_initialize.php +++ b/database/migrations/2015_01_27_154541_initialize.php @@ -63,10 +63,10 @@ public function up() $table->integer('role_id')->unsigned(); $table->foreign('role_id') - ->references('id') - ->on('roles') + ->references('id') + ->on('roles') // dont delete role if it is in use - ->onDelete('restrict'); + ->onDelete('restrict'); // token for the "stay logged in" session $table->rememberToken(); @@ -91,10 +91,10 @@ public function up() // the user, this token belongs to $table->integer('owner_id')->unsigned(); $table->foreign('owner_id') - ->references('id') - ->on('users') + ->references('id') + ->on('users') // delete tokens of a user if they are deleted - ->onDelete('cascade'); + ->onDelete('cascade'); $table->string('purpose'); // hashing uses bcrypt so the token hash is always 60 chars long @@ -118,10 +118,10 @@ public function up() $table->integer('visibility_id')->unsigned(); $table->foreign('visibility_id') - ->references('id') - ->on('visibilities') + ->references('id') + ->on('visibilities') // don't delete a visibility that is in use - ->onDelete('restrict'); + ->onDelete('restrict'); $table->timestamps(); }); @@ -134,24 +134,24 @@ public function up() Schema::create('label_tree_user', function (Blueprint $table) { $table->integer('label_tree_id')->unsigned(); $table->foreign('label_tree_id') - ->references('id') - ->on('label_trees') + ->references('id') + ->on('label_trees') // remove the member assignment if the label tree is deleted - ->onDelete('cascade'); + ->onDelete('cascade'); $table->integer('user_id')->unsigned(); $table->foreign('user_id') - ->references('id') - ->on('users') + ->references('id') + ->on('users') // remove the member if the user is deleted - ->onDelete('cascade'); + ->onDelete('cascade'); $table->integer('role_id')->unsigned(); $table->foreign('role_id') - ->references('id') - ->on('roles') + ->references('id') + ->on('roles') // dont delete role if it is in use - ->onDelete('restrict'); + ->onDelete('restrict'); // each user must not be added twice as a label tree member $table->unique(['label_tree_id', 'user_id']); @@ -168,10 +168,10 @@ public function up() // creator of the project $table->integer('creator_id')->unsigned()->nullable(); $table->foreign('creator_id') - ->references('id') - ->on('users') + ->references('id') + ->on('users') // if the creator is deleted, the project should still exist - ->onDelete('set null'); + ->onDelete('set null'); $table->timestamps(); }); @@ -184,17 +184,17 @@ public function up() Schema::create('label_tree_project', function (Blueprint $table) { $table->integer('label_tree_id')->unsigned(); $table->foreign('label_tree_id') - ->references('id') - ->on('label_trees') + ->references('id') + ->on('label_trees') // delete the label tree from the project if the tree is deleted - ->onDelete('cascade'); + ->onDelete('cascade'); $table->integer('project_id')->unsigned(); $table->foreign('project_id') - ->references('id') - ->on('projects') + ->references('id') + ->on('projects') // delete the reference to the label tree if the project was deleted - ->onDelete('cascade'); + ->onDelete('cascade'); // each project may "use" each label tree only once $table->unique(['label_tree_id', 'project_id']); @@ -207,17 +207,17 @@ public function up() Schema::create('label_tree_authorized_project', function (Blueprint $table) { $table->integer('label_tree_id')->unsigned(); $table->foreign('label_tree_id') - ->references('id') - ->on('label_trees') + ->references('id') + ->on('label_trees') // delete the authorization if the tree is deleted - ->onDelete('cascade'); + ->onDelete('cascade'); $table->integer('project_id')->unsigned(); $table->foreign('project_id') - ->references('id') - ->on('projects') + ->references('id') + ->on('projects') // delete the reference to the label tree if the project was deleted - ->onDelete('cascade'); + ->onDelete('cascade'); // each project may be authorized only once $table->unique(['label_tree_id', 'project_id']); @@ -230,22 +230,22 @@ public function up() Schema::create('project_user', function (Blueprint $table) { $table->integer('project_role_id')->unsigned(); $table->foreign('project_role_id') - ->references('id') - ->on('roles') + ->references('id') + ->on('roles') // dont delete role if it is in use - ->onDelete('restrict'); + ->onDelete('restrict'); $table->integer('user_id')->unsigned(); $table->foreign('user_id') - ->references('id') - ->on('users') - ->onDelete('cascade'); + ->references('id') + ->on('users') + ->onDelete('cascade'); $table->integer('project_id')->unsigned(); $table->foreign('project_id') - ->references('id') - ->on('projects') - ->onDelete('cascade'); + ->references('id') + ->on('projects') + ->onDelete('cascade'); // users should only have one role per project since roles // are hierarchical @@ -290,18 +290,18 @@ public function up() // which kind of data is stored in this transect? $table->integer('media_type_id')->unsigned(); $table->foreign('media_type_id') - ->references('id') - ->on('media_types') + ->references('id') + ->on('media_types') // media types in use shouldn't be deleted - ->onDelete('restrict'); + ->onDelete('restrict'); // the creator of the transect $table->integer('creator_id')->unsigned()->nullable(); $table->foreign('creator_id') - ->references('id') - ->on('users') + ->references('id') + ->on('users') // the transect should still exist if the creator was deleted - ->onDelete('set null'); + ->onDelete('set null'); $table->timestamps(); @@ -316,16 +316,16 @@ public function up() Schema::create('project_transect', function (Blueprint $table) { $table->integer('transect_id')->unsigned(); $table->foreign('transect_id') - ->references('id') - ->on('transects') - ->onDelete('cascade'); + ->references('id') + ->on('transects') + ->onDelete('cascade'); $table->integer('project_id')->unsigned(); $table->foreign('project_id') - ->references('id') - ->on('projects') + ->references('id') + ->on('projects') // projects with transects shouldn't be deleted - ->onDelete('restrict'); + ->onDelete('restrict'); // each transect may belong to each project only once $table->unique(['transect_id', 'project_id']); @@ -344,9 +344,9 @@ public function up() // images are primarily searched by transect, so do index $table->integer('transect_id')->unsigned()->index(); $table->foreign('transect_id') - ->references('id') - ->on('transects') - ->onDelete('cascade'); + ->references('id') + ->on('transects') + ->onDelete('cascade'); // filename must be unique for each transect $table->unique(['filename', 'transect_id']); @@ -370,19 +370,19 @@ public function up() // children should be deleted as well $table->integer('parent_id')->unsigned()->nullable(); $table->foreign('parent_id') - ->references('id') - ->on('labels') - ->onDelete('cascade'); + ->references('id') + ->on('labels') + ->onDelete('cascade'); // id for the World Register of Marine Species (WoRMS) $table->integer('aphia_id')->nullable(); $table->integer('label_tree_id')->unsigned()->nullable(); $table->foreign('label_tree_id') - ->references('id') - ->on('label_trees') + ->references('id') + ->on('label_trees') // delete labels of a tree if the tree is deleted - ->onDelete('cascade'); + ->onDelete('cascade'); // NO timestamps }); @@ -399,23 +399,23 @@ public function up() $table->integer('image_id')->unsigned(); $table->foreign('image_id') - ->references('id') - ->on('images') - ->onDelete('cascade'); + ->references('id') + ->on('images') + ->onDelete('cascade'); $table->integer('label_id')->unsigned(); $table->foreign('label_id') - ->references('id') - ->on('labels') + ->references('id') + ->on('labels') // don't delete labels in use - ->onDelete('restrict'); + ->onDelete('restrict'); $table->integer('user_id')->unsigned()->nullable(); $table->foreign('user_id') - ->references('id') - ->on('users') + ->references('id') + ->on('users') // don't delete labels if the creator is deleted - ->onDelete('set null'); + ->onDelete('set null'); $table->timestamps(); @@ -446,17 +446,17 @@ public function up() // annotations are primarily searched by image, so do index $table->integer('image_id')->unsigned()->index(); $table->foreign('image_id') - ->references('id') - ->on('images') + ->references('id') + ->on('images') // delete all annotations of a deleted image - ->onDelete('cascade'); + ->onDelete('cascade'); $table->integer('shape_id')->unsigned(); $table->foreign('shape_id') - ->references('id') - ->on('shapes') + ->references('id') + ->on('shapes') // don't delete shapes that are used - ->onDelete('restrict'); + ->onDelete('restrict'); $table->timestamps(); }); @@ -474,23 +474,23 @@ public function up() $table->integer('annotation_id')->unsigned(); $table->foreign('annotation_id') - ->references('id') - ->on('annotations') - ->onDelete('cascade'); + ->references('id') + ->on('annotations') + ->onDelete('cascade'); $table->integer('label_id')->unsigned(); $table->foreign('label_id') - ->references('id') - ->on('labels') + ->references('id') + ->on('labels') // don't delete labels in use - ->onDelete('restrict'); + ->onDelete('restrict'); $table->integer('user_id')->unsigned()->nullable(); $table->foreign('user_id') - ->references('id') - ->on('users') + ->references('id') + ->on('users') // don't delete labels if the creator is deleted - ->onDelete('set null'); + ->onDelete('set null'); $table->float('confidence'); diff --git a/database/migrations/2016_07_04_071231_create_label_sources_table.php b/database/migrations/2016_07_04_071231_create_label_sources_table.php index 1fc346805..03bc28044 100644 --- a/database/migrations/2016_07_04_071231_create_label_sources_table.php +++ b/database/migrations/2016_07_04_071231_create_label_sources_table.php @@ -46,10 +46,10 @@ public function up() $table->integer('label_source_id')->unsigned()->nullable(); $table->foreign('label_source_id') - ->references('id') - ->on('label_sources') + ->references('id') + ->on('label_sources') // don't delete label sources if there are still labels from it - ->onDelete('restrict'); + ->onDelete('restrict'); }); Label::whereNotNull('aphia_id')->chunkById(500, function ($labels) use ($wormsSourceId) { diff --git a/database/migrations/2016_09_05_073358_add_annotation_sessions_table.php b/database/migrations/2016_09_05_073358_add_annotation_sessions_table.php index ab5c3300b..69f284d57 100644 --- a/database/migrations/2016_09_05_073358_add_annotation_sessions_table.php +++ b/database/migrations/2016_09_05_073358_add_annotation_sessions_table.php @@ -32,9 +32,9 @@ public function up() $table->integer('transect_id')->unsigned(); $table->foreign('transect_id') - ->references('id') - ->on('transects') - ->onDelete('cascade'); + ->references('id') + ->on('transects') + ->onDelete('cascade'); $table->timestamps(); $table->timestamp('starts_at'); @@ -55,15 +55,15 @@ public function up() Schema::create('annotation_session_user', function (Blueprint $table) { $table->integer('annotation_session_id')->unsigned(); $table->foreign('annotation_session_id') - ->references('id') - ->on('annotation_sessions') - ->onDelete('cascade'); + ->references('id') + ->on('annotation_sessions') + ->onDelete('cascade'); $table->integer('user_id')->unsigned(); $table->foreign('user_id') - ->references('id') - ->on('users') - ->onDelete('cascade'); + ->references('id') + ->on('users') + ->onDelete('cascade'); // each user must not be added twice $table->unique(['annotation_session_id', 'user_id']); diff --git a/database/migrations/2016_11_08_135324_create_system_messages_table.php b/database/migrations/2016_11_08_135324_create_system_messages_table.php index bd7a58a91..55ce1f019 100644 --- a/database/migrations/2016_11_08_135324_create_system_messages_table.php +++ b/database/migrations/2016_11_08_135324_create_system_messages_table.php @@ -39,10 +39,10 @@ public function up() $table->integer('type_id')->unsigned(); $table->foreign('type_id') - ->references('id') - ->on('system_message_types') + ->references('id') + ->on('system_message_types') // dont delete type if it is in use - ->onDelete('restrict'); + ->onDelete('restrict'); }); } diff --git a/database/migrations/2019_01_09_121306_create_videos_tables.php b/database/migrations/2019_01_09_121306_create_videos_tables.php index 4497de28b..5852eaa4b 100644 --- a/database/migrations/2019_01_09_121306_create_videos_tables.php +++ b/database/migrations/2019_01_09_121306_create_videos_tables.php @@ -21,9 +21,9 @@ public function up() $table->integer('project_id')->unsigned()->index(); $table->foreign('project_id') - ->references('id') - ->on('projects') - ->onDelete('cascade'); + ->references('id') + ->on('projects') + ->onDelete('cascade'); $table->json('attrs')->nullable(); $table->timestamps(); @@ -36,17 +36,17 @@ public function up() $table->integer('video_id')->unsigned()->index(); $table->foreign('video_id') - ->references('id') - ->on('videos') + ->references('id') + ->on('videos') // delete all annotations of a deleted video - ->onDelete('cascade'); + ->onDelete('cascade'); $table->integer('shape_id')->unsigned(); $table->foreign('shape_id') - ->references('id') - ->on('shapes') + ->references('id') + ->on('shapes') // don't delete shapes that are used - ->onDelete('restrict'); + ->onDelete('restrict'); $table->timestamps(); }); @@ -55,23 +55,23 @@ public function up() $table->increments('id'); $table->integer('video_annotation_id')->unsigned(); $table->foreign('video_annotation_id') - ->references('id') - ->on('video_annotations') - ->onDelete('cascade'); + ->references('id') + ->on('video_annotations') + ->onDelete('cascade'); $table->integer('label_id')->unsigned(); $table->foreign('label_id') - ->references('id') - ->on('labels') + ->references('id') + ->on('labels') // don't delete labels in use - ->onDelete('restrict'); + ->onDelete('restrict'); $table->integer('user_id')->unsigned()->nullable(); $table->foreign('user_id') - ->references('id') - ->on('users') + ->references('id') + ->on('users') // don't delete video annotation labels if the creator is deleted - ->onDelete('set null'); + ->onDelete('set null'); $table->timestamps(); diff --git a/database/migrations/2019_05_31_144000_add_videos_creator_id_column.php b/database/migrations/2019_05_31_144000_add_videos_creator_id_column.php index 2978bf51a..970ce111c 100644 --- a/database/migrations/2019_05_31_144000_add_videos_creator_id_column.php +++ b/database/migrations/2019_05_31_144000_add_videos_creator_id_column.php @@ -16,9 +16,9 @@ public function up() Schema::table('videos', function (Blueprint $table) { $table->integer('creator_id')->unsigned()->nullable(); $table->foreign('creator_id') - ->references('id') - ->on('users') - ->onDelete('set null'); + ->references('id') + ->on('users') + ->onDelete('set null'); }); } diff --git a/database/migrations/2019_06_05_101912_add_label_tree_versions.php b/database/migrations/2019_06_05_101912_add_label_tree_versions.php index 7ea76f2a2..393c1059d 100644 --- a/database/migrations/2019_06_05_101912_add_label_tree_versions.php +++ b/database/migrations/2019_06_05_101912_add_label_tree_versions.php @@ -19,9 +19,9 @@ public function up() $table->integer('label_tree_id')->unsigned()->index(); $table->foreign('label_tree_id') - ->references('id') - ->on('label_trees') - ->onDelete('cascade'); + ->references('id') + ->on('label_trees') + ->onDelete('cascade'); $table->unique(['name', 'label_tree_id']); }); @@ -29,9 +29,9 @@ public function up() Schema::table('label_trees', function (Blueprint $table) { $table->integer('version_id')->unsigned()->nullable()->unique(); $table->foreign('version_id') - ->references('id') - ->on('label_tree_versions') - ->onDelete('cascade'); + ->references('id') + ->on('label_tree_versions') + ->onDelete('cascade'); }); } diff --git a/database/migrations/2020_07_14_074140_rename_image_annotations.php b/database/migrations/2020_07_14_074140_rename_image_annotations.php index 3abfe22eb..a724340f9 100644 --- a/database/migrations/2020_07_14_074140_rename_image_annotations.php +++ b/database/migrations/2020_07_14_074140_rename_image_annotations.php @@ -1,7 +1,6 @@ integer('volume_id')->unsigned()->index()->nullable(); $table->foreign('volume_id') - ->references('id') - ->on('volumes') - ->onDelete('cascade'); + ->references('id') + ->on('volumes') + ->onDelete('cascade'); $table->string('filename', 512)->nullable(); $table->unique(['filename', 'volume_id']); @@ -66,15 +66,15 @@ public function down() Schema::table('videos', function (Blueprint $table) { $table->integer('project_id')->unsigned()->index()->nullable(); $table->foreign('project_id') - ->references('id') - ->on('projects') - ->onDelete('cascade'); + ->references('id') + ->on('projects') + ->onDelete('cascade'); $table->integer('creator_id')->unsigned()->nullable(); $table->foreign('creator_id') - ->references('id') - ->on('users') - ->onDelete('set null'); + ->references('id') + ->on('users') + ->onDelete('set null'); $table->integer('volume_id')->nullable(true)->change(); diff --git a/database/migrations/2020_07_29_142043_create_video_labels_table.php b/database/migrations/2020_07_29_142043_create_video_labels_table.php index e5439124b..44d7c68a9 100644 --- a/database/migrations/2020_07_29_142043_create_video_labels_table.php +++ b/database/migrations/2020_07_29_142043_create_video_labels_table.php @@ -18,23 +18,23 @@ public function up() $table->integer('video_id')->unsigned(); $table->foreign('video_id') - ->references('id') - ->on('videos') - ->onDelete('cascade'); + ->references('id') + ->on('videos') + ->onDelete('cascade'); $table->integer('label_id')->unsigned(); $table->foreign('label_id') - ->references('id') - ->on('labels') + ->references('id') + ->on('labels') // don't delete labels in use - ->onDelete('restrict'); + ->onDelete('restrict'); $table->integer('user_id')->unsigned()->nullable(); $table->foreign('user_id') - ->references('id') - ->on('users') + ->references('id') + ->on('users') // don't delete labels if the creator is deleted - ->onDelete('set null'); + ->onDelete('set null'); $table->timestamps(); diff --git a/database/migrations/2020_08_18_114620_add_federated_search_tables.php b/database/migrations/2020_08_18_114620_add_federated_search_tables.php index f684d46cf..dfd84aa56 100644 --- a/database/migrations/2020_08_18_114620_add_federated_search_tables.php +++ b/database/migrations/2020_08_18_114620_add_federated_search_tables.php @@ -44,23 +44,23 @@ public function up() $table->unsignedInteger('federated_search_instance_id'); $table->foreign('federated_search_instance_id') - ->references('id') - ->on('federated_search_instances') - ->onDelete('cascade'); + ->references('id') + ->on('federated_search_instances') + ->onDelete('cascade'); }); Schema::create('federated_search_model_user', function (Blueprint $table) { $table->unsignedBigInteger('federated_search_model_id'); $table->foreign('federated_search_model_id') - ->references('id') - ->on('federated_search_models') - ->onDelete('cascade'); + ->references('id') + ->on('federated_search_models') + ->onDelete('cascade'); $table->unsignedInteger('user_id'); $table->foreign('user_id') - ->references('id') - ->on('users') - ->onDelete('cascade'); + ->references('id') + ->on('users') + ->onDelete('cascade'); $table->unique(['federated_search_model_id', 'user_id']); }); diff --git a/database/migrations/2020_11_02_150156_add_whole_frame_annotation_shape.php b/database/migrations/2020_11_02_150156_add_whole_frame_annotation_shape.php index 99f987721..5ca3d0775 100644 --- a/database/migrations/2020_11_02_150156_add_whole_frame_annotation_shape.php +++ b/database/migrations/2020_11_02_150156_add_whole_frame_annotation_shape.php @@ -1,8 +1,6 @@ integer('type_id')->unsigned()->nullable(); $table->foreign('type_id') - ->references('id') - ->on('system_message_types') + ->references('id') + ->on('system_message_types') // dont delete type if it is in use - ->onDelete('restrict'); + ->onDelete('restrict'); }); $importantType = DB::table('system_message_types') diff --git a/database/migrations/2022_10_21_150936_delete_system_message_notifications.php b/database/migrations/2022_10_21_150936_delete_system_message_notifications.php index c1f4e1ac2..88f25f465 100644 --- a/database/migrations/2022_10_21_150936_delete_system_message_notifications.php +++ b/database/migrations/2022_10_21_150936_delete_system_message_notifications.php @@ -1,11 +1,8 @@ integer('project_id')->unsigned(); $table->foreign('project_id') - ->references('id') - ->on('projects') - ->onDelete('cascade'); + ->references('id') + ->on('projects') + ->onDelete('cascade'); $table->integer('role_id')->unsigned(); $table->foreign('role_id') - ->references('id') - ->on('roles') - ->onDelete('restrict'); + ->references('id') + ->on('roles') + ->onDelete('restrict'); }); DB::statement('ALTER TABLE project_invitations ADD CONSTRAINT check_max_uses CHECK ("max_uses" IS NULL OR "current_uses" <= "max_uses")'); diff --git a/database/migrations/2023_06_02_101511_fix_volume_url_trailing_slash.php b/database/migrations/2023_06_02_101511_fix_volume_url_trailing_slash.php index 1f6135b4e..301f926b9 100644 --- a/database/migrations/2023_06_02_101511_fix_volume_url_trailing_slash.php +++ b/database/migrations/2023_06_02_101511_fix_volume_url_trailing_slash.php @@ -2,11 +2,8 @@ use Biigle\Volume; use Illuminate\Database\Migrations\Migration; -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/tests/TestCase.php b/tests/TestCase.php index c455f6fcb..56153dd6d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,10 +1,10 @@ beGlobalAdmin(); - $this->json('POST', '/api/v1/announcements', [ + $this + ->json('POST', '/api/v1/announcements', [ 'title' => 'my title', ]) // body required ->assertStatus(422); - $this->json('POST', '/api/v1/announcements', [ + $this + ->json('POST', '/api/v1/announcements', [ 'body' => 'my body', ]) // title required ->assertStatus(422); - $this->json('POST', '/api/v1/announcements', [ + $this + ->json('POST', '/api/v1/announcements', [ 'title' => 'my title', 'body' => 'my body', 'show_until' => '2000-01-01', @@ -39,7 +42,8 @@ public function testStore() $this->assertEquals(0, Announcement::count()); - $this->json('POST', '/api/v1/announcements', [ + $this + ->json('POST', '/api/v1/announcements', [ 'title' => 'my title', 'body' => 'my body', ]) @@ -49,7 +53,8 @@ public function testStore() $this->assertNull($announcement->show_until); $announcement->delete(); - $this->json('POST', '/api/v1/announcements', [ + $this + ->json('POST', '/api/v1/announcements', [ 'title' => 'my title', 'body' => 'my body', 'show_until' => now()->addDay(), @@ -64,7 +69,8 @@ public function testStoreDenyOtherWithDate() { Announcement::factory()->create(['show_until' => now()->addDay()]); $this->beGlobalAdmin(); - $this->json('POST', '/api/v1/announcements', [ + $this + ->json('POST', '/api/v1/announcements', [ 'title' => 'my title', 'body' => 'my body', ]) @@ -75,7 +81,8 @@ public function testStoreDenyOtherWithoutDate() { Announcement::factory()->create(); $this->beGlobalAdmin(); - $this->json('POST', '/api/v1/announcements', [ + $this + ->json('POST', '/api/v1/announcements', [ 'title' => 'my title', 'body' => 'my body', ]) @@ -86,7 +93,8 @@ public function testStoreAllowOtherHidden() { Announcement::factory()->create(['show_until' => '2022-10-20 16:00:00']); $this->beGlobalAdmin(); - $this->json('POST', '/api/v1/announcements', [ + $this + ->json('POST', '/api/v1/announcements', [ 'title' => 'my title', 'body' => 'my body', ]) diff --git a/tests/php/Http/Controllers/Api/FederatedSearchInstanceControllerTest.php b/tests/php/Http/Controllers/Api/FederatedSearchInstanceControllerTest.php index f6b9585f7..cb758bcea 100644 --- a/tests/php/Http/Controllers/Api/FederatedSearchInstanceControllerTest.php +++ b/tests/php/Http/Controllers/Api/FederatedSearchInstanceControllerTest.php @@ -26,19 +26,22 @@ public function testStore() $this->postJson('/api/v1/federated-search-instances')->assertStatus(403); $this->beGlobalAdmin(); - $this->postJson('/api/v1/federated-search-instances', [ + $this + ->postJson('/api/v1/federated-search-instances', [ 'name' => 'my instance', ]) // url missing ->assertStatus(422); - $this->postJson('/api/v1/federated-search-instances', [ + $this + ->postJson('/api/v1/federated-search-instances', [ 'url' => 'https://example.com', ]) // name missing ->assertStatus(422); - $this->postJson('/api/v1/federated-search-instances', [ + $this + ->postJson('/api/v1/federated-search-instances', [ 'name' => 'my instance', 'url' => 'https://example.com', ]) @@ -52,7 +55,8 @@ public function testStore() $this->assertNull($instance->remote_token); $this->assertNull($instance->indexed_at); - $this->postJson('/api/v1/federated-search-instances', [ + $this + ->postJson('/api/v1/federated-search-instances', [ 'name' => 'my other instance', 'url' => 'https://example.com', ]) @@ -74,10 +78,12 @@ public function testUpdate() $this->putJson("/api/v1/federated-search-instances/{$id}")->assertStatus(403); $this->beGlobalAdmin(); - $this->putJson("/api/v1/federated-search-instances/{$id}", [ - 'name' => 'my updated instance', - 'url' => 'https://www.example.com', - ])->assertStatus(200); + $this + ->putJson("/api/v1/federated-search-instances/{$id}", [ + 'name' => 'my updated instance', + 'url' => 'https://www.example.com', + ]) + ->assertStatus(200); $instance->refresh(); $this->assertEquals('my updated instance', $instance->name); @@ -104,9 +110,11 @@ public function testUpdateSetRemoteToken() Bus::fake(); $this->beGlobalAdmin(); - $this->putJson("/api/v1/federated-search-instances/{$id}", [ - 'remote_token' => 'mytoken', - ])->assertStatus(200); + $this + ->putJson("/api/v1/federated-search-instances/{$id}", [ + 'remote_token' => 'mytoken', + ]) + ->assertStatus(200); $this->assertEquals('mytoken', $instance->fresh()->remote_token); $this->assertCount(1, $container); @@ -137,9 +145,11 @@ public function testUpdateSetRemoteTokenInvalidToken() Bus::fake(); $this->beGlobalAdmin(); - $this->putJson("/api/v1/federated-search-instances/{$id}", [ - 'remote_token' => 'mytoken', - ])->assertStatus(422); + $this + ->putJson("/api/v1/federated-search-instances/{$id}", [ + 'remote_token' => 'mytoken', + ]) + ->assertStatus(422); Bus::assertNotDispatched(UpdateFederatedSearchIndex::class); } @@ -166,13 +176,17 @@ public function testUpdateSetRemoteTokenInvalidUrl() Bus::fake(); $this->beGlobalAdmin(); - $this->putJson("/api/v1/federated-search-instances/{$id}", [ - 'remote_token' => 'mytoken', - ])->assertStatus(422); + $this + ->putJson("/api/v1/federated-search-instances/{$id}", [ + 'remote_token' => 'mytoken', + ]) + ->assertStatus(422); - $this->putJson("/api/v1/federated-search-instances/{$id}", [ - 'remote_token' => 'mytoken', - ])->assertStatus(422); + $this + ->putJson("/api/v1/federated-search-instances/{$id}", [ + 'remote_token' => 'mytoken', + ]) + ->assertStatus(422); Bus::assertNotDispatched(UpdateFederatedSearchIndex::class); } @@ -198,9 +212,11 @@ public function testUpdateClearRemoteToken() Bus::fake(); $this->beGlobalAdmin(); - $this->putJson("/api/v1/federated-search-instances/{$id}", [ - 'remote_token' => '', - ])->assertStatus(200); + $this + ->putJson("/api/v1/federated-search-instances/{$id}", [ + 'remote_token' => '', + ]) + ->assertStatus(200); $this->assertCount(0, $container); $this->assertNull($instance->fresh()->remote_token); @@ -229,9 +245,11 @@ public function testUpdateUrlWithRemoteToken() Bus::fake(); $this->beGlobalAdmin(); - $this->putJson("/api/v1/federated-search-instances/{$id}", [ - 'url' => 'https://www.example.com', - ])->assertStatus(200); + $this + ->putJson("/api/v1/federated-search-instances/{$id}", [ + 'url' => 'https://www.example.com', + ]) + ->assertStatus(200); Bus::assertNotDispatched(UpdateFederatedSearchIndex::class); $this->assertCount(1, $container); @@ -249,7 +267,8 @@ public function testUpdateGetLocalToken() $id = $instance->id; $this->beGlobalAdmin(); - $response = $this->putJson("/api/v1/federated-search-instances/{$id}", [ + $response = $this + ->putJson("/api/v1/federated-search-instances/{$id}", [ 'local_token' => true, ]) ->assertStatus(200); @@ -257,7 +276,8 @@ public function testUpdateGetLocalToken() $this->assertNotNull($instance->fresh()->local_token); $this->assertStringContainsString('new_local_token', $response->getContent()); - $this->put("/api/v1/federated-search-instances/{$id}", [ + $this + ->put("/api/v1/federated-search-instances/{$id}", [ 'local_token' => true, ]) ->assertSessionHas('new_local_token'); @@ -271,7 +291,8 @@ public function testUpdateClearLocalToken() $id = $instance->id; $this->beGlobalAdmin(); - $response = $this->putJson("/api/v1/federated-search-instances/{$id}", [ + $response = $this + ->putJson("/api/v1/federated-search-instances/{$id}", [ 'local_token' => false, ]) ->assertStatus(200); diff --git a/tests/php/Http/Controllers/Api/ImageAnnotationBulkControllerTest.php b/tests/php/Http/Controllers/Api/ImageAnnotationBulkControllerTest.php index 285a63c0e..d4e436504 100644 --- a/tests/php/Http/Controllers/Api/ImageAnnotationBulkControllerTest.php +++ b/tests/php/Http/Controllers/Api/ImageAnnotationBulkControllerTest.php @@ -4,12 +4,9 @@ use ApiTestCase; use Biigle\Shape; -use Biigle\Tests\AnnotationSessionTest; use Biigle\Tests\ImageAnnotationTest; use Biigle\Tests\ImageTest; use Biigle\Tests\LabelTest; -use Cache; -use Carbon\Carbon; class ImageAnnotationBulkControllerTest extends ApiTestCase { @@ -38,7 +35,8 @@ public function store($url) $image = ImageTest::create(); $this->beUser(); - $this->postJson($url, [[ + $this + ->postJson($url, [[ 'image_id' => $image->id, 'shape_id' => Shape::pointId(), 'points' => [100, 100], @@ -48,7 +46,8 @@ public function store($url) ->assertStatus(403); $this->beEditor(); - $this->postJson($url, [[ + $this + ->postJson($url, [[ 'image_id' => $image->id, 'shape_id' => Shape::pointId(), 'points' => [100, 100], @@ -57,7 +56,8 @@ public function store($url) ]]) ->assertStatus(403); - $this->postJson($url, [ + $this + ->postJson($url, [ [ 'image_id' => $image->id, 'shape_id' => Shape::pointId(), @@ -75,7 +75,8 @@ public function store($url) ]) ->assertStatus(403); - $this->postJson($url, [ + $this + ->postJson($url, [ [ 'image_id' => $this->annotation->image_id, 'shape_id' => Shape::pointId(), @@ -114,7 +115,8 @@ public function testStoreValidationLegacy() public function storeValidation($url) { $this->beEditor(); - $this->postJson($url, [[ + $this + ->postJson($url, [[ 'image_id' => 999, 'shape_id' => Shape::pointId(), 'points' => [100, 100], @@ -123,7 +125,8 @@ public function storeValidation($url) ]]) ->assertStatus(422); - $this->postJson($url, [[ + $this + ->postJson($url, [[ 'image_id' => $this->annotation->image_id, 'shape_id' => Shape::pointId(), 'points' => [100], @@ -132,7 +135,8 @@ public function storeValidation($url) ]]) ->assertStatus(422); - $this->postJson($url, [[ + $this + ->postJson($url, [[ 'image_id' => $this->annotation->image_id, 'shape_id' => 999, 'points' => [100, 100], @@ -141,7 +145,8 @@ public function storeValidation($url) ]]) ->assertStatus(422); - $this->postJson($url, [[ + $this + ->postJson($url, [[ 'shape_id' => Shape::pointId(), 'points' => [100, 100], 'label_id' => $this->labelRoot()->id, @@ -149,7 +154,8 @@ public function storeValidation($url) ]]) ->assertStatus(422); - $this->postJson($url, [[ + $this + ->postJson($url, [[ 'image_id' => $this->annotation->image_id, 'shape_id' => Shape::pointId(), 'points' => [100, 100], @@ -158,7 +164,8 @@ public function storeValidation($url) ]]) ->assertStatus(422); - $this->postJson($url, [ + $this + ->postJson($url, [ [ 'image_id' => $this->annotation->image_id, 'shape_id' => Shape::pointId(), @@ -176,7 +183,8 @@ public function storeValidation($url) ]) ->assertStatus(403); - $this->postJson($url, [[ + $this + ->postJson($url, [[ 'image_id' => $this->annotation->image_id, 'shape_id' => Shape::pointId(), 'points' => [100, 100], @@ -187,7 +195,8 @@ public function storeValidation($url) $this->assertEquals(1, $this->annotation->image->annotations()->count()); - $this->postJson($url, [[ + $this + ->postJson($url, [[ 'image_id' => $this->annotation->image_id + 0.9, 'shape_id' => Shape::pointId(), 'points' => [100, 100], @@ -196,7 +205,8 @@ public function storeValidation($url) ]]) ->assertStatus(422); - $this->postJson($url, [[ + $this + ->postJson($url, [[ 'image_id' => $this->annotation->image_id, 'shape_id' => Shape::pointId(), 'points' => [100, 100], @@ -237,7 +247,8 @@ public function storeLimit($url) public function testStoreLabelIdIsString() { $this->beEditor(); - $this->postJson('api/v1/annotations', [ + $this + ->postJson('api/v1/annotations', [ [ 'image_id' => $this->annotation->image_id, 'shape_id' => Shape::pointId(), @@ -254,7 +265,8 @@ public function testStoreLabelIdIsString() public function testStoreLabelIdIsFloat() { $this->beEditor(); - $this->postJson('api/v1/annotations', [ + $this + ->postJson('api/v1/annotations', [ [ 'image_id' => $this->annotation->image_id, 'shape_id' => Shape::pointId(), diff --git a/tests/php/Http/Controllers/Api/ImageAnnotationControllerTest.php b/tests/php/Http/Controllers/Api/ImageAnnotationControllerTest.php index 3ba0ab5bb..c637e8dcf 100644 --- a/tests/php/Http/Controllers/Api/ImageAnnotationControllerTest.php +++ b/tests/php/Http/Controllers/Api/ImageAnnotationControllerTest.php @@ -384,7 +384,8 @@ public function updateChangeShape($url) $this->putJson("{$url}/{$id}", ['shape_id' => Shape::circleId()]) ->assertStatus(422); - $this->putJson("{$url}/{$id}", [ + $this + ->putJson("{$url}/{$id}", [ 'shape_id' => Shape::circleId(), 'points' => [100, 200, 300], ]) diff --git a/tests/php/Http/Controllers/Api/ImageControllerTest.php b/tests/php/Http/Controllers/Api/ImageControllerTest.php index ac3c1e7c4..cd3970fb7 100644 --- a/tests/php/Http/Controllers/Api/ImageControllerTest.php +++ b/tests/php/Http/Controllers/Api/ImageControllerTest.php @@ -3,11 +3,8 @@ namespace Biigle\Tests\Http\Controllers\Api; use ApiTestCase; -use Biigle\Image; use Biigle\Tests\ImageAnnotationTest; use Biigle\Tests\ImageTest; -use Biigle\Volume; -use File; class ImageControllerTest extends ApiTestCase { diff --git a/tests/php/Http/Controllers/Api/LabelSourceControllerTest.php b/tests/php/Http/Controllers/Api/LabelSourceControllerTest.php index b0fe72ef9..05b4942c7 100644 --- a/tests/php/Http/Controllers/Api/LabelSourceControllerTest.php +++ b/tests/php/Http/Controllers/Api/LabelSourceControllerTest.php @@ -6,7 +6,6 @@ use App; use Biigle\Tests\LabelSourceTest; use Illuminate\Http\Request; -use Illuminate\Http\Response; use Mockery; class LabelSourceControllerTest extends ApiTestCase @@ -21,9 +20,7 @@ public function testFind() ->with(Mockery::type(Request::class)) ->andReturn([['name' => 'My Query Label']]); - App::singleton('Biigle\Services\LabelSourceAdapters\MySourceAdapter', function () use ($mock) { - return $mock; - }); + App::singleton('Biigle\Services\LabelSourceAdapters\MySourceAdapter', fn () => $mock); $this->doTestApiRoute('GET', "/api/v1/label-sources/{$source->id}/find"); @@ -33,9 +30,10 @@ public function testFind() // no query parameter $response->assertStatus(422); - $response = $this->json('GET', "/api/v1/label-sources/{$source->id}/find", [ - 'query' => 'my query', - ]); + $response = $this + ->json('GET', "/api/v1/label-sources/{$source->id}/find", [ + 'query' => 'my query', + ]); $response->assertStatus(200); $response->assertExactJson([['name' => 'My Query Label']]); } diff --git a/tests/php/Http/Controllers/Api/LabelTreeAuthorizedProjectControllerTest.php b/tests/php/Http/Controllers/Api/LabelTreeAuthorizedProjectControllerTest.php index f8985e545..07d5c628d 100644 --- a/tests/php/Http/Controllers/Api/LabelTreeAuthorizedProjectControllerTest.php +++ b/tests/php/Http/Controllers/Api/LabelTreeAuthorizedProjectControllerTest.php @@ -76,7 +76,8 @@ public function testStoreVersions() $version->labelTree->addMember($this->admin(), Role::admin()); $tree = LabelTreeTest::create(['version_id' => $version->id]); $this->beAdmin(); - $this->postJson("/api/v1/label-trees/{$tree->id}/authorized-projects", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/authorized-projects", [ 'id' => $this->project()->id, ]) ->assertStatus(403); @@ -88,7 +89,8 @@ public function testStorePropagateVersions() $version->labelTree->addMember($this->admin(), Role::admin()); $tree = LabelTreeTest::create(['version_id' => $version->id]); $this->beAdmin(); - $this->postJson("/api/v1/label-trees/{$version->labelTree->id}/authorized-projects", [ + $this + ->postJson("/api/v1/label-trees/{$version->labelTree->id}/authorized-projects", [ 'id' => $this->project()->id, ]) ->assertStatus(200); diff --git a/tests/php/Http/Controllers/Api/LabelTreeControllerTest.php b/tests/php/Http/Controllers/Api/LabelTreeControllerTest.php index 94481d419..dd8810ba4 100644 --- a/tests/php/Http/Controllers/Api/LabelTreeControllerTest.php +++ b/tests/php/Http/Controllers/Api/LabelTreeControllerTest.php @@ -90,28 +90,29 @@ public function testShow() $response->assertStatus(403); $this->beEditor(); - $response = $this->get("/api/v1/label-trees/{$tree->id}") - ->assertJsonFragment([ - 'id' => $tree->id, - 'name' => $tree->name, - 'description' => $tree->description, - 'created_at' => $tree->created_at->toJson(), - 'updated_at' => $tree->updated_at->toJson(), - 'version' => null, - 'versions' => [], - ]) - ->assertJsonFragment([ - 'id' => $label->id, - 'name' => $label->name, - 'parent_id' => $label->parent_id, - 'label_tree_id' => $tree->id, - ]) - ->assertJsonFragment([ - 'id' => $this->editor()->id, - 'firstname' => $this->editor()->firstname, - 'lastname' => $this->editor()->lastname, - 'role_id' => Role::editorId(), - ]); + $response = $this + ->get("/api/v1/label-trees/{$tree->id}") + ->assertJsonFragment([ + 'id' => $tree->id, + 'name' => $tree->name, + 'description' => $tree->description, + 'created_at' => $tree->created_at->toJson(), + 'updated_at' => $tree->updated_at->toJson(), + 'version' => null, + 'versions' => [], + ]) + ->assertJsonFragment([ + 'id' => $label->id, + 'name' => $label->name, + 'parent_id' => $label->parent_id, + 'label_tree_id' => $tree->id, + ]) + ->assertJsonFragment([ + 'id' => $this->editor()->id, + 'firstname' => $this->editor()->firstname, + 'lastname' => $this->editor()->lastname, + 'role_id' => Role::editorId(), + ]); } public function testUpdate() @@ -229,7 +230,8 @@ public function testUpdatePropagateVisibility() ]); $master->addMember($this->admin(), Role::admin()); $this->beAdmin(); - $this->putJson("/api/v1/label-trees/{$master->id}", [ + $this + ->putJson("/api/v1/label-trees/{$master->id}", [ 'visibility_id' => Visibility::publicId(), ]) ->assertStatus(200); @@ -247,7 +249,8 @@ public function testUpdatePropagateName() ]); $master->addMember($this->admin(), Role::admin()); $this->beAdmin(); - $this->putJson("/api/v1/label-trees/{$master->id}", [ + $this + ->putJson("/api/v1/label-trees/{$master->id}", [ 'name' => 'My Cool Tree', ]) ->assertStatus(200); @@ -403,7 +406,8 @@ public function testStoreFork() ]); $this->beEditor(); - $this->postJson('/api/v1/label-trees', [ + $this + ->postJson('/api/v1/label-trees', [ 'upstream_label_tree_id' => $baseTree->id, 'name' => 'abc', 'visibility_id' => Visibility::publicId(), @@ -415,7 +419,8 @@ public function testStoreFork() $baseTree->addMember($this->editor(), Role::editor()); Cache::flush(); - $this->postJson('/api/v1/label-trees', [ + $this + ->postJson('/api/v1/label-trees', [ 'upstream_label_tree_id' => $baseTree->id, 'name' => 'abc', 'visibility_id' => Visibility::publicId(), @@ -427,7 +432,8 @@ public function testStoreFork() $this->beGuest(); $baseTree->visibility_id = Visibility::publicId(); $baseTree->save(); - $this->postJson('/api/v1/label-trees', [ + $this + ->postJson('/api/v1/label-trees', [ 'upstream_label_tree_id' => $baseTree->id, 'name' => 'abc', 'visibility_id' => Visibility::publicId(), diff --git a/tests/php/Http/Controllers/Api/LabelTreeLabelControllerTest.php b/tests/php/Http/Controllers/Api/LabelTreeLabelControllerTest.php index 382133987..9bda666c7 100644 --- a/tests/php/Http/Controllers/Api/LabelTreeLabelControllerTest.php +++ b/tests/php/Http/Controllers/Api/LabelTreeLabelControllerTest.php @@ -148,9 +148,7 @@ public function testStoreLabelSource() ->once() ->andReturn($labels); - App::singleton('Biigle\Services\LabelSourceAdapters\MySourceAdapter', function () use ($mock) { - return $mock; - }); + App::singleton('Biigle\Services\LabelSourceAdapters\MySourceAdapter', fn () => $mock); $response = $this->json('POST', "/api/v1/label-trees/{$tree->id}/labels", [ 'name' => 'new label', @@ -175,9 +173,7 @@ public function testStoreLabelSourceError() ->once() ->andThrow($exception); - App::singleton('Biigle\Services\LabelSourceAdapters\MySourceAdapter', function () use ($mock) { - return $mock; - }); + App::singleton('Biigle\Services\LabelSourceAdapters\MySourceAdapter', fn () => $mock); $this->beEditor(); $response = $this->json('POST', "/api/v1/label-trees/{$tree->id}/labels", [ @@ -197,7 +193,8 @@ public function testStoreVersionedTree() $tree = LabelTreeTest::create(['version_id' => $version->id]); $this->beEditor(); - $this->postJson("/api/v1/label-trees/{$tree->id}/labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/labels", [ 'name' => 'new label', 'color' => 'bada55', ]) diff --git a/tests/php/Http/Controllers/Api/LabelTreeMergeControllerTest.php b/tests/php/Http/Controllers/Api/LabelTreeMergeControllerTest.php index 4526a006f..369e0ac54 100644 --- a/tests/php/Http/Controllers/Api/LabelTreeMergeControllerTest.php +++ b/tests/php/Http/Controllers/Api/LabelTreeMergeControllerTest.php @@ -8,10 +8,8 @@ use Biigle\Tests\ImageLabelTest; use Biigle\Tests\LabelTest; use Biigle\Tests\LabelTreeTest; -use Biigle\Tests\UserTest; use Biigle\Tests\VideoAnnotationLabelTest; use Biigle\Tests\VideoLabelTest; -use Biigle\Visibility; class LabelTreeMergeControllerTest extends ApiTestCase { @@ -36,7 +34,8 @@ public function testStore() // Missing arguments. ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$existingChild->id], 'create' => [ [ @@ -87,7 +86,8 @@ public function testStoreValidateParentIds() $otherParent = LabelTest::create(); $this->beEditor(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'create' => [ [ 'name' => 'New Label', @@ -99,7 +99,8 @@ public function testStoreValidateParentIds() // Parent does not exist. ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'create' => [ [ 'name' => 'New Label', @@ -111,7 +112,8 @@ public function testStoreValidateParentIds() // Parent is no ID. ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'create' => [ [ 'name' => 'New Label', @@ -123,7 +125,8 @@ public function testStoreValidateParentIds() // Parent belongs to other tree. ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'create' => [ [ 'name' => 'New Label', @@ -142,7 +145,8 @@ public function testStoreValidateCreateProperties() $sameParent = LabelTest::create(['label_tree_id' => $tree->id]); $this->beEditor(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'create' => [ [ 'name' => 'New Label', @@ -152,7 +156,8 @@ public function testStoreValidateCreateProperties() // Color is required. ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'create' => [ [ 'color' => 'bada55', @@ -162,7 +167,8 @@ public function testStoreValidateCreateProperties() // Name is required. ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'create' => [ [ 'name' => 'New Label', @@ -173,7 +179,8 @@ public function testStoreValidateCreateProperties() // Color is invalid. ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'create' => [ [ 'name' => 'New Label', @@ -189,7 +196,8 @@ public function testStoreValidateCreateProperties() // Child is invalid. ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'create' => [ [ 'name' => 'New Label', @@ -215,13 +223,15 @@ public function testStoreRemoveIdsExist() $otherTree = LabelTest::create(); $this->beEditor(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [999], ]) // Does not exist. ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$otherTree->id], ]) // Belongs to other tree. @@ -236,7 +246,8 @@ public function testStoreRemoveIdsCanBeDeletedImageAnnotationLabel() $annotationLabel = ImageAnnotationLabelTest::create(['label_id' => $label->id]); $this->beEditor(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$label->id], ]) // Cannot be removed. @@ -248,13 +259,15 @@ public function testStoreRemoveIdsCanBeDeletedImageAnnotationLabel() 'parent_id' => $label->id, ]); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$label->id], ]) // Still cannot be removed. ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$label->id, $child->id], ]) ->assertStatus(200); @@ -268,7 +281,8 @@ public function testStoreRemoveIdsCanBeDeletedImageLabel() $annotationLabel = ImageLabelTest::create(['label_id' => $label->id]); $this->beEditor(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$label->id], ]) // Cannot be removed. @@ -276,7 +290,8 @@ public function testStoreRemoveIdsCanBeDeletedImageLabel() $annotationLabel->delete(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$label->id], ]) ->assertStatus(200); @@ -290,7 +305,8 @@ public function testStoreRemoveIdsCanBeDeletedVideoAnnotationLabel() $annotationLabel = VideoAnnotationLabelTest::create(['label_id' => $label->id]); $this->beEditor(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$label->id], ]) // Cannot be removed. @@ -298,7 +314,8 @@ public function testStoreRemoveIdsCanBeDeletedVideoAnnotationLabel() $annotationLabel->delete(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$label->id], ]) ->assertStatus(200); @@ -312,7 +329,8 @@ public function testStoreRemoveIdsCanBeDeletedVideoLabel() $annotationLabel = VideoLabelTest::create(['label_id' => $label->id]); $this->beEditor(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$label->id], ]) // Cannot be removed. @@ -320,7 +338,8 @@ public function testStoreRemoveIdsCanBeDeletedVideoLabel() $annotationLabel->delete(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$label->id], ]) ->assertStatus(200); @@ -333,7 +352,8 @@ public function testStoreRemoveIdsAreNotUsedInCreate() $label = LabelTest::create(['label_tree_id' => $tree->id]); $this->beEditor(); - $this->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ + $this + ->postJson("/api/v1/label-trees/{$tree->id}/merge-labels", [ 'remove' => [$label->id], 'create' => [ [ diff --git a/tests/php/Http/Controllers/Api/LabelTreeVersionControllerTest.php b/tests/php/Http/Controllers/Api/LabelTreeVersionControllerTest.php index 2ce1a49ec..8b9cdb8ff 100644 --- a/tests/php/Http/Controllers/Api/LabelTreeVersionControllerTest.php +++ b/tests/php/Http/Controllers/Api/LabelTreeVersionControllerTest.php @@ -6,10 +6,7 @@ use Biigle\LabelTree; use Biigle\Role; use Biigle\Tests\ImageAnnotationLabelTest; -use Biigle\Tests\LabelTest; -use Biigle\Tests\LabelTreeTest; use Biigle\Tests\LabelTreeVersionTest; -use Biigle\Visibility; class LabelTreeVersionControllerTest extends ApiTestCase { @@ -36,13 +33,15 @@ public function testStore() $this->postJson("/api/v1/label-trees/{$master->id}/versions") ->assertStatus(422); - $this->postJson("/api/v1/label-trees/{$master->id}/versions", [ + $this + ->postJson("/api/v1/label-trees/{$master->id}/versions", [ 'name' => 'v1.0', 'description' => 'First version.', ]) ->assertStatus(200); - $this->postJson("/api/v1/label-trees/{$master->id}/versions", [ + $this + ->postJson("/api/v1/label-trees/{$master->id}/versions", [ 'name' => 'v1.0', 'description' => 'Another first version.', ]) @@ -76,7 +75,8 @@ public function testStoreDoi() $master = $this->labelTree(); $master->addMember($this->admin(), Role::adminId()); $this->beAdmin(); - $this->postJson("/api/v1/label-trees/{$master->id}/versions", [ + $this + ->postJson("/api/v1/label-trees/{$master->id}/versions", [ 'name' => 'v1.0', 'doi' => 'https://doi.org/10.5281/zenodo.xxxxxxx', ]) @@ -90,7 +90,8 @@ public function testStoreDoiEmpty() $master = $this->labelTree(); $master->addMember($this->admin(), Role::adminId()); $this->beAdmin(); - $this->postJson("/api/v1/label-trees/{$master->id}/versions", [ + $this + ->postJson("/api/v1/label-trees/{$master->id}/versions", [ 'name' => 'v1.0', 'doi' => '', ]) @@ -116,7 +117,8 @@ public function testUpdate() $this->putJson("/api/v1/label-tree-versions/{$version->id}") ->assertStatus(422); - $this->putJson("/api/v1/label-tree-versions/{$version->id}", [ + $this + ->putJson("/api/v1/label-tree-versions/{$version->id}", [ 'doi' => 'https://doi.org/10.5281/zenodo.xxxxxxx', ]) ->assertStatus(200); diff --git a/tests/php/Http/Controllers/Api/LinkVideoAnnotationControllerTest.php b/tests/php/Http/Controllers/Api/LinkVideoAnnotationControllerTest.php index d4d86051c..70876df82 100644 --- a/tests/php/Http/Controllers/Api/LinkVideoAnnotationControllerTest.php +++ b/tests/php/Http/Controllers/Api/LinkVideoAnnotationControllerTest.php @@ -37,34 +37,39 @@ public function testStoreValidation() $this->doTestApiRoute('POST', "api/v1/video-annotations/{$a1->id}/link"); $this->beUser(); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(403); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => 0, ]) // Second annotation ID must exist. ->assertStatus(404); $a2->update(['video_id' => VideoTest::create()->id]); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) // Other annotation must belong to the same video. ->assertStatus(422); $a2->update(['video_id' => $this->video->id, 'shape_id' => Shape::circleId()]); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) // The shapes must match. ->assertStatus(422); $a2->update(['shape_id' => Shape::pointId()]); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(200) @@ -91,43 +96,50 @@ public function testStoreValidateOverlap() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(422); $a2->update(['frames' => [0.5, 1.5]]); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(422); $a2->update(['frames' => [1.25, 1.75]]); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(422); $a2->update(['frames' => [0.5, 2.5]]); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(422); $a2->update(['frames' => [0.5, 2.0]]); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(422); $a2->update(['frames' => [1.0, 2.5]]); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(422); $a2->update(['frames' => [1.0, 2.0]]); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(422); @@ -150,7 +162,8 @@ public function testStoreBefore() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(200); @@ -177,7 +190,8 @@ public function testStoreAfter() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(200); @@ -224,7 +238,8 @@ public function testStoreMergeLabels() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(200); @@ -253,7 +268,8 @@ public function testStoreTouching() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(200); @@ -280,7 +296,8 @@ public function testStoreSingleFrameTouching() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) // This is the same than overlapping times of an annotation clip. @@ -304,7 +321,8 @@ public function testStoreWholeFrame() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$a1->id}/link", [ + $this + ->postJson("api/v1/video-annotations/{$a1->id}/link", [ 'annotation_id' => $a2->id, ]) ->assertStatus(200); diff --git a/tests/php/Http/Controllers/Api/ProjectInvitationControllerTest.php b/tests/php/Http/Controllers/Api/ProjectInvitationControllerTest.php index cf6af6559..d8b66123b 100644 --- a/tests/php/Http/Controllers/Api/ProjectInvitationControllerTest.php +++ b/tests/php/Http/Controllers/Api/ProjectInvitationControllerTest.php @@ -3,10 +3,8 @@ namespace Biigle\Tests\Http\Controllers\Api; use ApiTestCase; -use Biigle\Project; use Biigle\ProjectInvitation; use Biigle\Role; -use Biigle\User; class ProjectInvitationControllerTest extends ApiTestCase { @@ -16,23 +14,29 @@ public function testStore() $this->doTestApiRoute('POST', "/api/v1/projects/{$id}/invitations"); $this->beUser(); - $this->postJson("/api/v1/projects/{$id}/invitations")->assertStatus(403); + $this->postJson("/api/v1/projects/{$id}/invitations") + ->assertStatus(403); // missing arguments $this->beAdmin(); - $this->postJson("/api/v1/projects/{$id}/invitations")->assertStatus(422); + $this->postJson("/api/v1/projects/{$id}/invitations") + ->assertStatus(422); // Expiration must be in the future. - $this->postJson("/api/v1/projects/{$id}/invitations", [ - 'expires_at' => '2022-11-09 15:10:00', - ])->assertStatus(422); + $this + ->postJson("/api/v1/projects/{$id}/invitations", [ + 'expires_at' => '2022-11-09 15:10:00', + ]) + ->assertStatus(422); $this->assertFalse($this->project()->invitations()->exists()); $timestamp = now()->addDay()->startOfDay(); - $this->postJson("/api/v1/projects/{$id}/invitations", [ - 'expires_at' => $timestamp, - ])->assertSuccessful(); + $this + ->postJson("/api/v1/projects/{$id}/invitations", [ + 'expires_at' => $timestamp, + ]) + ->assertSuccessful(); $invitation = $this->project()->invitations()->first(); $this->assertNotNull($invitation); @@ -50,26 +54,34 @@ public function testStoreOptionalAttributes() $timestamp = now()->addDay(); // Invited users may not become admins. - $this->postJson("/api/v1/projects/{$id}/invitations", [ - 'expires_at' => $timestamp, - 'role_id' => Role::adminId(), - ])->assertStatus(422); - - $this->postJson("/api/v1/projects/{$id}/invitations", [ - 'expires_at' => $timestamp, - 'role_id' => -1, - ])->assertStatus(422); - - $this->postJson("/api/v1/projects/{$id}/invitations", [ - 'expires_at' => $timestamp, - 'max_uses' => 0, - ])->assertStatus(422); - - $this->postJson("/api/v1/projects/{$id}/invitations", [ - 'expires_at' => $timestamp, - 'role_id' => Role::guestId(), - 'max_uses' => 10, - ])->assertSuccessful(); + $this + ->postJson("/api/v1/projects/{$id}/invitations", [ + 'expires_at' => $timestamp, + 'role_id' => Role::adminId(), + ]) + ->assertStatus(422); + + $this + ->postJson("/api/v1/projects/{$id}/invitations", [ + 'expires_at' => $timestamp, + 'role_id' => -1, + ]) + ->assertStatus(422); + + $this + ->postJson("/api/v1/projects/{$id}/invitations", [ + 'expires_at' => $timestamp, + 'max_uses' => 0, + ]) + ->assertStatus(422); + + $this + ->postJson("/api/v1/projects/{$id}/invitations", [ + 'expires_at' => $timestamp, + 'role_id' => Role::guestId(), + 'max_uses' => 10, + ]) + ->assertSuccessful(); $invitation = $this->project()->invitations()->first(); $this->assertNotNull($invitation); @@ -108,12 +120,14 @@ public function testJoin() $this->postJson("/api/v1/project-invitations/{$id}/join") ->assertStatus(422); - $this->postJson("/api/v1/project-invitations/{$id}/join", [ + $this + ->postJson("/api/v1/project-invitations/{$id}/join", [ 'token' => 'caa3183e-a7ee-46c9-a744-0fc91d1a1fc4', ]) ->assertStatus(422); - $this->postJson("/api/v1/project-invitations/{$id}/join", [ + $this + ->postJson("/api/v1/project-invitations/{$id}/join", [ 'token' => $invitation->uuid, ]) ->assertSuccessful(); @@ -134,7 +148,8 @@ public function testJoinRedirect() $pid = $this->project()->id; $this->beUser(); - $this->post("/api/v1/project-invitations/{$id}/join", [ + $this + ->post("/api/v1/project-invitations/{$id}/join", [ 'token' => $invitation->uuid, ]) ->assertRedirect("projects/{$pid}"); @@ -151,7 +166,8 @@ public function testJoinExpiredUses() $id = $invitation->id; $this->beUser(); - $this->postJson("/api/v1/project-invitations/{$id}/join", [ + $this + ->postJson("/api/v1/project-invitations/{$id}/join", [ 'token' => $invitation->uuid, ]) ->assertStatus(404); @@ -167,7 +183,8 @@ public function testJoinExpiredDate() $id = $invitation->id; $this->beUser(); - $this->postJson("/api/v1/project-invitations/{$id}/join", [ + $this + ->postJson("/api/v1/project-invitations/{$id}/join", [ 'token' => $invitation->uuid, ]) ->assertStatus(404); @@ -181,7 +198,8 @@ public function testJoinAlreadyMember() $id = $invitation->id; $this->beGuest(); - $this->postJson("/api/v1/project-invitations/{$id}/join", [ + $this + ->postJson("/api/v1/project-invitations/{$id}/join", [ 'token' => $invitation->uuid, ]) ->assertSuccessful(); diff --git a/tests/php/Http/Controllers/Api/ProjectLabelTreeControllerTest.php b/tests/php/Http/Controllers/Api/ProjectLabelTreeControllerTest.php index ae67f36c5..bbbf06240 100644 --- a/tests/php/Http/Controllers/Api/ProjectLabelTreeControllerTest.php +++ b/tests/php/Http/Controllers/Api/ProjectLabelTreeControllerTest.php @@ -3,7 +3,6 @@ namespace Biigle\Tests\Http\Controllers\Api; use ApiTestCase; -use Biigle\LabelTree; use Biigle\Project; use Biigle\Tests\LabelTreeTest; use Biigle\Tests\LabelTreeVersionTest; diff --git a/tests/php/Http/Controllers/Api/ProjectUserControllerTest.php b/tests/php/Http/Controllers/Api/ProjectUserControllerTest.php index 257616757..23924b080 100644 --- a/tests/php/Http/Controllers/Api/ProjectUserControllerTest.php +++ b/tests/php/Http/Controllers/Api/ProjectUserControllerTest.php @@ -67,7 +67,8 @@ public function testUpdate() $response->assertStatus(422); // last admin cannot be removed - $this->putJson("/api/v1/projects/{$id}/users/".$this->admin()->id, [ + $this + ->putJson("/api/v1/projects/{$id}/users/".$this->admin()->id, [ 'project_role_id' => Role::guestId(), ]) ->assertStatus(422) @@ -91,17 +92,23 @@ public function testUpdateGlobalGuest() $this->project()->addUserId($id, Role::guestId()); $this->beAdmin(); - $this->putJson("/api/v1/projects/{$pid}/users/{$id}", [ - 'project_role_id' => Role::editorId(), - ])->assertStatus(200); + $this + ->putJson("/api/v1/projects/{$pid}/users/{$id}", [ + 'project_role_id' => Role::editorId(), + ]) + ->assertStatus(200); - $this->putJson("/api/v1/projects/{$pid}/users/{$id}", [ - 'project_role_id' => Role::expertId(), - ])->assertStatus(200); + $this + ->putJson("/api/v1/projects/{$pid}/users/{$id}", [ + 'project_role_id' => Role::expertId(), + ]) + ->assertStatus(200); - $this->putJson("/api/v1/projects/{$pid}/users/{$id}", [ - 'project_role_id' => Role::adminId(), - ])->assertStatus(422); + $this + ->putJson("/api/v1/projects/{$pid}/users/{$id}", [ + 'project_role_id' => Role::adminId(), + ]) + ->assertStatus(422); } public function testAttach() @@ -147,21 +154,27 @@ public function testAttachGlobalGuest() $id = $this->globalGuest()->id; $this->beAdmin(); - $this->postJson("/api/v1/projects/{$pid}/users/{$id}", [ - 'project_role_id' => Role::editorId(), - ])->assertStatus(200); + $this + ->postJson("/api/v1/projects/{$pid}/users/{$id}", [ + 'project_role_id' => Role::editorId(), + ]) + ->assertStatus(200); $this->project()->removeUserId($id); - $this->postJson("/api/v1/projects/{$pid}/users/{$id}", [ - 'project_role_id' => Role::expertId(), - ])->assertStatus(200); + $this + ->postJson("/api/v1/projects/{$pid}/users/{$id}", [ + 'project_role_id' => Role::expertId(), + ]) + ->assertStatus(200); $this->project()->removeUserId($id); - $this->postJson("/api/v1/projects/{$pid}/users/{$id}", [ - 'project_role_id' => Role::adminId(), - ])->assertStatus(422); + $this + ->postJson("/api/v1/projects/{$pid}/users/{$id}", [ + 'project_role_id' => Role::adminId(), + ]) + ->assertStatus(422); } public function testDestroy() diff --git a/tests/php/Http/Controllers/Api/ProjectVolumeControllerTest.php b/tests/php/Http/Controllers/Api/ProjectVolumeControllerTest.php index 4110829c7..3881dcfd3 100644 --- a/tests/php/Http/Controllers/Api/ProjectVolumeControllerTest.php +++ b/tests/php/Http/Controllers/Api/ProjectVolumeControllerTest.php @@ -3,19 +3,15 @@ namespace Biigle\Tests\Http\Controllers\Api; use ApiTestCase; -use Biigle\Events\ImagesDeleted; use Biigle\Image; use Biigle\Jobs\CreateNewImagesOrVideos; use Biigle\Jobs\DeleteVolume; -use Biigle\MediaType; use Biigle\Role; -use Biigle\Tests\ImageTest; use Biigle\Tests\ProjectTest; use Biigle\Tests\VolumeTest; use Biigle\Video; use Biigle\Volume; use Cache; -use Event; use Exception; use FileCache; use Illuminate\Http\UploadedFile; @@ -140,7 +136,8 @@ public function testStoreImages() $response->assertStatus(422); // Image filename too long. - $this->json('POST', "/api/v1/projects/{$id}/volumes", [ + $this + ->json('POST', "/api/v1/projects/{$id}/volumes", [ 'name' => 'my volume no. 1', 'url' => 'test://images', 'media_type' => 'image', @@ -176,49 +173,59 @@ public function testStoreHandle() $id = $this->project()->id; $this->beAdmin(); - $this->json('POST', "/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => '1.jpg', - 'handle' => 'https://doi.org/10.3389/fmars.2017.00083', - ])->assertStatus(422); + $this + ->json('POST', "/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => '1.jpg', + 'handle' => 'https://doi.org/10.3389/fmars.2017.00083', + ]) + ->assertStatus(422); - $this->json('POST', "/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => '1.jpg', - 'handle' => '10.3389/fmars.2017.00083', - ])->assertStatus(201); + $this + ->json('POST', "/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => '1.jpg', + 'handle' => '10.3389/fmars.2017.00083', + ]) + ->assertStatus(201); $volume = Volume::orderBy('id', 'desc')->first(); $this->assertEquals('10.3389/fmars.2017.00083', $volume->handle); // Some DOIs can contain multiple slashes. - $this->json('POST', "/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => '1.jpg', - 'handle' => '10.3389/fmars.2017/00083', - ])->assertStatus(201); + $this + ->json('POST', "/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => '1.jpg', + 'handle' => '10.3389/fmars.2017/00083', + ]) + ->assertStatus(201); // Backwards compatibility. - $this->json('POST', "/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => '1.jpg', - 'doi' => '10.3389/fmars.2017.00083', - ])->assertStatus(201); + $this + ->json('POST', "/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => '1.jpg', + 'doi' => '10.3389/fmars.2017.00083', + ]) + ->assertStatus(201); - $this->json('POST', "/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => '1.jpg', - 'handle' => '', - ])->assertStatus(201); + $this + ->json('POST', "/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => '1.jpg', + 'handle' => '', + ]) + ->assertStatus(201); $volume = Volume::orderBy('id', 'desc')->first(); $this->assertNull($volume->handle); } @@ -231,7 +238,8 @@ public function testStoreFilesArray() $id = $this->project()->id; $this->beAdmin(); - $this->postJson("/api/v1/projects/{$id}/volumes", [ + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ 'name' => 'my volume no. 1', 'url' => 'test://images', 'media_type' => 'image', @@ -247,7 +255,8 @@ public function testStoreFilesExist() Storage::disk('test')->makeDirectory('images'); Storage::disk('test')->put('images/1.jpg', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ 'name' => 'my volume no. 1', 'url' => 'test://images', 'media_type' => 'image', @@ -257,7 +266,8 @@ public function testStoreFilesExist() Storage::disk('test')->put('images/2.jpg', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ 'name' => 'my volume no. 1', 'url' => 'test://images', 'media_type' => 'image', @@ -272,7 +282,8 @@ public function testStoreDeprecatedImagesAttribute() $this->beAdmin(); Storage::disk('test')->makeDirectory('images'); Storage::disk('test')->put('images/1.jpg', 'abc'); - $this->json('POST', "/api/v1/projects/{$id}/volumes", [ + $this + ->json('POST', "/api/v1/projects/{$id}/volumes", [ 'name' => 'my volume no. 1', 'url' => 'test://images', 'media_type' => 'image', @@ -287,7 +298,8 @@ public function testStoreNoMediaTypeAttribute() $this->beAdmin(); Storage::disk('test')->makeDirectory('images'); Storage::disk('test')->put('images/1.jpg', 'abc'); - $this->json('POST', "/api/v1/projects/{$id}/volumes", [ + $this + ->json('POST', "/api/v1/projects/{$id}/volumes", [ 'name' => 'my volume no. 1', 'url' => 'test://images', 'files' => '1.jpg', @@ -303,7 +315,8 @@ public function testStoreUnableToParseUri() $id = $this->project()->id; $this->beAdmin(); - $this->postJson("/api/v1/projects/{$id}/volumes", [ + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ 'name' => 'my volume no. 1', 'url' => 'https:///my/images', 'media_type' => 'image', @@ -321,7 +334,8 @@ public function testStoreFilesExistException() FileCache::shouldReceive('exists') ->andThrow(new Exception('Invalid MIME type.')); - $response = $this->postJson("/api/v1/projects/{$id}/volumes", [ + $response = $this + ->postJson("/api/v1/projects/{$id}/volumes", [ 'name' => 'my volume no. 1', 'url' => 'test://images', 'media_type' => 'image', @@ -388,7 +402,8 @@ public function testStoreVideos() $response->assertStatus(422); // Video filename too long. - $this->json('POST', "/api/v1/projects/{$id}/volumes", [ + $this + ->json('POST', "/api/v1/projects/{$id}/volumes", [ 'name' => 'my volume no. 1', 'url' => 'test://videos', 'media_type' => 'video', @@ -421,17 +436,17 @@ public function testStoreEmptyImageMetadataText() Storage::disk('test')->makeDirectory('images'); Storage::disk('test')->put('images/1.jpg', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => '1.jpg', - 'metadata_text' => "", - ])->assertSuccessful(); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => '1.jpg', + 'metadata_text' => "", + ]) + ->assertSuccessful(); - Queue::assertPushed(CreateNewImagesOrVideos::class, function ($job) { - return empty($job->metadata); - }); + Queue::assertPushed(CreateNewImagesOrVideos::class, fn ($job) => empty($job->metadata)); } public function testStoreImageMetadataText() @@ -441,17 +456,17 @@ public function testStoreImageMetadataText() Storage::disk('test')->makeDirectory('images'); Storage::disk('test')->put('images/1.jpg', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => '1.jpg', - 'metadata_text' => "filename,area\n1.jpg,2.5", - ])->assertSuccessful(); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => '1.jpg', + 'metadata_text' => "filename,area\n1.jpg,2.5", + ]) + ->assertSuccessful(); - Queue::assertPushed(CreateNewImagesOrVideos::class, function ($job) { - return $job->metadata[1][0] === '1.jpg' && $job->metadata[1][1] === '2.5'; - }); + Queue::assertPushed(CreateNewImagesOrVideos::class, fn ($job) => $job->metadata[1][0] === '1.jpg' && $job->metadata[1][1] === '2.5'); } public function testStoreImageMetadataCsv() @@ -463,17 +478,17 @@ public function testStoreImageMetadataCsv() Storage::disk('test')->makeDirectory('images'); Storage::disk('test')->put('images/abc.jpg', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => 'abc.jpg', - 'metadata_csv' => $file, - ])->assertSuccessful(); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => 'abc.jpg', + 'metadata_csv' => $file, + ]) + ->assertSuccessful(); - Queue::assertPushed(CreateNewImagesOrVideos::class, function ($job) { - return $job->metadata[1][0] === 'abc.jpg' && $job->metadata[1][6] === '2.6'; - }); + Queue::assertPushed(CreateNewImagesOrVideos::class, fn ($job) => $job->metadata[1][0] === 'abc.jpg' && $job->metadata[1][6] === '2.6'); } public function testStoreImageMetadataInvalid() @@ -483,13 +498,15 @@ public function testStoreImageMetadataInvalid() Storage::disk('test')->makeDirectory('images'); Storage::disk('test')->put('images/1.jpg', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => '1.jpg', - 'metadata_text' => "filename,area\nabc.jpg,2.5", - ])->assertStatus(422); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => '1.jpg', + 'metadata_text' => "filename,area\nabc.jpg,2.5", + ]) + ->assertStatus(422); } public function testStoreEmptyVideoMetadataText() @@ -499,17 +516,17 @@ public function testStoreEmptyVideoMetadataText() Storage::disk('test')->makeDirectory('videos'); Storage::disk('test')->put('videos/1.mp4', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://videos', - 'media_type' => 'video', - 'files' => '1.mp4', - 'metadata_text' => "", - ])->assertSuccessful(); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://videos', + 'media_type' => 'video', + 'files' => '1.mp4', + 'metadata_text' => "", + ]) + ->assertSuccessful(); - Queue::assertPushed(CreateNewImagesOrVideos::class, function ($job) { - return empty($job->metadata); - }); + Queue::assertPushed(CreateNewImagesOrVideos::class, fn ($job) => empty($job->metadata)); } public function testStoreVideoMetadataText() @@ -519,17 +536,17 @@ public function testStoreVideoMetadataText() Storage::disk('test')->makeDirectory('videos'); Storage::disk('test')->put('videos/1.mp4', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://videos', - 'media_type' => 'video', - 'files' => '1.mp4', - 'metadata_text' => "filename,area\n1.mp4,2.5", - ])->assertSuccessful(); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://videos', + 'media_type' => 'video', + 'files' => '1.mp4', + 'metadata_text' => "filename,area\n1.mp4,2.5", + ]) + ->assertSuccessful(); - Queue::assertPushed(CreateNewImagesOrVideos::class, function ($job) { - return $job->metadata[1][0] === '1.mp4' && $job->metadata[1][1] === '2.5'; - }); + Queue::assertPushed(CreateNewImagesOrVideos::class, fn ($job) => $job->metadata[1][0] === '1.mp4' && $job->metadata[1][1] === '2.5'); } public function testStoreVideoMetadataCsv() @@ -541,17 +558,17 @@ public function testStoreVideoMetadataCsv() Storage::disk('test')->makeDirectory('videos'); Storage::disk('test')->put('videos/abc.mp4', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://videos', - 'media_type' => 'video', - 'files' => 'abc.mp4', - 'metadata_csv' => $file, - ])->assertSuccessful(); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://videos', + 'media_type' => 'video', + 'files' => 'abc.mp4', + 'metadata_csv' => $file, + ]) + ->assertSuccessful(); - Queue::assertPushed(CreateNewImagesOrVideos::class, function ($job) { - return $job->metadata[1][0] === 'abc.mp4' && $job->metadata[1][6] === '2.6' && $job->metadata[2][6] === '1.6'; - }); + Queue::assertPushed(CreateNewImagesOrVideos::class, fn ($job) => $job->metadata[1][0] === 'abc.mp4' && $job->metadata[1][6] === '2.6' && $job->metadata[2][6] === '1.6'); } public function testStoreVideoMetadataInvalid() @@ -561,13 +578,15 @@ public function testStoreVideoMetadataInvalid() Storage::disk('test')->makeDirectory('videos'); Storage::disk('test')->put('videos/1.mp4', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://videos', - 'media_type' => 'video', - 'files' => '1.mp4', - 'metadata_text' => "filename,area\nabc.mp4,2.5", - ])->assertStatus(422); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://videos', + 'media_type' => 'video', + 'files' => '1.mp4', + 'metadata_text' => "filename,area\nabc.mp4,2.5", + ]) + ->assertStatus(422); } public function testStoreImageIfdoFile() @@ -581,13 +600,15 @@ public function testStoreImageIfdoFile() Storage::fake('ifdos'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => 'abc.jpg', - 'ifdo_file' => $file, - ])->assertSuccessful(); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => 'abc.jpg', + 'ifdo_file' => $file, + ]) + ->assertSuccessful(); $volume = Volume::orderBy('id', 'desc')->first(); $this->assertTrue($volume->hasIfdo()); @@ -604,13 +625,15 @@ public function testStoreVideoIfdoFile() Storage::fake('ifdos'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://videos', - 'media_type' => 'video', - 'files' => 'abc.mp4', - 'ifdo_file' => $file, - ])->assertSuccessful(); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://videos', + 'media_type' => 'video', + 'files' => 'abc.mp4', + 'ifdo_file' => $file, + ]) + ->assertSuccessful(); $volume = Volume::orderBy('id', 'desc')->first(); $this->assertTrue($volume->hasIfdo()); @@ -625,13 +648,15 @@ public function testStoreVideoVolumeWithImageIfdoFile() Storage::disk('test')->makeDirectory('videos'); Storage::disk('test')->put('videos/abc.mp4', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://videos', - 'media_type' => 'video', - 'files' => 'abc.mp4', - 'ifdo_file' => $file, - ])->assertStatus(422); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://videos', + 'media_type' => 'video', + 'files' => 'abc.mp4', + 'ifdo_file' => $file, + ]) + ->assertStatus(422); } public function testStoreImageVolumeWithVideoIfdoFile() @@ -643,20 +668,23 @@ public function testStoreImageVolumeWithVideoIfdoFile() Storage::disk('test')->makeDirectory('images'); Storage::disk('test')->put('images/abc.jpg', 'abc'); - $this->postJson("/api/v1/projects/{$id}/volumes", [ - 'name' => 'my volume no. 1', - 'url' => 'test://images', - 'media_type' => 'image', - 'files' => 'abc.jpg', - 'ifdo_file' => $file, - ])->assertStatus(422); + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ + 'name' => 'my volume no. 1', + 'url' => 'test://images', + 'media_type' => 'image', + 'files' => 'abc.jpg', + 'ifdo_file' => $file, + ]) + ->assertStatus(422); } public function testStoreProviderDenylist() { $id = $this->project()->id; $this->beAdmin(); - $this->postJson("/api/v1/projects/{$id}/volumes", [ + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ 'name' => 'my volume no. 1', 'url' => 'https://dropbox.com', 'media_type' => 'image', @@ -678,7 +706,8 @@ public function testStoreAuthorizeDisk() $id = $this->project()->id; $this->beAdmin(); - $this->postJson("/api/v1/projects/{$id}/volumes", [ + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ 'name' => 'name', 'url' => 'admin-test://images', 'media_type' => 'image', @@ -686,7 +715,8 @@ public function testStoreAuthorizeDisk() ]) ->assertStatus(422); - $this->postJson("/api/v1/projects/{$id}/volumes", [ + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ 'name' => 'name', 'url' => 'editor-test://images', 'media_type' => 'image', @@ -695,7 +725,8 @@ public function testStoreAuthorizeDisk() ->assertSuccessful(); $this->beGlobalAdmin(); - $this->postJson("/api/v1/projects/{$id}/volumes", [ + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ 'name' => 'name', 'url' => 'admin-test://images', 'media_type' => 'image', @@ -703,7 +734,8 @@ public function testStoreAuthorizeDisk() ]) ->assertSuccessful(); - $this->postJson("/api/v1/projects/{$id}/volumes", [ + $this + ->postJson("/api/v1/projects/{$id}/volumes", [ 'name' => 'name', 'url' => 'editor-test://images', 'media_type' => 'image', @@ -741,7 +773,9 @@ public function testAttachDuplicate() $pid = $this->project()->id; $this->beAdmin(); - $this->json('POST', "/api/v1/projects/{$pid}/volumes/{$tid}")->assertStatus(200); + $this + ->json('POST', "/api/v1/projects/{$pid}/volumes/{$tid}") + ->assertStatus(200); } public function testDestroy() @@ -779,9 +813,7 @@ public function testDestroy() ]); // deleting with force succeeds $response->assertStatus(200); - Queue::assertPushed(DeleteVolume::class, function ($job) use ($id) { - return $id === $job->volume->id; - }); + Queue::assertPushed(DeleteVolume::class, fn ($job) => $id === $job->volume->id); $this->assertFalse($this->project()->volumes()->exists()); } } diff --git a/tests/php/Http/Controllers/Api/SplitVideoAnnotationControllerTest.php b/tests/php/Http/Controllers/Api/SplitVideoAnnotationControllerTest.php index 5dbef2007..401a73c9b 100644 --- a/tests/php/Http/Controllers/Api/SplitVideoAnnotationControllerTest.php +++ b/tests/php/Http/Controllers/Api/SplitVideoAnnotationControllerTest.php @@ -34,31 +34,37 @@ public function testStore() $this->doTestApiRoute('POST', "api/v1/video-annotations/{$annotation->id}/split"); $this->beUser(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split") + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split") ->assertStatus(403); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 0.5, ]) ->assertStatus(422); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.0, ]) ->assertStatus(422); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 2.0, ]) ->assertStatus(422); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 2.5, ]) ->assertStatus(422); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.5, ]) ->assertStatus(200); @@ -81,7 +87,8 @@ public function testStorePoint() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.5, ]) ->assertStatus(200) @@ -108,7 +115,8 @@ public function testStoreRectangle() $expect = [5, 0, 15, 0, 15, 10, 5, 10]; $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.5, ]) ->assertStatus(200) @@ -128,7 +136,8 @@ public function testStoreCircle() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.5, ]) ->assertStatus(200) @@ -148,7 +157,8 @@ public function testStoreLineString() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.5, ]) // Line strings cannot be split because the interpolation is not implemented. @@ -165,7 +175,8 @@ public function testStorePolygon() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.5, ]) // Polygons cannot be split because the interpolation is not implemented. @@ -182,7 +193,8 @@ public function testStoreWholeFrame() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.5, ]) ->assertStatus(200) @@ -201,7 +213,8 @@ public function testStorePointAtGap() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.5, ]) ->assertStatus(200) @@ -221,7 +234,8 @@ public function testStorePointAtFrame() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.5, ]) ->assertStatus(200) @@ -241,7 +255,8 @@ public function testStoreWholeFrameAtFrame() ]); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$annotation->id}/split", [ + $this + ->postJson("api/v1/video-annotations/{$annotation->id}/split", [ 'time' => 1.5, ]) ->assertStatus(200) diff --git a/tests/php/Http/Controllers/Api/UserControllerTest.php b/tests/php/Http/Controllers/Api/UserControllerTest.php index 194447504..70d10267b 100644 --- a/tests/php/Http/Controllers/Api/UserControllerTest.php +++ b/tests/php/Http/Controllers/Api/UserControllerTest.php @@ -278,23 +278,27 @@ public function testUpdateRole() $this->globalAdmin()->password = '$2y$10$O/OuPUHuswXD.6LRVUeHueY5hbiFkHVFaPLcdOd.sp3U9C8H9dcJS'; $this->globalAdmin()->save(); $this->beGlobalAdmin(); - $this->putJson("api/v1/users/{$user->id}", [ + $this + ->putJson("api/v1/users/{$user->id}", [ 'role_id' => Role::guestId(), 'auth_password' => 'adminpassword', ]) ->assertStatus(200); - $this->putJson("api/v1/users/{$user->id}", [ + $this + ->putJson("api/v1/users/{$user->id}", [ 'role_id' => Role::editorId(), 'auth_password' => 'adminpassword', ]) ->assertStatus(200); $this->assertEquals(Role::editorId(), $user->fresh()->role_id); - $this->putJson("api/v1/users/{$user->id}", [ + $this + ->putJson("api/v1/users/{$user->id}", [ 'role_id' => Role::expertId(), 'auth_password' => 'adminpassword', ]) ->assertStatus(422); - $this->putJson("api/v1/users/{$user->id}", [ + $this + ->putJson("api/v1/users/{$user->id}", [ 'role_id' => Role::adminId(), 'auth_password' => 'adminpassword', ]) @@ -310,7 +314,8 @@ public function testUpdateCanReview() $this->beGlobalAdmin(); $user = $this->guest(); - $this->putJson("api/v1/users/{$user->id}", [ + $this + ->putJson("api/v1/users/{$user->id}", [ 'can_review' => '1', 'auth_password' => 'adminpassword', ]) @@ -320,14 +325,16 @@ public function testUpdateCanReview() $user = $this->user(); $this->assertFalse($user->canReview); - $this->putJson("api/v1/users/{$user->id}", [ + $this + ->putJson("api/v1/users/{$user->id}", [ 'can_review' => '1', 'auth_password' => 'adminpassword', ]) ->assertStatus(200); $this->assertTrue($user->fresh()->canReview); - $this->putJson("api/v1/users/{$user->id}", [ + $this + ->putJson("api/v1/users/{$user->id}", [ 'can_review' => '0', 'auth_password' => 'adminpassword', ]) @@ -346,13 +353,15 @@ public function testDowngradeRoleWithCanReview() $user->save(); // This sets canReview to false, too. - $this->putJson("api/v1/users/{$user->id}", [ + $this + ->putJson("api/v1/users/{$user->id}", [ 'role_id' => Role::guestId(), 'auth_password' => 'adminpassword', ]) ->assertStatus(200); - $this->putJson("api/v1/users/{$user->id}", [ + $this + ->putJson("api/v1/users/{$user->id}", [ 'role_id' => Role::editorId(), 'auth_password' => 'adminpassword', ]) diff --git a/tests/php/Http/Controllers/Api/UserPinnedProjectControllerTest.php b/tests/php/Http/Controllers/Api/UserPinnedProjectControllerTest.php index c6981c861..ec5cc1645 100644 --- a/tests/php/Http/Controllers/Api/UserPinnedProjectControllerTest.php +++ b/tests/php/Http/Controllers/Api/UserPinnedProjectControllerTest.php @@ -4,7 +4,6 @@ use ApiTestCase; use Biigle\Project; -use Biigle\Role; use Biigle\Tests\ProjectTest; class UserPinnedProjectControllerTest extends ApiTestCase diff --git a/tests/php/Http/Controllers/Api/VideoAnnotationControllerTest.php b/tests/php/Http/Controllers/Api/VideoAnnotationControllerTest.php index 6ac403105..5fecf71da 100644 --- a/tests/php/Http/Controllers/Api/VideoAnnotationControllerTest.php +++ b/tests/php/Http/Controllers/Api/VideoAnnotationControllerTest.php @@ -49,11 +49,13 @@ public function testIndex() $this->doTestApiRoute('GET', "/api/v1/videos/{$this->video->id}/annotations"); $this->beUser(); - $this->getJson("/api/v1/videos/{$this->video->id}/annotations") + $this + ->getJson("/api/v1/videos/{$this->video->id}/annotations") ->assertStatus(403); $this->beGuest(); - $this->getJson("/api/v1/videos/{$this->video->id}/annotations") + $this + ->getJson("/api/v1/videos/{$this->video->id}/annotations") ->assertStatus(200) ->assertJsonFragment(['frames' => [1.0]]) ->assertJsonFragment(['points' => [[10, 20]]]) @@ -94,7 +96,8 @@ public function testIndexAnnotationSessionHideOwn() ]); $this->beEditor(); - $this->get("/api/v1/videos/{$this->video->id}/annotations") + $this + ->get("/api/v1/videos/{$this->video->id}/annotations") ->assertStatus(200) ->assertJsonFragment(['points' => [[10, 20]]]) ->assertJsonFragment(['points' => [[20, 30]]]); @@ -102,7 +105,8 @@ public function testIndexAnnotationSessionHideOwn() $session->users()->attach($this->editor()); Cache::flush(); - $this->get("/api/v1/videos/{$this->video->id}/annotations") + $this + ->get("/api/v1/videos/{$this->video->id}/annotations") ->assertStatus(200) ->assertJsonMissing(['points' => [[10, 20]]]) ->assertJsonFragment(['points' => [[20, 30]]]); @@ -130,11 +134,13 @@ public function testShow() $this->doTestApiRoute('GET', "/api/v1/video-annotations/{$annotation->id}"); $this->beUser(); - $this->getJson("/api/v1/video-annotations/{$annotation->id}") + $this + ->getJson("/api/v1/video-annotations/{$annotation->id}") ->assertStatus(403); $this->beGuest(); - $this->getJson("/api/v1/video-annotations/{$annotation->id}") + $this + ->getJson("/api/v1/video-annotations/{$annotation->id}") ->assertStatus(200) ->assertJsonFragment(['frames' => [1.0]]) ->assertJsonFragment(['points' => [[10, 20]]]) @@ -142,7 +148,6 @@ public function testShow() ->assertJsonFragment(['name' => 'My label']); } - public function showAnnotationSession() { $annotation = VideoAnnotationTest::create([ @@ -161,13 +166,15 @@ public function showAnnotationSession() ]); $this->beAdmin(); - $this->get("/api/v1/video-annotations/{$this->annotation->id}") + $this + ->get("/api/v1/video-annotations/{$this->annotation->id}") ->assertStatus(200); $session->users()->attach($this->admin()); Cache::flush(); - $this->get("/api/v1/video-annotations/{$this->annotation->id}") + $this + ->get("/api/v1/video-annotations/{$this->annotation->id}") ->assertStatus(403); } @@ -181,11 +188,13 @@ public function testStore() $this->beEditor(); // missing arguments - $this->postJson("/api/v1/videos/{$this->video->id}/annotations") + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations") ->assertStatus(422); // shape does not exist - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => 99999, 'label_id' => $label->id, 'points' => [], @@ -194,7 +203,8 @@ public function testStore() ->assertStatus(422); // points is required - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::lineId(), 'label_id' => $label->id, 'frames' => [], @@ -202,7 +212,8 @@ public function testStore() ->assertStatus(422); // frames is required - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::lineId(), 'label_id' => $label->id, 'points' => [], @@ -210,7 +221,8 @@ public function testStore() ->assertStatus(422); // at least one point required - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $label->id, 'points' => [], @@ -219,7 +231,8 @@ public function testStore() ->assertStatus(422); // number of points and frames does not match - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $label->id, 'points' => [[0, 0]], @@ -228,7 +241,8 @@ public function testStore() ->assertStatus(422); // label does not belong to a label tree of the project of the video - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $label->id, 'points' => [[0, 0]], @@ -240,7 +254,8 @@ public function testStore() // policies are cached Cache::flush(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $label->id, 'points' => [[10, 11]], @@ -262,7 +277,8 @@ public function testStore() public function testStoreValidatePoints() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11, 12, 13]], @@ -274,7 +290,8 @@ public function testStoreValidatePoints() public function testStoreValidatePointsArray() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [null], @@ -286,7 +303,8 @@ public function testStoreValidatePointsArray() public function testStoreValidateFrames() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11]], @@ -298,7 +316,8 @@ public function testStoreValidateFrames() public function testStoreAndTrackPoint() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11]], @@ -308,7 +327,8 @@ public function testStoreAndTrackPoint() // Not a single frame annotation. ->assertStatus(422); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11], [20, 21]], @@ -318,7 +338,8 @@ public function testStoreAndTrackPoint() // Still not a single frame annotation. ->assertStatus(422); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11]], @@ -329,7 +350,8 @@ public function testStoreAndTrackPoint() ->assertStatus(422); Queue::fake(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11]], @@ -343,7 +365,8 @@ public function testStoreAndTrackPoint() public function testStoreAndTrackRectangle() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::rectangleId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11, 12, 13]], @@ -357,7 +380,8 @@ public function testStoreAndTrackRectangle() public function testStoreAndTrackCircle() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::circleId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11, 12]], @@ -370,7 +394,8 @@ public function testStoreAndTrackCircle() public function testStoreAndTrackLineString() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::lineId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11, 12, 13]], @@ -384,7 +409,8 @@ public function testStoreAndTrackLineString() public function testStoreAndTrackPolygon() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::polygonId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11, 12, 13, 14, 15]], @@ -400,7 +426,8 @@ public function testStoreAndTrackPointOutsideBoundary() config(['videos.tracking_point_padding' => 10]); $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[0, 0]], @@ -413,7 +440,8 @@ public function testStoreAndTrackPointOutsideBoundary() $this->video->height = 100; $this->video->save(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[0, 0]], @@ -422,7 +450,8 @@ public function testStoreAndTrackPointOutsideBoundary() ]) ->assertStatus(422); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[100, 100]], @@ -431,7 +460,8 @@ public function testStoreAndTrackPointOutsideBoundary() ]) ->assertStatus(422); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[90, 90]], @@ -444,7 +474,8 @@ public function testStoreAndTrackPointOutsideBoundary() public function testStoreAndTrackCircleOutsideBoundary() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::circleId(), 'label_id' => $this->labelRoot()->id, 'points' => [[0, 0, 10]], @@ -457,7 +488,8 @@ public function testStoreAndTrackCircleOutsideBoundary() $this->video->height = 100; $this->video->save(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::circleId(), 'label_id' => $this->labelRoot()->id, 'points' => [[0, 0, 10]], @@ -466,7 +498,8 @@ public function testStoreAndTrackCircleOutsideBoundary() ]) ->assertStatus(422); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::circleId(), 'label_id' => $this->labelRoot()->id, 'points' => [[100, 100, 10]], @@ -475,7 +508,8 @@ public function testStoreAndTrackCircleOutsideBoundary() ]) ->assertStatus(422); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::circleId(), 'label_id' => $this->labelRoot()->id, 'points' => [[90, 90, 10]], @@ -489,7 +523,8 @@ public function testStoreAndTrackIncrementRateLimit() { Queue::fake(); $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11]], @@ -506,7 +541,8 @@ public function testStoreAndTrackRestrictRateLimit() config(['videos.track_object_max_jobs_per_user' => 3]); Cache::put(TrackObject::getRateLimitCacheKey($this->editor()), 3); $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::pointId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11]], @@ -520,7 +556,8 @@ public function testStoreAndTrackRestrictRateLimit() public function testStoreWholeFrameAnnotation() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::wholeFrameId(), 'label_id' => $this->labelRoot()->id, 'points' => [[0, 0], [1, 1]], @@ -529,7 +566,8 @@ public function testStoreWholeFrameAnnotation() // Points must be empty. ->assertStatus(422); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::wholeFrameId(), 'label_id' => $this->labelRoot()->id, 'points' => [], @@ -538,7 +576,8 @@ public function testStoreWholeFrameAnnotation() // No more than two frames for a new whole frame annotation. ->assertStatus(422); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::wholeFrameId(), 'label_id' => $this->labelRoot()->id, 'frames' => [0.0, 1.5], @@ -555,7 +594,8 @@ public function testStoreWholeFrameAnnotation() public function testStoreWholeFrameSingleFrameAnnotation() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::wholeFrameId(), 'label_id' => $this->labelRoot()->id, 'frames' => [0.0], @@ -572,7 +612,8 @@ public function testStoreWholeFrameSingleFrameAnnotation() public function testStoreAndTrackWholeFrameAnnotation() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::wholeFrameId(), 'label_id' => $this->labelRoot()->id, 'points' => [[10, 11, 12, 13, 14, 15]], @@ -586,21 +627,24 @@ public function testStoreAndTrackWholeFrameAnnotation() public function testStoreInvalidKeyFrames() { $this->beEditor(); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::wholeFrameId(), 'label_id' => $this->labelRoot()->id, 'frames' => [-1, 1.5], ]) ->assertStatus(422); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::wholeFrameId(), 'label_id' => $this->labelRoot()->id, 'frames' => [0, 2.5], ]) ->assertStatus(422); - $this->postJson("/api/v1/videos/{$this->video->id}/annotations", [ + $this + ->postJson("/api/v1/videos/{$this->video->id}/annotations", [ 'shape_id' => Shape::wholeFrameId(), 'label_id' => $this->labelRoot()->id, 'frames' => [0, 2.0], @@ -619,10 +663,12 @@ public function testUpdate() $this->doTestApiRoute('PUT', "api/v1/video-annotations/{$annotation->id}"); $this->beUser(); - $this->putJson("api/v1/video-annotations/{$annotation->id}")->assertStatus(403); + $this + ->putJson("api/v1/video-annotations/{$annotation->id}")->assertStatus(403); $this->beAdmin(); - $this->putJson("api/v1/video-annotations/{$annotation->id}", [ + $this + ->putJson("api/v1/video-annotations/{$annotation->id}", [ 'points' => [[10, 20], [30, 40]], 'frames' => [1.0, 10.0] ]) @@ -644,7 +690,8 @@ public function testUpdateValidatePoints() $this->beAdmin(); // invalid number of points - $this->putJson("api/v1/video-annotations/{$annotation->id}", [ + $this + ->putJson("api/v1/video-annotations/{$annotation->id}", [ 'points' => [[10, 15, 20]], ]) ->assertStatus(422); @@ -660,7 +707,8 @@ public function testUpdateWholeFrameAnnotation() ]); $this->beAdmin(); - $this->putJson("api/v1/video-annotations/{$annotation->id}", [ + $this + ->putJson("api/v1/video-annotations/{$annotation->id}", [ 'frames' => [1.0, 2.0, null, 3.0, 4.0], ]) ->assertStatus(200); diff --git a/tests/php/Http/Controllers/Api/VideoAnnotationLabelControllerTest.php b/tests/php/Http/Controllers/Api/VideoAnnotationLabelControllerTest.php index c5cdbf1ae..055e8f1b9 100644 --- a/tests/php/Http/Controllers/Api/VideoAnnotationLabelControllerTest.php +++ b/tests/php/Http/Controllers/Api/VideoAnnotationLabelControllerTest.php @@ -26,19 +26,22 @@ public function testStore() $this->doTestApiRoute('POST', "api/v1/video-annotations/{$id}/labels"); $this->beUser(); - $this->postJson("api/v1/video-annotations/{$id}/labels", [ + $this + ->postJson("api/v1/video-annotations/{$id}/labels", [ 'label_id' => $this->labelRoot()->id, ]) ->assertStatus(403); $this->beEditor(); - $this->postJson("api/v1/video-annotations/{$id}/labels", [ + $this + ->postJson("api/v1/video-annotations/{$id}/labels", [ 'label_id' => LabelTest::create()->id, ]) // Label ID belong to the projects of the video. ->assertStatus(403); - $this->postJson("api/v1/video-annotations/{$id}/labels", [ + $this + ->postJson("api/v1/video-annotations/{$id}/labels", [ 'label_id' => $this->labelRoot()->id, ]) ->assertSuccessful() @@ -49,7 +52,8 @@ public function testStore() $this->assertEquals($this->labelRoot()->id, $label->label_id); $this->assertEquals($this->editor()->id, $label->user_id); - $this->postJson("api/v1/video-annotations/{$id}/labels", [ + $this + ->postJson("api/v1/video-annotations/{$id}/labels", [ 'label_id' => $this->labelRoot()->id, ]) // Label is already attached. @@ -75,24 +79,29 @@ public function testDestroy() $this->doTestApiRoute('DELETE', "api/v1/video-annotation-labels/{$annotationLabel1->id}"); $this->beUser(); - $this->deleteJson("api/v1/video-annotation-labels/{$annotationLabel1->id}") + $this + ->deleteJson("api/v1/video-annotation-labels/{$annotationLabel1->id}") ->assertStatus(403); $this->beEditor(); - $this->deleteJson("api/v1/video-annotation-labels/{$annotationLabel1->id}") + $this + ->deleteJson("api/v1/video-annotation-labels/{$annotationLabel1->id}") // Cannot detach label of other user. ->assertStatus(403); - $this->deleteJson("api/v1/video-annotation-labels/{$annotationLabel3->id}") + $this + ->deleteJson("api/v1/video-annotation-labels/{$annotationLabel3->id}") ->assertStatus(200); $this->assertNull($annotationLabel3->fresh()); $this->beExpert(); - $this->deleteJson("api/v1/video-annotation-labels/{$annotationLabel2->id}") + $this + ->deleteJson("api/v1/video-annotation-labels/{$annotationLabel2->id}") ->assertStatus(200); $this->assertNull($annotationLabel2->fresh()); - $this->deleteJson("api/v1/video-annotation-labels/{$annotationLabel1->id}") + $this + ->deleteJson("api/v1/video-annotation-labels/{$annotationLabel1->id}") // Cannot detach the last label. ->assertStatus(422); } diff --git a/tests/php/Http/Controllers/Api/VideoControllerTest.php b/tests/php/Http/Controllers/Api/VideoControllerTest.php index d343bb64e..2a97747b3 100644 --- a/tests/php/Http/Controllers/Api/VideoControllerTest.php +++ b/tests/php/Http/Controllers/Api/VideoControllerTest.php @@ -3,13 +3,9 @@ namespace Biigle\Tests\Http\Controllers\Api; use ApiTestCase; -use Biigle\Jobs\ProcessNewVideo; use Biigle\Tests\VideoAnnotationTest; use Biigle\Tests\VideoTest; use Biigle\Video; -use Illuminate\Http\File; -use Queue; -use Storage; class VideoControllerTest extends ApiTestCase { diff --git a/tests/php/Http/Controllers/Api/VideoFileControllerTest.php b/tests/php/Http/Controllers/Api/VideoFileControllerTest.php index f1fc490fb..9a19c9576 100644 --- a/tests/php/Http/Controllers/Api/VideoFileControllerTest.php +++ b/tests/php/Http/Controllers/Api/VideoFileControllerTest.php @@ -5,7 +5,6 @@ use ApiTestCase; use Biigle\MediaType; use Biigle\Tests\VideoTest; -use Exception; use Mockery; use Storage; diff --git a/tests/php/Http/Controllers/Api/VideoLabelControllerTest.php b/tests/php/Http/Controllers/Api/VideoLabelControllerTest.php index 0c3892a94..f54265fb9 100644 --- a/tests/php/Http/Controllers/Api/VideoLabelControllerTest.php +++ b/tests/php/Http/Controllers/Api/VideoLabelControllerTest.php @@ -27,7 +27,8 @@ public function testIndex() $this->get("/api/v1/videos/{$id}/labels")->assertStatus(403); $this->beGuest(); - $this->get("/api/v1/videos/{$id}/labels") + $this + ->get("/api/v1/videos/{$id}/labels") ->assertStatus(200) ->assertJsonFragment([ 'id' => $il->label->id, @@ -49,34 +50,44 @@ public function testStore() // missing arguments $this->beEditor(); - $this->postJson("/api/v1/videos/{$id}/labels")->assertStatus(422); + $this + ->postJson("/api/v1/videos/{$id}/labels")->assertStatus(422); $this->assertEquals(0, $this->video->labels()->count()); $this->beUser(); - $this->post("/api/v1/videos/{$id}/labels", [ - 'label_id' => $this->labelRoot()->id, - ])->assertStatus(403); + $this + ->post("/api/v1/videos/{$id}/labels", [ + 'label_id' => $this->labelRoot()->id, + ]) + ->assertStatus(403); $this->beGuest(); - $this->post("/api/v1/videos/{$id}/labels", [ - 'label_id' => $this->labelRoot()->id, - ])->assertStatus(403); + $this + ->post("/api/v1/videos/{$id}/labels", [ + 'label_id' => $this->labelRoot()->id, + ]) + ->assertStatus(403); $this->beEditor(); - $this->post("/api/v1/videos/{$id}/labels", [ - 'label_id' => $this->labelRoot()->id, - ])->assertSuccessful(); + $this + ->post("/api/v1/videos/{$id}/labels", [ + 'label_id' => $this->labelRoot()->id, + ]) + ->assertSuccessful(); $this->assertEquals(1, $this->video->labels()->count()); $this->beAdmin(); // the same label cannot be attached twice - $this->post("/api/v1/videos/{$id}/labels", [ - 'label_id' => $this->labelRoot()->id, - ])->assertStatus(400); + $this + ->post("/api/v1/videos/{$id}/labels", [ + 'label_id' => $this->labelRoot()->id, + ]) + ->assertStatus(400); $this->assertEquals(1, $this->video->labels()->count()); - $this->postJson("/api/v1/videos/{$id}/labels", [ + $this + ->postJson("/api/v1/videos/{$id}/labels", [ 'label_id' => $this->labelChild()->id, ]) ->assertSuccessful() diff --git a/tests/php/Http/Controllers/Api/VolumeControllerTest.php b/tests/php/Http/Controllers/Api/VolumeControllerTest.php index 5cf82c934..e3c59b237 100644 --- a/tests/php/Http/Controllers/Api/VolumeControllerTest.php +++ b/tests/php/Http/Controllers/Api/VolumeControllerTest.php @@ -9,12 +9,11 @@ use Biigle\Role; use Biigle\Tests\ProjectTest; use Illuminate\Support\Facades\Cache; -use Queue; use Illuminate\Support\Facades\Storage; +use Queue; class VolumeControllerTest extends ApiTestCase { - public function testIndex() { $project = ProjectTest::create(); @@ -23,12 +22,14 @@ public function testIndex() $this->doTestApiRoute('GET', '/api/v1/volumes/'); $this->beUser(); - $this->get('/api/v1/volumes/') + $this + ->get('/api/v1/volumes/') ->assertStatus(200) ->assertExactJson([]); $this->beGuest(); - $this->get('/api/v1/volumes/') + $this + ->get('/api/v1/volumes/') ->assertStatus(200) ->assertJsonFragment(['id' => $this->volume()->id]) ->assertJsonFragment(['media_type_id' => $this->volume()->media_type_id]) @@ -43,7 +44,8 @@ public function testIndexGlobalAdmin() $project->addVolumeId($this->volume()->id); $this->beGlobalAdmin(); - $this->get('/api/v1/volumes/') + $this + ->get('/api/v1/volumes/') ->assertStatus(200) ->assertJsonFragment(['id' => $this->volume()->id]) ->assertJsonFragment(['media_type_id' => $this->volume()->media_type_id]) @@ -63,7 +65,8 @@ public function testShow() $response->assertStatus(403); $this->beGuest(); - $this->get("/api/v1/volumes/{$id}") + $this + ->get("/api/v1/volumes/{$id}") ->assertStatus(200) ->assertJsonFragment(['id' => $this->volume()->id]) ->assertJsonFragment(['media_type_id' => $this->volume()->media_type_id]) @@ -105,29 +108,39 @@ public function testUpdateHandle() $this->doTestApiRoute('PUT', "/api/v1/volumes/{$id}"); $this->beAdmin(); - $this->json('PUT', "/api/v1/volumes/{$id}", [ - 'handle' => 'https://doi.org/10.3389/fmars.2017.00083', - ])->assertStatus(422); - - $this->json('PUT', "/api/v1/volumes/{$id}", [ - 'handle' => '10.3389/fmars.2017.00083', - ])->assertStatus(200); + $this + ->json('PUT', "/api/v1/volumes/{$id}", [ + 'handle' => 'https://doi.org/10.3389/fmars.2017.00083', + ]) + ->assertStatus(422); + + $this + ->json('PUT', "/api/v1/volumes/{$id}", [ + 'handle' => '10.3389/fmars.2017.00083', + ]) + ->assertStatus(200); $this->volume()->refresh(); $this->assertEquals('10.3389/fmars.2017.00083', $this->volume()->handle); // Some DOIs can contain multiple slashes. - $this->json('PUT', "/api/v1/volumes/{$id}", [ - 'handle' => '10.3389/fmars.2017/00083', - ])->assertStatus(200); + $this + ->json('PUT', "/api/v1/volumes/{$id}", [ + 'handle' => '10.3389/fmars.2017/00083', + ]) + ->assertStatus(200); // Backwards compatibility. - $this->json('PUT', "/api/v1/volumes/{$id}", [ - 'doi' => '10.3389/fmars.2017.00083', - ])->assertStatus(200); + $this + ->json('PUT', "/api/v1/volumes/{$id}", [ + 'doi' => '10.3389/fmars.2017.00083', + ]) + ->assertStatus(200); - $this->json('PUT', "/api/v1/volumes/{$id}", [ - 'handle' => '', - ])->assertStatus(200); + $this + ->json('PUT', "/api/v1/volumes/{$id}", [ + 'handle' => '', + ]) + ->assertStatus(200); $this->volume()->refresh(); $this->assertNull($this->volume()->handle); } @@ -144,21 +157,31 @@ public function testUpdateUrl() $disk->put('volumes/file.txt', 'abc'); $this->beAdmin(); - $this->json('PUT', '/api/v1/volumes/'.$this->volume()->id, [ - 'url' => 'admin-test://volumes', - ])->assertStatus(422); - $this->json('PUT', '/api/v1/volumes/'.$this->volume()->id, [ - 'url' => 'editor-test://volumes', - ])->assertStatus(200); + + $this + ->json('PUT', '/api/v1/volumes/'.$this->volume()->id, [ + 'url' => 'admin-test://volumes', + ]) + ->assertStatus(422); + $this + ->json('PUT', '/api/v1/volumes/'.$this->volume()->id, [ + 'url' => 'editor-test://volumes', + ]) + ->assertStatus(200); + $this->assertEquals('editor-test://volumes', $this->volume()->fresh()->url); $this->beGlobalAdmin(); - $this->json('PUT', '/api/v1/volumes/'.$this->volume()->id, [ - 'url' => 'editor-test://volumes', - ])->assertStatus(422); - $this->json('PUT', '/api/v1/volumes/'.$this->volume()->id, [ - 'url' => 'admin-test://volumes', - ])->assertStatus(200); + $this + ->json('PUT', '/api/v1/volumes/'.$this->volume()->id, [ + 'url' => 'editor-test://volumes', + ]) + ->assertStatus(422); + $this + ->json('PUT', '/api/v1/volumes/'.$this->volume()->id, [ + 'url' => 'admin-test://volumes', + ]) + ->assertStatus(200); $this->assertEquals('admin-test://volumes', $this->volume()->fresh()->url); Queue::assertPushed(ProcessNewVolumeFiles::class); } @@ -166,9 +189,11 @@ public function testUpdateUrl() public function testUpdateUrlProviderDenylist() { $this->beAdmin(); - $this->json('PUT', '/api/v1/volumes/'.$this->volume()->id, [ - 'url' => 'https://dropbox.com', - ])->assertStatus(422); + $this + ->json('PUT', '/api/v1/volumes/'.$this->volume()->id, [ + 'url' => 'https://dropbox.com', + ]) + ->assertStatus(422); } public function testUpdateGlobalAdmin() @@ -176,7 +201,8 @@ public function testUpdateGlobalAdmin() $this->beGlobalAdmin(); // A request that changes no attributes performed by a global admin triggers // a reread. - $this->json('PUT', '/api/v1/volumes/'.$this->volume()->id) + $this + ->json('PUT', '/api/v1/volumes/'.$this->volume()->id) ->assertStatus(200); Queue::assertPushed(ProcessNewVolumeFiles::class); } @@ -218,20 +244,25 @@ public function testUpdateRedirect() public function testCloneVolume() { - $volume = $this->volume( - ['created_at' => '2022-11-09 14:37:00', - 'updated_at' => '2022-11-09 14:37:00',])->fresh(); + $volume = $this + ->volume([ + 'created_at' => '2022-11-09 14:37:00', + 'updated_at' => '2022-11-09 14:37:00', + ]) + ->fresh(); $project = ProjectTest::create(); $this->doTestApiRoute('POST', "/api/v1/volumes/{$volume->id}/clone-to/{$project->id}"); $this->be($project->creator); - $this->postJson("/api/v1/volumes/{$volume->id}/clone-to/{$project->id}") + $this + ->postJson("/api/v1/volumes/{$volume->id}/clone-to/{$project->id}") // No update permissions in the source project. ->assertStatus(403); $this->beAdmin(); - $this->postJSon("/api/v1/volumes/{$volume->id}/clone-to/{$project->id}") + $this + ->postJson("/api/v1/volumes/{$volume->id}/clone-to/{$project->id}") // No update permissions in the target project. ->assertStatus(403); @@ -241,7 +272,8 @@ public function testCloneVolume() Queue::fake(); - $this->postJson("/api/v1/volumes/{$volume->id}/clone-to/{$project->id}") + $this + ->postJson("/api/v1/volumes/{$volume->id}/clone-to/{$project->id}") ->assertStatus(201); Queue::assertPushed(CloneImagesOrVideos::class); @@ -255,5 +287,4 @@ public function testCloneVolume() $response->assertStatus(201); Queue::assertPushed(CloneImagesOrVideos::class); } - } diff --git a/tests/php/Http/Controllers/Api/VolumeFileControllerTest.php b/tests/php/Http/Controllers/Api/VolumeFileControllerTest.php index 69148abda..9a9fb31a7 100644 --- a/tests/php/Http/Controllers/Api/VolumeFileControllerTest.php +++ b/tests/php/Http/Controllers/Api/VolumeFileControllerTest.php @@ -27,7 +27,8 @@ public function testIndex() $this->get("/api/v1/volumes/{$id}/files")->assertStatus(403); $this->beGuest(); - $this->get("/api/v1/volumes/{$id}/files") + $this + ->get("/api/v1/volumes/{$id}/files") ->assertStatus(200) ->assertExactJson([$image->id]); } @@ -75,27 +76,31 @@ public function testStoreImage() $this->assertEquals(1, $this->volume()->images()->count()); - $this->json('POST', "/api/v1/volumes/{$id}/files", [ + $this + ->json('POST', "/api/v1/volumes/{$id}/files", [ 'files' => '1.jpg, 1.jpg', ]) // error because of duplicate image ->assertStatus(422); - $this->json('POST', "/api/v1/volumes/{$id}/files", [ + $this + ->json('POST', "/api/v1/volumes/{$id}/files", [ 'files' => '1.mp4', ]) // error because of unsupported image format ->assertStatus(422); // Image filename too long. - $this->json('POST', "/api/v1/volumes/{$id}/files", [ + $this + ->json('POST', "/api/v1/volumes/{$id}/files", [ 'files' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.jpg', ]) ->assertStatus(422); - $response = $this->json('POST', "/api/v1/volumes/{$id}/files", [ - 'files' => '1.jpg, 2.jpg', - ]); + $response = + $this->json('POST', "/api/v1/volumes/{$id}/files", [ + 'files' => '1.jpg, 2.jpg', + ]); $response->assertStatus(200); @@ -119,7 +124,8 @@ public function testStoreImageArray() Storage::disk('test')->put('images/2.jpg', 'abc'); $id = $this->volume(['url' => 'test://images'])->id; $this->beAdmin(); - $this->postJson("/api/v1/volumes/{$id}/files", ['files' => ['1.jpg', '2.jpg']]) + $this + ->postJson("/api/v1/volumes/{$id}/files", ['files' => ['1.jpg', '2.jpg']]) ->assertSuccessful(); } @@ -130,7 +136,8 @@ public function testStoreDeprecatedImagesAttribute() Storage::disk('test')->put('images/1.jpg', 'abc'); $id = $this->volume(['url' => 'test://images'])->id; $this->beAdmin(); - $this->postJson("/api/v1/volumes/{$id}/files", ['images' => ['1.jpg']]) + $this + ->postJson("/api/v1/volumes/{$id}/files", ['images' => ['1.jpg']]) ->assertSuccessful(); } @@ -142,7 +149,8 @@ public function testStoreImageExists() $id = $this->volume(['url' => 'test://images'])->id; ImageTest::create(['filename' => '1.jpg', 'volume_id' => $id]); $this->beAdmin(); - $this->postJson("/api/v1/volumes/{$id}/files", ['files' => '1.jpg']) + $this + ->postJson("/api/v1/volumes/{$id}/files", ['files' => '1.jpg']) // Image already exists. ->assertStatus(422); } @@ -151,7 +159,8 @@ public function testStoreImageFileNotExists() { $id = $this->volume()->id; $this->beAdmin(); - $this->postJson("/api/v1/volumes/{$id}/files", ['files' => '1.jpg']) + $this + ->postJson("/api/v1/volumes/{$id}/files", ['files' => '1.jpg']) ->assertStatus(422); } @@ -162,37 +171,42 @@ public function testStoreVideo() Storage::disk('test')->put('videos/1.mp4', 'abc'); Storage::disk('test')->put('videos/2.mp4', 'abc'); - $id = $this->volume([ - 'media_type_id' => MediaType::videoId(), - 'url' => 'test://videos', - ])->id; + $id = + $this->volume([ + 'media_type_id' => MediaType::videoId(), + 'url' => 'test://videos', + ])->id; VideoTest::create(['filename' => 'no.mp4', 'volume_id' => $id]); $this->assertEquals(1, $this->volume()->videos()->count()); $this->beAdmin(); - $this->json('POST', "/api/v1/volumes/{$id}/files", [ + $this + ->json('POST', "/api/v1/volumes/{$id}/files", [ 'files' => '1.mp4, 1.mp4', ]) // error because of duplicate file ->assertStatus(422); - $this->json('POST', "/api/v1/volumes/{$id}/files", [ + $this + ->json('POST', "/api/v1/volumes/{$id}/files", [ 'files' => '1.jpeg', ]) // error because of unsupported file format ->assertStatus(422); // Video filename too long. - $this->json('POST', "/api/v1/volumes/{$id}/files", [ + $this + ->json('POST', "/api/v1/volumes/{$id}/files", [ 'files' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.mp4', ]) ->assertStatus(422); - $response = $this->json('POST', "/api/v1/volumes/{$id}/files", [ - 'files' => '1.mp4, 2.mp4', - ]); + $response = + $this->json('POST', "/api/v1/volumes/{$id}/files", [ + 'files' => '1.mp4, 2.mp4', + ]); $response->assertStatus(200); @@ -218,7 +232,8 @@ public function testStoreVideoArray() 'url' => 'test://videos', ])->id; $this->beAdmin(); - $this->postJson("/api/v1/volumes/{$id}/files", ['files' => ['1.mp4', '2.mp4']]) + $this + ->postJson("/api/v1/volumes/{$id}/files", ['files' => ['1.mp4', '2.mp4']]) ->assertSuccessful(); } @@ -233,7 +248,8 @@ public function testStoreVideoExists() ])->id; VideoTest::create(['filename' => '1.mp4', 'volume_id' => $id]); $this->beAdmin(); - $this->postJson("/api/v1/volumes/{$id}/files", ['images' => '1.mp4']) + $this + ->postJson("/api/v1/volumes/{$id}/files", ['images' => '1.mp4']) // Video already exists. ->assertStatus(422); } @@ -242,7 +258,8 @@ public function testStoreVideoFileNotExists() { $id = $this->volume(['media_type_id' => MediaType::videoId()])->id; $this->beAdmin(); - $this->postJson("/api/v1/volumes/{$id}/files", ['images' => '1.mp4']) + $this + ->postJson("/api/v1/volumes/{$id}/files", ['images' => '1.mp4']) ->assertStatus(422); } @@ -253,7 +270,8 @@ public function testStoreFilesExistException() FileCache::shouldReceive('exists') ->andThrow(new Exception('Invalid MIME type.')); - $response = $this->postJson("/api/v1/volumes/{$id}/files", [ + $response = $this + ->postJson("/api/v1/volumes/{$id}/files", [ 'files' => '1.jpg', ]) ->assertStatus(422); diff --git a/tests/php/Http/Controllers/Api/Volumes/BrowserControllerTest.php b/tests/php/Http/Controllers/Api/Volumes/BrowserControllerTest.php index da93f5e51..7ef816e9a 100644 --- a/tests/php/Http/Controllers/Api/Volumes/BrowserControllerTest.php +++ b/tests/php/Http/Controllers/Api/Volumes/BrowserControllerTest.php @@ -3,7 +3,6 @@ namespace Biigle\Tests\Http\Controllers\Api\Volumes; use ApiTestCase; -use Biigle\MediaType; use Storage; class BrowserControllerTest extends ApiTestCase diff --git a/tests/php/Http/Controllers/Api/Volumes/FilenamesControllerTest.php b/tests/php/Http/Controllers/Api/Volumes/FilenamesControllerTest.php index af1cee503..f9df0793b 100644 --- a/tests/php/Http/Controllers/Api/Volumes/FilenamesControllerTest.php +++ b/tests/php/Http/Controllers/Api/Volumes/FilenamesControllerTest.php @@ -4,9 +4,7 @@ use ApiTestCase; use Biigle\MediaType; -use Biigle\Tests\ImageLabelTest; use Biigle\Tests\ImageTest; -use Biigle\Tests\LabelTest; use Biigle\Tests\VideoTest; class FilenamesControllerTest extends ApiTestCase diff --git a/tests/php/Http/Controllers/Api/Volumes/IfdoControllerTest.php b/tests/php/Http/Controllers/Api/Volumes/IfdoControllerTest.php index a148999d7..861ffbe5c 100644 --- a/tests/php/Http/Controllers/Api/Volumes/IfdoControllerTest.php +++ b/tests/php/Http/Controllers/Api/Volumes/IfdoControllerTest.php @@ -3,8 +3,6 @@ namespace Biigle\Tests\Http\Controllers\Api\Volumes; use ApiTestCase; -use Biigle\Tests\ImageTest; -use Illuminate\Http\UploadedFile; use Storage; class IfdoControllerTest extends ApiTestCase diff --git a/tests/php/Http/Controllers/Api/Volumes/ParseIfdoControllerTest.php b/tests/php/Http/Controllers/Api/Volumes/ParseIfdoControllerTest.php index b267d9193..cb7edc016 100644 --- a/tests/php/Http/Controllers/Api/Volumes/ParseIfdoControllerTest.php +++ b/tests/php/Http/Controllers/Api/Volumes/ParseIfdoControllerTest.php @@ -3,7 +3,6 @@ namespace Biigle\Tests\Http\Controllers\Api\Volumes; use ApiTestCase; -use Biigle\Tests\ImageTest; use Illuminate\Http\UploadedFile; class ParseIfdoControllerTest extends ApiTestCase diff --git a/tests/php/Http/Controllers/Api/Volumes/StatisticsControllerTest.php b/tests/php/Http/Controllers/Api/Volumes/StatisticsControllerTest.php index 35499d942..122dc76bc 100644 --- a/tests/php/Http/Controllers/Api/Volumes/StatisticsControllerTest.php +++ b/tests/php/Http/Controllers/Api/Volumes/StatisticsControllerTest.php @@ -3,14 +3,14 @@ namespace Biigle\Tests\Http\Controllers\Api\Volumes; use ApiTestCase; -use Biigle\Tests\ImageTest; -use Biigle\Tests\ImageAnnotationTest; +use Biigle\MediaType; use Biigle\Tests\ImageAnnotationLabelTest; -use Biigle\Tests\VideoTest; -use Biigle\Tests\VideoAnnotationTest; -use Biigle\Tests\VideoAnnotationLabelTest; +use Biigle\Tests\ImageAnnotationTest; +use Biigle\Tests\ImageTest; use Biigle\Tests\UserTest; -use Biigle\MediaType; +use Biigle\Tests\VideoAnnotationLabelTest; +use Biigle\Tests\VideoAnnotationTest; +use Biigle\Tests\VideoTest; class StatisticsControllerTest extends ApiTestCase { diff --git a/tests/php/Http/Controllers/Views/Admin/AnnouncementsControllerTest.php b/tests/php/Http/Controllers/Views/Admin/AnnouncementsControllerTest.php index b27d928d7..57a4ff900 100644 --- a/tests/php/Http/Controllers/Views/Admin/AnnouncementsControllerTest.php +++ b/tests/php/Http/Controllers/Views/Admin/AnnouncementsControllerTest.php @@ -3,7 +3,6 @@ namespace Biigle\Tests\Http\Controllers\Views\Admin; use Biigle\Role; -use Biigle\Announcement; use Biigle\User; use TestCase; diff --git a/tests/php/Http/Controllers/Views/Annotations/AnnotationToolControllerTest.php b/tests/php/Http/Controllers/Views/Annotations/AnnotationToolControllerTest.php index a510b4db0..bfa656128 100644 --- a/tests/php/Http/Controllers/Views/Annotations/AnnotationToolControllerTest.php +++ b/tests/php/Http/Controllers/Views/Annotations/AnnotationToolControllerTest.php @@ -4,9 +4,6 @@ use ApiTestCase; use Biigle\Tests\ImageTest; -use Biigle\Tests\ProjectTest; -use Biigle\Tests\UserTest; -use Biigle\Tests\VolumeTest; class AnnotationToolControllerTest extends ApiTestCase { diff --git a/tests/php/Http/Controllers/Views/DashboardControllerTest.php b/tests/php/Http/Controllers/Views/DashboardControllerTest.php index 466384b77..f65170749 100644 --- a/tests/php/Http/Controllers/Views/DashboardControllerTest.php +++ b/tests/php/Http/Controllers/Views/DashboardControllerTest.php @@ -4,12 +4,9 @@ use Biigle\Http\Controllers\Views\DashboardController; use Biigle\Image; -use Biigle\Role; use Biigle\Tests\ImageAnnotationLabelTest; -use Biigle\Tests\ProjectTest; use Biigle\Tests\UserTest; use Biigle\Tests\VideoAnnotationLabelTest; -use Biigle\Tests\VideoTest; use Biigle\Tests\VolumeTest; use Biigle\Video; use Biigle\Volume; diff --git a/tests/php/Http/Controllers/Views/LabelTrees/LabelTreeMergeControllerTest.php b/tests/php/Http/Controllers/Views/LabelTrees/LabelTreeMergeControllerTest.php index 10936bc20..da4028d8c 100644 --- a/tests/php/Http/Controllers/Views/LabelTrees/LabelTreeMergeControllerTest.php +++ b/tests/php/Http/Controllers/Views/LabelTrees/LabelTreeMergeControllerTest.php @@ -4,7 +4,6 @@ use Biigle\Role; use Biigle\Tests\LabelTreeTest; -use Biigle\Tests\LabelTreeVersionTest; use Biigle\Tests\UserTest; use Biigle\Visibility; use Cache; diff --git a/tests/php/Http/Controllers/Views/Volumes/VolumeCloneControllerTest.php b/tests/php/Http/Controllers/Views/Volumes/VolumeCloneControllerTest.php index e30e57e3f..431426857 100644 --- a/tests/php/Http/Controllers/Views/Volumes/VolumeCloneControllerTest.php +++ b/tests/php/Http/Controllers/Views/Volumes/VolumeCloneControllerTest.php @@ -6,7 +6,6 @@ class VolumeCloneControllerTest extends ApiTestCase { - public function testClone() { $id = $this->volume()->id; @@ -44,5 +43,4 @@ public function testClone() $response = $this->get('volumes/clone/0'); $response->assertStatus(404); } - } diff --git a/tests/php/Http/Middleware/VerifyCsrfTokenTest.php b/tests/php/Http/Middleware/VerifyCsrfTokenTest.php index 16e731a74..bcff25582 100644 --- a/tests/php/Http/Middleware/VerifyCsrfTokenTest.php +++ b/tests/php/Http/Middleware/VerifyCsrfTokenTest.php @@ -27,7 +27,8 @@ public function setUp(): void public function testHandleWrongToken() { - $this->call('PUT', '/api/v1/users/'.$this->guest()->id, [], [], [], [ + $this + ->call('PUT', '/api/v1/users/'.$this->guest()->id, [], [], [], [ 'PHP_AUTH_USER' => $this->globalAdmin()->email, 'PHP_AUTH_PW' => 'wrong_token', ]) @@ -36,7 +37,8 @@ public function testHandleWrongToken() public function testHandleWrongEmail() { - $this->call('PUT', '/api/v1/users/'.$this->guest()->id, [], [], [], [ + $this + ->call('PUT', '/api/v1/users/'.$this->guest()->id, [], [], [], [ 'PHP_AUTH_USER' => 'wrong@email.com', 'PHP_AUTH_PW' => 'test_token', ]) @@ -45,7 +47,8 @@ public function testHandleWrongEmail() public function testHandleCorrect() { - $this->call('PUT', '/api/v1/users/'.$this->guest()->id, [], [], [], [ + $this + ->call('PUT', '/api/v1/users/'.$this->guest()->id, [], [], [], [ 'PHP_AUTH_USER' => $this->globalAdmin()->email, 'PHP_AUTH_PW' => 'test_token', ]) diff --git a/tests/php/ImageTest.php b/tests/php/ImageTest.php index 9a1956606..286699e97 100644 --- a/tests/php/ImageTest.php +++ b/tests/php/ImageTest.php @@ -10,7 +10,6 @@ use Illuminate\Database\QueryException; use Mockery; use ModelTestCase; -use Response; use Storage; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -161,9 +160,7 @@ public function testImagesDeletedEventOnDelete() { Event::fake([ImagesDeleted::class]); $this->model->delete(); - Event::assertDispatched(ImagesDeleted::class, function ($event) { - return $event->uuids[0] === $this->model->uuid; - }); + Event::assertDispatched(ImagesDeleted::class, fn ($event) => $event->uuids[0] === $this->model->uuid); } public function testTiledImagesDeletedEventOnDelete() @@ -172,12 +169,8 @@ public function testTiledImagesDeletedEventOnDelete() $this->model->tiled = true; $this->model->save(); $this->model->delete(); - Event::assertDispatched(ImagesDeleted::class, function ($event) { - return $event->uuids[0] === $this->model->uuid; - }); - Event::assertDispatched(TiledImagesDeleted::class, function ($event) { - return $event->uuids[0] === $this->model->uuid; - }); + Event::assertDispatched(ImagesDeleted::class, fn ($event) => $event->uuids[0] === $this->model->uuid); + Event::assertDispatched(TiledImagesDeleted::class, fn ($event) => $event->uuids[0] === $this->model->uuid); } public function testLabels() diff --git a/tests/php/Jobs/CloneImagesOrVideosTest.php b/tests/php/Jobs/CloneImagesOrVideosTest.php index 9c9a13aa0..8da61a120 100644 --- a/tests/php/Jobs/CloneImagesOrVideosTest.php +++ b/tests/php/Jobs/CloneImagesOrVideosTest.php @@ -29,9 +29,10 @@ class CloneImagesOrVideosTest extends \ApiTestCase public function testCloneImageVolume() { Event::fake(); - $volume = $this->volume( - ['created_at' => '2022-11-09 14:37:00', - 'updated_at' => '2022-11-09 14:37:00',])->fresh(); // Use fresh() to load even the null fields. + $volume = $this->volume([ + 'created_at' => '2022-11-09 14:37:00', + 'updated_at' => '2022-11-09 14:37:00', + ])->fresh(); // Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); @@ -45,7 +46,8 @@ public function testCloneImageVolume() 'volume_id' => $volume->id, 'lng' => 1.5, 'lat' => 5.3, - 'tiled' => true])->fresh(); + 'tiled' => true, + ])->fresh(); ImageLabelTest::create(['image_id' => $oldImage->id]); $request = new Request(['project' => $project, 'volume' => $volume]); @@ -72,10 +74,11 @@ public function testCloneImageVolume() public function testCloneVideoVolume() { Event::fake(); - $volume = VolumeTest::create( - ['created_at' => '2022-01-09 14:37:00', - 'updated_at' => '2022-01-09 14:37:00', - 'media_type_id' => MediaType::videoId()])->fresh(); // Use fresh() to load even the null fields. + $volume = VolumeTest::create([ + 'created_at' => '2022-01-09 14:37:00', + 'updated_at' => '2022-01-09 14:37:00', + 'media_type_id' => MediaType::videoId(), + ])->fresh(); // Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); // The target project. @@ -88,7 +91,8 @@ public function testCloneVideoVolume() 'volume_id' => $volume->id, 'lng' => 1.5, 'lat' => 5.3, - 'duration' => 42.42])->fresh(); + 'duration' => 42.42, + ])->fresh(); VideoLabelTest::create(['video_id' => $oldVideo->id]); $request = new Request(['project' => $project, 'volume' => $volume]); @@ -122,7 +126,8 @@ public function testCloneVolumeImages() 'volume_id' => $volume->id, 'lng' => 1.5, 'lat' => 5.3, - 'tiled' => true])->fresh(); + 'tiled' => true, + ])->fresh(); ImageLabelTest::create(['image_id' => $oldImage->id]); $oldImageLabel = $oldImage->labels()->first(); @@ -148,13 +153,13 @@ public function testCloneVolumeImages() $ignore = ['id', 'volume_id', 'uuid']; $this->assertEquals( $oldImage->makeHidden($ignore)->toArray(), - $newImage->makeHidden($ignore)->toArray() + $newImage->makeHidden($ignore)->toArray(), ); $ignore = ['id', 'image_id']; $this->assertEquals( $oldImageLabel->makeHidden($ignore)->toArray(), - $newImageLabel->makeHidden($ignore)->toArray() + $newImageLabel->makeHidden($ignore)->toArray(), ); } @@ -178,7 +183,8 @@ public function testCloneVolumeImagesWithSomeLabels() 'volume_id' => $volume->id, 'lng' => 1.5, 'lat' => 5.3, - 'tiled' => true])->fresh(); + 'tiled' => true, + ])->fresh(); ImageLabelTest::create(['image_id' => $oldImage->id]); $oldImage->volume_id = $volume->id; $oldImage->save(); @@ -186,8 +192,12 @@ public function testCloneVolumeImagesWithSomeLabels() $l2 = ImageLabelTest::create(['image_id' => $oldImage->id]); $l3 = ImageLabelTest::create(['image_id' => $oldImage->id]); - $request = new Request(['project' => $project, 'volume' => $volume, 'clone_file_labels' => true, - 'only_file_labels' => [$l2->label_id, $l3->label_id]]); + $request = new Request([ + 'project' => $project, + 'volume' => $volume, + 'clone_file_labels' => true, + 'only_file_labels' => [$l2->label_id, $l3->label_id], + ]); with(new CloneImagesOrVideos($request, $copy))->handle(); @@ -206,7 +216,7 @@ public function testCloneVolumeVideos() $volume = $this->volume([ 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', - 'media_type_id' => MediaType::videoId() + 'media_type_id' => MediaType::videoId(), ])->fresh(); // Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); @@ -220,11 +230,16 @@ public function testCloneVolumeVideos() 'volume_id' => $volume->id, 'lng' => 1.5, 'lat' => 5.3, - 'duration' => 42.42])->fresh(); + 'duration' => 42.42, + ])->fresh(); VideoLabelTest::create(['video_id' => $oldVideo->id]); $oldVideoLabel = $oldVideo->labels()->first(); - $request = new Request(['project' => $project, 'volume' => $volume, 'clone_file_labels' => true]); + $request = new Request([ + 'project' => $project, + 'volume' => $volume, + 'clone_file_labels' => true, + ]); with(new CloneImagesOrVideos($request, $copy))->handle(); Queue::assertPushed(ProcessNewVolumeFiles::class); @@ -246,13 +261,13 @@ public function testCloneVolumeVideos() $ignore = ['id', 'volume_id', 'uuid']; $this->assertEquals( $oldVideo->makeHidden($ignore)->toArray(), - $newVideo->makeHidden($ignore)->toArray() + $newVideo->makeHidden($ignore)->toArray(), ); $ignore = ['id', 'video_id']; $this->assertEquals( $oldVideoLabel->makeHidden($ignore)->toArray(), - $newVideoLabel->makeHidden($ignore)->toArray() + $newVideoLabel->makeHidden($ignore)->toArray(), ); } @@ -261,8 +276,8 @@ public function testCloneVolumeVideosWithSomeLabels() $volume = VolumeTest::create([ 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', - 'media_type_id' => MediaType::videoId() - ])->fresh(); // Use fresh() to load even the null fields. + 'media_type_id' => MediaType::videoId(), + ])->fresh();// Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); // The target project. @@ -275,7 +290,8 @@ public function testCloneVolumeVideosWithSomeLabels() 'volume_id' => $volume->id, 'lng' => 1.5, 'lat' => 5.3, - 'duration' => 42.42])->fresh(); + 'duration' => 42.42, + ])->fresh(); VideoLabelTest::create(['video_id' => $oldVideo->id]); $oldVideo->volume_id = $volume->id; $oldVideo->save(); @@ -283,8 +299,12 @@ public function testCloneVolumeVideosWithSomeLabels() $l2 = VideoLabelTest::create(['video_id' => $oldVideo->id]); $l3 = VideoLabelTest::create(['video_id' => $oldVideo->id]); - $request = new Request(['project' => $project, 'volume' => $volume, 'clone_file_labels' => true, - 'only_file_labels' => [$l2->label_id, $l3->label_id]]); + $request = new Request([ + 'project' => $project, + 'volume' => $volume, + 'clone_file_labels' => true, + 'only_file_labels' => [$l2->label_id, $l3->label_id], + ]); with(new CloneImagesOrVideos($request, $copy))->handle(); @@ -300,7 +320,7 @@ public function testCloneVolumeVideosWithSomeLabels() public function testCloneVolumeImageAnnotations() { Event::fake(); - $volume = $this->volume([ + $volume = $this ->volume([ 'media_type_id' => MediaType::imageId(), 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', @@ -313,10 +333,16 @@ public function testCloneVolumeImageAnnotations() $oldImage = ImageTest::create(['volume_id' => $volume->id])->fresh(); $oldAnnotation = ImageAnnotationTest::create(['image_id' => $oldImage->id]); - $oldAnnotationLabel = ImageAnnotationLabelTest::create(['annotation_id' => $oldAnnotation->id]); + $oldAnnotationLabel = ImageAnnotationLabelTest::create([ + 'annotation_id' => $oldAnnotation->id, + ]); - $request = new Request(['project' => $project, 'volume' => $volume, 'clone_annotations' => true]); + $request = new Request([ + 'project' => $project, + 'volume' => $volume, + 'clone_annotations' => true, + ]); with(new CloneImagesOrVideos($request, $copy))->handle(); Queue::assertPushed(ProcessNewVolumeFiles::class); @@ -338,13 +364,13 @@ public function testCloneVolumeImageAnnotations() $ignore = ['id', 'image_id']; $this->assertEquals( $oldAnnotation->makeHidden($ignore)->toArray(), - $newAnnotation->makeHidden($ignore)->toArray() + $newAnnotation->makeHidden($ignore)->toArray(), ); $ignore = ['id', 'annotation_id']; $this->assertEquals( $oldAnnotationLabel->makeHidden($ignore)->toArray(), - $newAnnotationLabel->makeHidden($ignore)->toArray() + $newAnnotationLabel->makeHidden($ignore)->toArray(), ); } @@ -354,7 +380,7 @@ public function testCloneVolumeImageAnnotationsWithSomeLabels() 'media_type_id' => MediaType::imageId(), 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', - ])->fresh(); // Use fresh() to load even the null fields. + ])->fresh();// Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); // The target project. @@ -369,8 +395,12 @@ public function testCloneVolumeImageAnnotationsWithSomeLabels() $l2 = ImageAnnotationLabelTest::create(['annotation_id' => $oldAnnotation->id]); $l3 = ImageAnnotationLabelTest::create(['annotation_id' => $oldAnnotation->id]); - $request = new Request(['project' => $project, 'volume' => $volume, 'clone_annotations' => true, - 'only_annotation_labels' => [$l2->label_id, $l3->label_id]]); + $request = new Request([ + 'project' => $project, + 'volume' => $volume, + 'clone_annotations' => true, + 'only_annotation_labels' => [$l2->label_id, $l3->label_id], + ]); with(new CloneImagesOrVideos($request, $copy))->handle(); @@ -390,7 +420,7 @@ public function testCloneVolumeImageWithoutAnnotations() 'media_type_id' => MediaType::imageId(), 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', - ])->fresh(); // Use fresh() to load even the null fields. + ])->fresh();// Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); // The target project. @@ -415,10 +445,10 @@ public function testCloneVolumeImageWithoutAnnotations() public function testCloneVolumeVideoAnnotations() { Event::fake(); - $volume = $this->volume([ + $volume = $this ->volume([ 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', - 'media_type_id' => MediaType::videoId() + 'media_type_id' => MediaType::videoId(), ])->fresh(); // Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); @@ -430,7 +460,11 @@ public function testCloneVolumeVideoAnnotations() $oldAnnotation = VideoAnnotationTest::create(['video_id' => $oldVideo->id]); $oldAnnotationLabel = VideoAnnotationLabelTest::create(['annotation_id' => $oldAnnotation->id]); - $request = new Request(['project' => $project, 'volume' => $volume, 'clone_annotations' => true]); + $request = new Request([ + 'project' => $project, + 'volume' => $volume, + 'clone_annotations' => true, + ]); with(new CloneImagesOrVideos($request, $copy))->handle(); Queue::assertPushed(ProcessNewVolumeFiles::class); @@ -452,15 +486,13 @@ public function testCloneVolumeVideoAnnotations() $ignore = ['id', 'video_id']; $this->assertEquals( $oldAnnotation->makeHidden($ignore)->toArray(), - $newAnnotation->makeHidden($ignore)->toArray() - + $newAnnotation->makeHidden($ignore)->toArray(), ); $ignore = ['id', 'annotation_id']; $this->assertEquals( $oldAnnotationLabel->makeHidden($ignore)->toArray(), - $newAnnotationLabel->makeHidden($ignore)->toArray() - + $newAnnotationLabel->makeHidden($ignore)->toArray(), ); } @@ -471,7 +503,7 @@ public function testCloneVolumeVideoAnnotationsWithSomeLabels() 'media_type_id' => MediaType::videoId(), 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', - ])->fresh(); // Use fresh() to load even the null fields. + ])->fresh();// Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); // The target project. @@ -486,8 +518,12 @@ public function testCloneVolumeVideoAnnotationsWithSomeLabels() $l2 = VideoAnnotationLabelTest::create(['annotation_id' => $oldAnnotation->id]); $l3 = VideoAnnotationLabelTest::create(['annotation_id' => $oldAnnotation->id]); - $request = new Request(['project' => $project, 'volume' => $volume, 'clone_annotations' => true, - 'only_annotation_labels' => [$l2->label_id, $l3->label_id]]); + $request = new Request([ + 'project' => $project, + 'volume' => $volume, + 'clone_annotations' => true, + 'only_annotation_labels' => [$l2->label_id, $l3->label_id], + ]); with(new CloneImagesOrVideos($request, $copy))->handle(); @@ -507,7 +543,7 @@ public function testCloneVolumeVideoWithoutAnnotations() 'media_type_id' => MediaType::videoId(), 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', - ])->fresh(); // Use fresh() to load even the null fields. + ])->fresh();// Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); // The target project. @@ -536,6 +572,7 @@ public function testCloneVolumeIfDoFiles() 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', ])->fresh(); + $copy = $volume->replicate(); $copy->save(); // Use fresh() to load even the null fields. @@ -569,7 +606,7 @@ public function testHandleVolumeImages() 'media_type_id' => MediaType::imageId(), 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', - ])->fresh(); // Use fresh() to load even the null fields. + ])->fresh();// Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); @@ -582,7 +619,6 @@ public function testHandleVolumeImages() Queue::assertNotPushed(GenerateImageAnnotationPatch::class); } - public function testHandleImageAnnotationPatches() { if (!class_exists(GenerateImageAnnotationPatch::class)) { @@ -596,7 +632,7 @@ public function testHandleImageAnnotationPatches() 'media_type_id' => MediaType::imageId(), 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', - ])->fresh(); // Use fresh() to load even the null fields. + ])->fresh();// Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); @@ -604,7 +640,11 @@ public function testHandleImageAnnotationPatches() $oldAnnotation = ImageAnnotationTest::create(['image_id' => $oldImage->id]); ImageAnnotationLabelTest::create(['annotation_id' => $oldAnnotation->id]); - $request = new Request(['project' => $project, 'volume' => $volume, 'clone_annotations' => true]); + $request = new Request([ + 'project' => $project, + 'volume' => $volume, + 'clone_annotations' => true, + ]); (new CloneImagesOrVideos($request, $copy))->handle(); // One job for the creation of the annotation and one job for GenerateImageAnnotationPatch @@ -625,7 +665,7 @@ public function testHandleVideoAnnotationPatches() 'media_type_id' => MediaType::videoId(), 'created_at' => '2022-11-09 14:37:00', 'updated_at' => '2022-11-09 14:37:00', - ])->fresh(); // Use fresh() to load even the null fields. + ])->fresh();// Use fresh() to load even the null fields. $copy = $volume->replicate(); $copy->save(); @@ -633,13 +673,15 @@ public function testHandleVideoAnnotationPatches() $oldAnnotation = VideoAnnotationTest::create(['video_id' => $oldVideo->id]); VideoAnnotationLabelTest::create(['annotation_id' => $oldAnnotation->id]); - $request = new Request(['project' => $project, 'volume' => $volume, 'clone_annotations' => true]); + $request = new Request([ + 'project' => $project, + 'volume' => $volume, + 'clone_annotations' => true, + ]); (new CloneImagesOrVideos($request, $copy))->handle(); // One job for the creation of the annotation and one job for GenerateVideoAnnotationPatch Queue::assertPushed(ProcessNewVolumeFiles::class); Queue::assertPushed(GenerateVideoAnnotationPatch::class); } - } - diff --git a/tests/php/Jobs/CreateNewImagesOrVideosTest.php b/tests/php/Jobs/CreateNewImagesOrVideosTest.php index e84f8eb99..06044f071 100644 --- a/tests/php/Jobs/CreateNewImagesOrVideosTest.php +++ b/tests/php/Jobs/CreateNewImagesOrVideosTest.php @@ -5,7 +5,6 @@ use Biigle\Jobs\CreateNewImagesOrVideos; use Biigle\Jobs\ProcessNewVolumeFiles; use Biigle\MediaType; -use Biigle\Tests\ImageTest; use Biigle\Tests\VolumeTest; use Carbon\Carbon; use Illuminate\Support\Facades\Event; @@ -152,9 +151,9 @@ public function testHandleVideoMetadataEmptyCells() ]); $filenames = ['a.mp4']; $metadata = [ - ['filename', 'taken_at','gps_altitude', 'distance_to_ground'], + ['filename', 'taken_at', 'gps_altitude', 'distance_to_ground'], ['a.mp4', '2016-12-19 12:27:00', '-1500', ''], - ['a.mp4', '2016-12-19 12:28:00', '', '',], + ['a.mp4', '2016-12-19 12:28:00', '', ''], ]; with(new CreateNewImagesOrVideos($volume, $filenames, $metadata))->handle(); @@ -170,7 +169,7 @@ public function testHandleVideoMetadataZeroSingle() ]); $filenames = ['a.mp4']; $metadata = [ - ['filename', 'taken_at','distance_to_ground'], + ['filename', 'taken_at', 'distance_to_ground'], ['a.mp4', '2016-12-19 12:27:00', '0'], ]; @@ -187,7 +186,7 @@ public function testHandleVideoMetadataZero() ]); $filenames = ['a.mp4']; $metadata = [ - ['filename', 'taken_at','distance_to_ground'], + ['filename', 'taken_at', 'distance_to_ground'], ['a.mp4', '2016-12-19 12:27:00', '0'], ['a.mp4', '2016-12-19 12:28:00', '1'], ]; diff --git a/tests/php/Jobs/DeleteVolumeTest.php b/tests/php/Jobs/DeleteVolumeTest.php index 4fe7e62cf..c5b2b3176 100644 --- a/tests/php/Jobs/DeleteVolumeTest.php +++ b/tests/php/Jobs/DeleteVolumeTest.php @@ -16,8 +16,6 @@ public function testHandle() $image = ImageTest::create(); with(new DeleteVolume($image->volume))->handle(); $this->assertNull($image->volume->fresh()); - Event::assertDispatched(ImagesDeleted::class, function ($event) use ($image) { - return $event->uuids[0] === $image->uuid; - }); + Event::assertDispatched(ImagesDeleted::class, fn ($event) => $event->uuids[0] === $image->uuid); } } diff --git a/tests/php/Jobs/ProcessNewImageTest.php b/tests/php/Jobs/ProcessNewImageTest.php index 48d97e165..73a9088a5 100644 --- a/tests/php/Jobs/ProcessNewImageTest.php +++ b/tests/php/Jobs/ProcessNewImageTest.php @@ -8,7 +8,6 @@ use Biigle\Tests\ImageTest; use Biigle\Tests\VolumeTest; use Jcupitt\Vips\Exception as VipsException; -use Log; use Queue; use Storage; use TestCase; @@ -131,9 +130,7 @@ public function testHandleTileLargeImage() Queue::fake(); with(new ProcessNewImageMock($image))->handle(); - Queue::assertPushed(TileSingleImage::class, function ($job) use ($image) { - return $job->image->id === $image->id; - }); + Queue::assertPushed(TileSingleImage::class, fn ($job) => $job->image->id === $image->id); $image->refresh(); $this->assertTrue($image->tiled); $this->assertTrue($image->tilingInProgress); @@ -201,6 +198,7 @@ class ImageMock extends \Jcupitt\Vips\Image { public $width; public $height; + public function __construct($width, $height) { parent::__construct(null); @@ -212,10 +210,12 @@ public function __construct($width, $height) class ProcessNewImageMock extends ProcessNewImage { public $exif = false; + protected function makeThumbnail(Image $image, $path) { // do nothing } + protected function getExif($path) { if ($this->exif) { diff --git a/tests/php/Jobs/ProcessNewVolumeFilesTest.php b/tests/php/Jobs/ProcessNewVolumeFilesTest.php index 3632fa648..5dc18f5f5 100644 --- a/tests/php/Jobs/ProcessNewVolumeFilesTest.php +++ b/tests/php/Jobs/ProcessNewVolumeFilesTest.php @@ -24,13 +24,9 @@ public function testHandleImages() with(new ProcessNewVolumeFiles($volume))->handle(); - Queue::assertPushed(ProcessNewImage::class, function ($job) use ($i1) { - return $job->image->id === $i1->id; - }); + Queue::assertPushed(ProcessNewImage::class, fn ($job) => $job->image->id === $i1->id); - Queue::assertPushed(ProcessNewImage::class, function ($job) use ($i2) { - return $job->image->id === $i2->id; - }); + Queue::assertPushed(ProcessNewImage::class, fn ($job) => $job->image->id === $i2->id); } public function testHandleImagesWithOnly() @@ -43,13 +39,9 @@ public function testHandleImagesWithOnly() with(new ProcessNewVolumeFiles($volume, [$i1->id]))->handle(); - Queue::assertPushed(ProcessNewImage::class, function ($job) use ($i1) { - return $job->image->id === $i1->id; - }); + Queue::assertPushed(ProcessNewImage::class, fn ($job) => $job->image->id === $i1->id); - Queue::assertNotPushed(ProcessNewImage::class, function ($job) use ($i2) { - return $job->image->id === $i2->id; - }); + Queue::assertNotPushed(ProcessNewImage::class, fn ($job) => $job->image->id === $i2->id); } public function testHandleVideos() @@ -62,13 +54,9 @@ public function testHandleVideos() with(new ProcessNewVolumeFiles($volume))->handle(); - Queue::assertPushed(ProcessNewVideo::class, function ($job) use ($v1) { - return $job->video->id === $v1->id; - }); + Queue::assertPushed(ProcessNewVideo::class, fn ($job) => $job->video->id === $v1->id); - Queue::assertPushed(ProcessNewVideo::class, function ($job) use ($v2) { - return $job->video->id === $v2->id; - }); + Queue::assertPushed(ProcessNewVideo::class, fn ($job) => $job->video->id === $v2->id); } public function testHandleVideosWithOnly() @@ -81,12 +69,8 @@ public function testHandleVideosWithOnly() with(new ProcessNewVolumeFiles($volume, [$v1->id]))->handle(); - Queue::assertPushed(ProcessNewVideo::class, function ($job) use ($v1) { - return $job->video->id === $v1->id; - }); + Queue::assertPushed(ProcessNewVideo::class, fn ($job) => $job->video->id === $v1->id); - Queue::assertNotPushed(ProcessNewVideo::class, function ($job) use ($v2) { - return $job->video->id === $v2->id; - }); + Queue::assertNotPushed(ProcessNewVideo::class, fn ($job) => $job->video->id === $v2->id); } } diff --git a/tests/php/Jobs/UpdateFederatedSearchIndexTest.php b/tests/php/Jobs/UpdateFederatedSearchIndexTest.php index d93c2e5a3..902dd8f6c 100644 --- a/tests/php/Jobs/UpdateFederatedSearchIndexTest.php +++ b/tests/php/Jobs/UpdateFederatedSearchIndexTest.php @@ -14,7 +14,6 @@ use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; -use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use TestCase; diff --git a/tests/php/LabelSourceTest.php b/tests/php/LabelSourceTest.php index 88b1797f0..19f5e0289 100644 --- a/tests/php/LabelSourceTest.php +++ b/tests/php/LabelSourceTest.php @@ -38,9 +38,7 @@ public function testGetAdapter() { $mock = Mockery::mock(); - App::singleton('Biigle\Services\LabelSourceAdapters\AbCdAdapter', function () use ($mock) { - return $mock; - }); + App::singleton('Biigle\Services\LabelSourceAdapters\AbCdAdapter', fn () => $mock); $source = self::create(['name' => 'ab_cd']); diff --git a/tests/php/LabelTreeTest.php b/tests/php/LabelTreeTest.php index a71c423c8..976f1907d 100644 --- a/tests/php/LabelTreeTest.php +++ b/tests/php/LabelTreeTest.php @@ -5,10 +5,8 @@ use Biigle\LabelTree; use Biigle\Role; use Biigle\Visibility; -use Exception; use Illuminate\Database\QueryException; use ModelTestCase; -use Symfony\Component\HttpKernel\Exception\HttpException; class LabelTreeTest extends ModelTestCase { diff --git a/tests/php/Listeners/CleanupImageThumbnailsTest.php b/tests/php/Listeners/CleanupImageThumbnailsTest.php index 5db53bc7a..425aed575 100644 --- a/tests/php/Listeners/CleanupImageThumbnailsTest.php +++ b/tests/php/Listeners/CleanupImageThumbnailsTest.php @@ -29,8 +29,6 @@ public function testListen() { $image = ImageTest::create(); event(new ImagesDeleted($image->uuid)); - Queue::assertPushed(CallQueuedListener::class, function ($job) { - return $job->class === CleanupImageThumbnails::class; - }); + Queue::assertPushed(CallQueuedListener::class, fn ($job) => $job->class === CleanupImageThumbnails::class); } } diff --git a/tests/php/Listeners/CleanupImageTilesTest.php b/tests/php/Listeners/CleanupImageTilesTest.php index ad6e51be9..0735a6f33 100644 --- a/tests/php/Listeners/CleanupImageTilesTest.php +++ b/tests/php/Listeners/CleanupImageTilesTest.php @@ -29,8 +29,6 @@ public function testListen() { $image = ImageTest::create(); event(new TiledImagesDeleted($image->uuid)); - Queue::assertPushed(CallQueuedListener::class, function ($job) { - return $job->class === CleanupImageTiles::class; - }); + Queue::assertPushed(CallQueuedListener::class, fn ($job) => $job->class === CleanupImageTiles::class); } } diff --git a/tests/php/Listeners/CleanupVideoThumbnailsTest.php b/tests/php/Listeners/CleanupVideoThumbnailsTest.php index f508a9c3d..6823ac198 100644 --- a/tests/php/Listeners/CleanupVideoThumbnailsTest.php +++ b/tests/php/Listeners/CleanupVideoThumbnailsTest.php @@ -28,8 +28,6 @@ public function testListen() { $video = VideoTest::create(); event(new VideosDeleted($video->uuid)); - Queue::assertPushed(CallQueuedListener::class, function ($job) { - return $job->class === CleanupVideoThumbnails::class; - }); + Queue::assertPushed(CallQueuedListener::class, fn ($job) => $job->class === CleanupVideoThumbnails::class); } } diff --git a/tests/php/Policies/AnnouncementPolicyTest.php b/tests/php/Policies/AnnouncementPolicyTest.php index 9435fedd9..f758afe4a 100644 --- a/tests/php/Policies/AnnouncementPolicyTest.php +++ b/tests/php/Policies/AnnouncementPolicyTest.php @@ -2,8 +2,8 @@ namespace Biigle\Tests\Policies; -use Biigle\Role; use Biigle\Announcement; +use Biigle\Role; use Biigle\User; use TestCase; diff --git a/tests/php/Policies/CachedPolicyTest.php b/tests/php/Policies/CachedPolicyTest.php index 5d4aae65e..11a186cb2 100644 --- a/tests/php/Policies/CachedPolicyTest.php +++ b/tests/php/Policies/CachedPolicyTest.php @@ -28,9 +28,7 @@ public function testCache() public function testRemember() { - $callback = function () { - return 'abc'; - }; + $callback = fn () => 'abc'; $store = Mockery::mock(\Illuminate\Cache\ArrayStore::class); $store->shouldReceive('remember') ->once() diff --git a/tests/php/Policies/LabelTreeVersionPolicyTest.php b/tests/php/Policies/LabelTreeVersionPolicyTest.php index c4219354a..eeb7e1c55 100644 --- a/tests/php/Policies/LabelTreeVersionPolicyTest.php +++ b/tests/php/Policies/LabelTreeVersionPolicyTest.php @@ -2,7 +2,6 @@ namespace Biigle\Tests\Policies; -use Biigle\LabelTree; use Biigle\LabelTreeVersion; use Biigle\Role; use Biigle\Tests\LabelTreeVersionTest; diff --git a/tests/php/Policies/VideoAnnotationLabelPolicyTest.php b/tests/php/Policies/VideoAnnotationLabelPolicyTest.php index 635405dd9..b3b5c2ce2 100644 --- a/tests/php/Policies/VideoAnnotationLabelPolicyTest.php +++ b/tests/php/Policies/VideoAnnotationLabelPolicyTest.php @@ -7,7 +7,6 @@ use Biigle\Tests\UserTest; use Biigle\Tests\VideoAnnotationLabelTest; use Biigle\Tests\VideoAnnotationTest; -use Biigle\Tests\VideoTest; use TestCase; class VideoAnnotationLabelPolicyTest extends TestCase diff --git a/tests/php/ProjectInvitationTest.php b/tests/php/ProjectInvitationTest.php index 870d48a0e..5043f68d0 100644 --- a/tests/php/ProjectInvitationTest.php +++ b/tests/php/ProjectInvitationTest.php @@ -2,9 +2,7 @@ namespace Biigle\Tests; -use Biigle\Project; use Biigle\ProjectInvitation; -use Biigle\Role; use Illuminate\Database\QueryException; use ModelTestCase; diff --git a/tests/php/ProjectTest.php b/tests/php/ProjectTest.php index f0de032a7..3261393ad 100644 --- a/tests/php/ProjectTest.php +++ b/tests/php/ProjectTest.php @@ -7,7 +7,6 @@ use Biigle\Project; use Biigle\ProjectInvitation; use Biigle\Role; -use Biigle\Video; use Illuminate\Database\QueryException; use ModelTestCase; use Queue; @@ -185,9 +184,7 @@ public function testRemoveVolume() // use the force to detach and delete the volume Queue::fake(); $this->model->removeVolume($volume, true); - Queue::assertPushed(DeleteVolume::class, function ($job) use ($volume) { - return $volume->id === $job->volume->id; - }); + Queue::assertPushed(DeleteVolume::class, fn ($job) => $volume->id === $job->volume->id); $this->assertFalse($this->model->volumes()->exists()); } @@ -215,9 +212,7 @@ public function testRemoveAllVolumes() // use the force to detach and delete the volume Queue::fake(); $this->model->removeAllVolumes(true); - Queue::assertPushed(DeleteVolume::class, function ($job) use ($volume) { - return $volume->id === $job->volume->id; - }); + Queue::assertPushed(DeleteVolume::class, fn ($job) => $volume->id === $job->volume->id); $this->assertFalse($this->model->volumes()->exists()); } diff --git a/tests/php/Rules/VideoMetadataTest.php b/tests/php/Rules/VideoMetadataTest.php index 168baf989..f44c4eb40 100644 --- a/tests/php/Rules/VideoMetadataTest.php +++ b/tests/php/Rules/VideoMetadataTest.php @@ -3,7 +3,6 @@ namespace Biigle\Tests\Rules; use Biigle\Rules\VideoMetadata; -use TestCase; class VideoMetadataTest extends ImageMetadataTest { diff --git a/tests/php/Rules/VolumeUrlTest.php b/tests/php/Rules/VolumeUrlTest.php index 69d2cf76c..a47a3c412 100644 --- a/tests/php/Rules/VolumeUrlTest.php +++ b/tests/php/Rules/VolumeUrlTest.php @@ -2,8 +2,8 @@ namespace Biigle\Tests\Rules; -use Biigle\Rules\VolumeUrl; use Biigle\Role; +use Biigle\Rules\VolumeUrl; use Biigle\User; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; @@ -105,9 +105,7 @@ public function testRemoteError() $handler = HandlerStack::create($mock); $client = new Client(['handler' => $handler]); - app()->bind(Client::class, function () use ($client) { - return $client; - }); + app()->bind(Client::class, fn () => $client); $validator = new VolumeUrl; $this->assertFalse($validator->passes(null, 'http://localhost')); $this->assertStringContainsString('The remote volume URL does not seem to exist', $validator->message()); @@ -119,9 +117,7 @@ public function testRemoteNotReadable() $handler = HandlerStack::create($mock); $client = new Client(['handler' => $handler]); - app()->bind(Client::class, function () use ($client) { - return $client; - }); + app()->bind(Client::class, fn () => $client); $validator = new VolumeUrl; $this->assertFalse($validator->passes(null, 'http://localhost')); $this->assertStringContainsString('The remote volume URL returned an error response', $validator->message()); @@ -140,9 +136,7 @@ public function testRemoteOk() $handler = HandlerStack::create($mock); $handler->push($history); $client = new Client(['handler' => $handler]); - app()->bind(Client::class, function () use ($client) { - return $client; - }); + app()->bind(Client::class, fn () => $client); $validator = new VolumeUrl; $this->assertTrue($validator->passes(null, 'http://localhost')); diff --git a/tests/php/Services/LabelSourceAdapters/WormsAdapterTest.php b/tests/php/Services/LabelSourceAdapters/WormsAdapterTest.php index d739fedd9..0b85eb891 100644 --- a/tests/php/Services/LabelSourceAdapters/WormsAdapterTest.php +++ b/tests/php/Services/LabelSourceAdapters/WormsAdapterTest.php @@ -3,7 +3,6 @@ namespace Biigle\Services\LabelSourceAdapters; use App; -use Biigle\Services\LabelSourceAdapters\WormsAdapter; use Biigle\Tests\LabelTest; use Biigle\Tests\LabelTreeTest; use Illuminate\Http\Request; diff --git a/tests/php/Services/ModulesTest.php b/tests/php/Services/ModulesTest.php index 38bcca76d..386b67827 100644 --- a/tests/php/Services/ModulesTest.php +++ b/tests/php/Services/ModulesTest.php @@ -54,9 +54,7 @@ public function testRegisterViewMixinOrdering() public function testCallControllerMixins() { - Modules::registerControllerMixin('myModule', 'dashboard', function ($arg) { - return ['callable' => true]; - }); + Modules::registerControllerMixin('myModule', 'dashboard', fn ($arg) => ['callable' => true]); Modules::registerControllerMixin('myModule2', 'dashboard', ControllerMixinStub::class.'@call'); $values = Modules::callControllerMixins('dashboard', ['arg' => 1]); diff --git a/tests/php/Support/FilesystemManagerTest.php b/tests/php/Support/FilesystemManagerTest.php index 7b098d017..1cdfd76b2 100644 --- a/tests/php/Support/FilesystemManagerTest.php +++ b/tests/php/Support/FilesystemManagerTest.php @@ -8,7 +8,7 @@ class FilesystemManagerTest extends TestCase { - function testAddConfigResolver() + public function testAddConfigResolver() { Storage::addConfigResolver(function ($name) { if ($name === 'mydisk') { diff --git a/tests/php/VideoTest.php b/tests/php/VideoTest.php index 87c67ff3e..19bb254e1 100644 --- a/tests/php/VideoTest.php +++ b/tests/php/VideoTest.php @@ -3,8 +3,6 @@ namespace Biigle\Tests; use Biigle\Events\VideosDeleted; -use Biigle\Role; -use Biigle\Tests\UserTest; use Biigle\Video; use Carbon\Carbon; use Event; @@ -132,9 +130,7 @@ public function testImagesDeletedEventOnDelete() { Event::fake([VideosDeleted::class]); $this->model->delete(); - Event::assertDispatched(VideosDeleted::class, function ($event) { - return $event->uuids[0] === $this->model->uuid; - }); + Event::assertDispatched(VideosDeleted::class, fn ($event) => $event->uuids[0] === $this->model->uuid); } public function testTakenAt() diff --git a/tests/php/VolumeTest.php b/tests/php/VolumeTest.php index 10d956fee..504a9ea2c 100644 --- a/tests/php/VolumeTest.php +++ b/tests/php/VolumeTest.php @@ -12,13 +12,11 @@ use Carbon\Carbon; use Event; use Exception; -use File; use Illuminate\Database\QueryException; use Illuminate\Http\UploadedFile; use ModelTestCase; use Storage; use Symfony\Component\HttpFoundation\StreamedResponse; -use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class VolumeTest extends ModelTestCase @@ -149,9 +147,7 @@ public function testImagesDeletedEventOnDelete() $image = ImageTest::create(['volume_id' => $this->model->id]); $this->model->delete(); - Event::assertDispatched(ImagesDeleted::class, function ($event) use ($image) { - return $event->uuids[0] === $image->uuid; - }); + Event::assertDispatched(ImagesDeleted::class, fn ($event) => $event->uuids[0] === $image->uuid); } public function testTiledImagesDeletedEventOnDelete() @@ -161,12 +157,8 @@ public function testTiledImagesDeletedEventOnDelete() $image = ImageTest::create(['volume_id' => $this->model->id, 'tiled' => true]); $this->model->delete(); - Event::assertDispatched(ImagesDeleted::class, function ($event) use ($image) { - return $event->uuids[0] === $image->uuid; - }); - Event::assertDispatched(TiledImagesDeleted::class, function ($event) use ($image) { - return $event->uuids[0] === $image->uuid; - }); + Event::assertDispatched(ImagesDeleted::class, fn ($event) => $event->uuids[0] === $image->uuid); + Event::assertDispatched(TiledImagesDeleted::class, fn ($event) => $event->uuids[0] === $image->uuid); } public function testAnnotationSessions()