From 91616bb251644219702ae529606366738686c107 Mon Sep 17 00:00:00 2001
From: Alex Quintard <61151860+aquintard@users.noreply.github.com>
Date: Thu, 21 Jan 2021 14:35:39 +0100
Subject: [PATCH] Fixing issue #26 (#27)
* Added an `Okipa\MediaLibraryExt\Exceptions\CollectionNotFound` exception throw when the given collection is not found in the targeted model.
---
CHANGELOG.md | 8 +-
README.md | 20 +--
phpcs.xml | 2 +-
src/Exceptions/CollectionNotFound.php | 10 ++
src/ExtendsMediaAbilities.php | 116 +++++++++++++++---
tests/MediaLibraryExtTestCase.php | 2 +-
.../Unit/Captions/CollectionCaptionsTest.php | 10 +-
.../CollectionDimensionsCaptionTest.php | 25 ++--
.../Captions/CollectionTypesCaptionTest.php | 20 ++-
tests/Unit/Captions/SizeCaptionTest.php | 2 +-
...CollectionDimensionValidationRulesTest.php | 40 ++----
...CollectionMimeTypesValidationRulesTest.php | 23 ++--
.../CollectionMimesValidationRulesTest.php | 31 ++---
.../CollectionValidationRulesTest.php | 15 +--
.../SizeValidationRuleTest.php | 2 +-
15 files changed, 189 insertions(+), 137 deletions(-)
create mode 100644 src/Exceptions/CollectionNotFound.php
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0c9d9e68..bc39e67e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,12 @@
# Changelog
-## [9.1.0](https://github.com/Okipa/laravel-medialibrary-ext/compare/8.1.0...Okipa:9.0.0)
+## [9.2.0](https://github.com/Okipa/laravel-medialibrary-ext/compare/9.1.0...9.2.0)
+
+2020-11-14
+
+* Added an `Okipa\MediaLibraryExt\Exceptions\CollectionNotFound` exception throw when the given collection is not found in the targeted model.
+
+## [9.1.0](https://github.com/Okipa/laravel-medialibrary-ext/compare/9.0.0...9.1.0)
2020-11-14
diff --git a/README.md b/README.md
index 24525a17..a112ea97 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,7 @@ This package extension will follow the [base package](https://github.com/spatie/
* [Installation](#installation)
* [Documentation](#documentation)
* [Translations](#translations)
-* [Extra features](#extra-features)
+* [Extension features](#extension-features)
* [Validation rules](#media-validation-rules)
* [Media caption](#media-caption)
* [Testing](#testing)
@@ -96,7 +96,7 @@ Here is the list of the sentences available for translation:
* `{1}Accepted type: :types.|[2,*]Accepted types: :types.`
* `Max. file size: :size Mb.`
-## Extra features
+## Extension features
### Media validation rules
@@ -120,13 +120,13 @@ Will generate:
['mimetypes:image/jpeg,image/png', 'mimes:jpg,jpeg,jpe,png', 'dimensions:min_width=60,min_height=20', 'max:5000'];
```
-#### Available methods:
+#### Available public methods:
* `->getMediaValidationRules(string $collectionName): array`: returns all the validation rules for the given collection.
-* `->getMediaMimesValidationRules(string $collectionName): string`: returns only the mimes validation rule for the given collection.
-* `->getMediaMimeTypesValidationRules(string $collectionName): string`: returns only the mime types validation rule for the given collection.
-* `->getMediaDimensionValidationRules(string $collectionName): string`: returns only the dimensions validation rule for the given collection.
-* `->getMediaSizeValidationRule(): string`: returns only the config max file size validation rule.
+* `->getMediaMimesValidationRules(string $collectionName): string`: returns only the mimes validation rules for the given collection.
+* `->getMediaMimeTypesValidationRules(string $collectionName): string`: returns only the mime types validation rules for the given collection.
+* `->getMediaDimensionValidationRules(string $collectionName): string`: returns only the dimension validation rules for the given collection.
+* `->getMediaSizeValidationRule(): string`: returns only the max file size validation rule set from the base package `media-library.max_file_size` configuration value.
### Media caption
@@ -146,13 +146,17 @@ Will generate:
Min. width: 150 px. Min. height: 70 px. Accepted types: jpg, jpeg, jpe, png. Max file size: 5Mb.
```
-#### Available methods:
+#### Available public methods:
* `getMediaCaption(string $collectionName): string`: returns a complete caption for the given collection.
* `getMediaDimensionsCaption(string $collectionName): string`: returns only the dimensions caption for the given collection.
* `getMediaMimeTypesCaption(string $collectionName): string`: returns only the mime types caption for the given collection.
* `getMediaSizeCaption(): string`: returns only the config max file size caption only.
+### Exceptions
+
+In order to avoid careless mistakes when using public methods that are requiring a `string $collectionName` argument provided by this extension, an `Okipa\MediaLibraryExt\Exceptions\CollectionNotFound` exception will be thrown when the given collection name is not found in the targeted model.
+
## Testing
``` bash
diff --git a/phpcs.xml b/phpcs.xml
index bcca0341..c842bffe 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -7,7 +7,7 @@
./tests/*
-
+
./tests/*
diff --git a/src/Exceptions/CollectionNotFound.php b/src/Exceptions/CollectionNotFound.php
new file mode 100644
index 00000000..7c1f4e39
--- /dev/null
+++ b/src/Exceptions/CollectionNotFound.php
@@ -0,0 +1,10 @@
+getMediaCollection($collectionName)) {
- return '';
- }
+ $this->checkIfMediaCollectionExist($collectionName);
$dimensionsCaption = $this->getMediaDimensionsCaption($collectionName);
$mimeTypesCaption = $this->getMediaMimeTypesCaption($collectionName);
$sizeCaption = $this->getMediaSizeCaption();
@@ -28,8 +37,25 @@ public function getMediaCaption(string $collectionName): string
. $sizeCaption;
}
- abstract public function getMediaCollection(string $collectionName = 'default'): ?MediaCollection;
+ /**
+ * @param string $collectionName
+ *
+ * @throws \Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
+ */
+ protected function checkIfMediaCollectionExist(string $collectionName): void
+ {
+ $mediaCollection = $this->getMediaCollection($collectionName);
+ if (! $mediaCollection) {
+ throw new CollectionNotFound("The collection {$mediaCollection} as not been found.");
+ }
+ }
+ /**
+ * @param string $collectionName
+ *
+ * @return string
+ * @throws \Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
+ */
public function getMediaDimensionsCaption(string $collectionName): string
{
$maxDimensions = $this->getMediaMaxDimensions($collectionName);
@@ -46,6 +72,12 @@ public function getMediaDimensionsCaption(string $collectionName): string
return $caption;
}
+ /**
+ * @param string $collectionName
+ *
+ * @return array
+ * @throws \Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
+ */
protected function getMediaMaxDimensions(string $collectionName): array
{
if (! $this->mediaHasDimensions($collectionName)) {
@@ -65,20 +97,40 @@ protected function getMediaMaxDimensions(string $collectionName): array
return $this->getMaxWidthAndMaxHeight($sizes);
}
+ /**
+ * @param string $collectionName
+ *
+ * @return bool
+ * @throws \Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
+ */
protected function mediaHasDimensions(string $collectionName): bool
{
- $mediaCollection = $this->getMediaCollection($collectionName);
- if (! $mediaCollection) {
- return false;
- }
+ $mediaCollection = $this->getMediaCollectionOrFail($collectionName);
$mediaConversions = $this->getAllMediaConversions($collectionName);
if ($mediaConversions->isEmpty()) {
return false;
}
- return ! count(array_filter($mediaCollection->acceptsMimeTypes, function ($mimeTypes) {
- return ! Str::startsWith($mimeTypes, 'image');
- }));
+ return ! count(array_filter(
+ $mediaCollection->acceptsMimeTypes,
+ static fn($mimeTypes) => ! Str::startsWith($mimeTypes, 'image')
+ ));
+ }
+
+ /**
+ * @param string $collectionName
+ *
+ * @return \Spatie\MediaLibrary\MediaCollections\MediaCollection
+ * @throws \Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
+ */
+ protected function getMediaCollectionOrFail(string $collectionName = 'default'): MediaCollection
+ {
+ $mediaCollection = $this->getMediaCollection($collectionName);
+ if (! $mediaCollection) {
+ throw new CollectionNotFound("The collection {$mediaCollection} as not been found.");
+ }
+
+ return $mediaCollection;
}
protected function getAllMediaConversions(string $collectionName): Collection
@@ -90,8 +142,6 @@ protected function getAllMediaConversions(string $collectionName): Collection
}));
}
- abstract public function registerAllMediaConversions(Media $media = null): void;
-
protected function getMaxWidthAndMaxHeight(array $sizes): array
{
$width = ! empty($sizes) ? max(Arr::pluck($sizes, 'width')) : null;
@@ -100,9 +150,15 @@ protected function getMaxWidthAndMaxHeight(array $sizes): array
return compact('width', 'height');
}
+ /**
+ * @param string $collectionName
+ *
+ * @return string
+ * @throws \Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
+ */
public function getMediaMimeTypesCaption(string $collectionName): string
{
- $mediaCollection = $this->getMediaCollection($collectionName);
+ $mediaCollection = $this->getMediaCollectionOrFail($collectionName);
if (! empty($mediaCollection->acceptsMimeTypes)) {
$extensions = $this->getExtensionsFromMimeTypes($mediaCollection->acceptsMimeTypes);
$extensionsString = implode(',', $extensions);
@@ -140,11 +196,15 @@ public function getMediaSizeCaption(): string
: '';
}
+ /**
+ * @param string $collectionName
+ *
+ * @return array
+ * @throws \Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
+ */
public function getMediaValidationRules(string $collectionName): array
{
- if (! $this->getMediaCollection($collectionName)) {
- return [];
- }
+ $this->checkIfMediaCollectionExist($collectionName);
$mimesConstraints = $this->getMediaMimesValidationRules($collectionName);
$mimeTypeConstraints = $this->getMediaMimeTypesValidationRules($collectionName);
$dimensionConstraints = $this->getMediaDimensionValidationRules($collectionName);
@@ -158,9 +218,15 @@ public function getMediaValidationRules(string $collectionName): array
]));
}
+ /**
+ * @param string $collectionName
+ *
+ * @return string
+ * @throws \Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
+ */
public function getMediaMimesValidationRules(string $collectionName): string
{
- $mediaCollection = $this->getMediaCollection($collectionName);
+ $mediaCollection = $this->getMediaCollectionOrFail($collectionName);
$validationString = '';
if (! empty($mediaCollection->acceptsMimeTypes)) {
$acceptedExtensions = $this->getExtensionsFromMimeTypes($mediaCollection->acceptsMimeTypes);
@@ -172,13 +238,19 @@ public function getMediaMimesValidationRules(string $collectionName): string
return $validationString;
}
+ /**
+ * @param string $collectionName
+ *
+ * @return string
+ * @throws \Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
+ */
public function getMediaMimeTypesValidationRules(string $collectionName): string
{
+ $mediaCollection = $this->getMediaCollectionOrFail($collectionName);
$mediaConversions = $this->getAllMediaConversions($collectionName);
if ($mediaConversions->isEmpty()) {
return '';
}
- $mediaCollection = $this->getMediaCollection($collectionName);
$validationString = '';
if (! empty($mediaCollection->acceptsMimeTypes)) {
$validationString .= 'mimetypes:' . implode(',', $mediaCollection->acceptsMimeTypes);
@@ -187,6 +259,12 @@ public function getMediaMimeTypesValidationRules(string $collectionName): string
return $validationString;
}
+ /**
+ * @param string $collectionName
+ *
+ * @return string
+ * @throws \Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
+ */
public function getMediaDimensionValidationRules(string $collectionName): string
{
$maxDimensions = $this->getMediaMaxDimensions($collectionName);
diff --git a/tests/MediaLibraryExtTestCase.php b/tests/MediaLibraryExtTestCase.php
index fe8fb0a8..4c762f10 100644
--- a/tests/MediaLibraryExtTestCase.php
+++ b/tests/MediaLibraryExtTestCase.php
@@ -7,7 +7,7 @@
class MediaLibraryExtTestCase extends TestCase
{
- protected function getPackageProviders($app)
+ protected function getPackageProviders($app): array
{
return [MediaLibraryServiceProvider::class];
}
diff --git a/tests/Unit/Captions/CollectionCaptionsTest.php b/tests/Unit/Captions/CollectionCaptionsTest.php
index e5070088..8ed4590b 100644
--- a/tests/Unit/Captions/CollectionCaptionsTest.php
+++ b/tests/Unit/Captions/CollectionCaptionsTest.php
@@ -1,7 +1,8 @@
set('media-library.max_file_size', 1000000);
- $captionString = (new InteractsWithMediaModel())->getMediaCaption('test');
- self::assertEquals('', $captionString);
+ $this->expectException(CollectionNotFound::class);
+ (new InteractsWithMediaModel())->getMediaCaption('test');
}
/** @test */
diff --git a/tests/Unit/Captions/CollectionDimensionsCaptionTest.php b/tests/Unit/Captions/CollectionDimensionsCaptionTest.php
index 93d6ae65..a84aef99 100644
--- a/tests/Unit/Captions/CollectionDimensionsCaptionTest.php
+++ b/tests/Unit/Captions/CollectionDimensionsCaptionTest.php
@@ -1,7 +1,8 @@
addMediaConversion('thumb')->crop(Manipulations::CROP_CENTER, 60, 20);
- }
- };
- $dimensionsCaptionString = $testModel->getMediaDimensionsCaption('test');
- self::assertEquals('', $dimensionsCaptionString);
+ $this->expectException(CollectionNotFound::class);
+ (new InteractsWithMediaModel())->getMediaDimensionsCaption('test');
}
/** @test */
@@ -37,7 +32,7 @@ public function registerMediaCollections(): void
}
/** @test */
- public function it_returns_only_width_dimension_legend_when_only_width_is_declared(): void
+ public function it_returns_only_width_dimension_caption_when_only_width_is_declared(): void
{
$testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
@@ -55,7 +50,7 @@ public function registerMediaConversions(Media $media = null): void
}
/** @test */
- public function it_returns_only_height_dimension_legend_when_only_height_is_declared(): void
+ public function it_returns_only_height_dimension_caption_when_only_height_is_declared(): void
{
$testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
@@ -73,7 +68,7 @@ public function registerMediaConversions(Media $media = null): void
}
/** @test */
- public function it_returns_no_dimension_legend_when_no_size_is_declared(): void
+ public function it_returns_no_dimension_caption_when_no_size_is_declared(): void
{
$testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
@@ -91,7 +86,7 @@ public function registerMediaConversions(Media $media = null): void
}
/** @test */
- public function it_returns_width_and_height_dimension_legend_when_both_are_declared(): void
+ public function it_returns_width_and_height_dimension_caption_when_both_are_declared(): void
{
$testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
@@ -119,7 +114,7 @@ public function registerMediaConversions(Media $media = null): void
}
/** @test */
- public function it_does_not_returns_dimensions_legend_when_no_image_declared(): void
+ public function it_does_not_returns_dimensions_caption_when_no_image_declared(): void
{
$testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
diff --git a/tests/Unit/Captions/CollectionTypesCaptionTest.php b/tests/Unit/Captions/CollectionTypesCaptionTest.php
index c714bf4d..679d60ec 100644
--- a/tests/Unit/Captions/CollectionTypesCaptionTest.php
+++ b/tests/Unit/Captions/CollectionTypesCaptionTest.php
@@ -1,7 +1,8 @@
addMediaConversion('thumb')->crop(Manipulations::CROP_CENTER, 60, 20);
- }
- };
- $dimensionsCaptionString = $testModel->getMediaMimeTypesCaption('test');
- self::assertEquals('', $dimensionsCaptionString);
+ $this->expectException(CollectionNotFound::class);
+ (new InteractsWithMediaModel())->getMediaMimeTypesCaption('test');
}
/** @test */
- public function it_returns_no_types_legend_when_none_declared(): void
+ public function it_returns_no_types_caption_when_none_declared(): void
{
$testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
@@ -42,7 +37,7 @@ public function registerMediaConversions(Media $media = null): void
}
/** @test */
- public function it_returns_types_legend_when_are_declared(): void
+ public function it_returns_types_caption_when_are_declared(): void
{
$testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
@@ -86,6 +81,7 @@ public function registerMediaCollections(): void
->crop(Manipulations::CROP_CENTER, 20, 80);
});
}
+
public function registerMediaConversions(Media $media = null): void
{
$this->addMediaConversion('thumb')->crop(Manipulations::CROP_CENTER, 100, 70);
diff --git a/tests/Unit/Captions/SizeCaptionTest.php b/tests/Unit/Captions/SizeCaptionTest.php
index 2c06d0ef..0f6c9ef6 100644
--- a/tests/Unit/Captions/SizeCaptionTest.php
+++ b/tests/Unit/Captions/SizeCaptionTest.php
@@ -1,6 +1,6 @@
addMediaConversion('thumb')->crop(Manipulations::CROP_CENTER, 60, 20);
- }
- };
- $rules = $testModel->getMediaDimensionValidationRules('test');
- self::assertEquals('', $rules);
+ $this->expectException(CollectionNotFound::class);
+ (new InteractsWithMediaModel())->getMediaDimensionValidationRules('test');
}
/** @test */
public function it_returns_none_when_it_is_called_with_non_existent_conversions(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar')->acceptsMimeTypes(['image/jpeg', 'image/png']);
@@ -41,8 +34,7 @@ public function registerMediaCollections(): void
/** @test */
public function it_returns_global_conversion_dimension_rules_when_no_collection_conversions_declared(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar');
@@ -60,8 +52,7 @@ public function registerMediaConversions(Media $media = null): void
/** @test */
public function it_returns_only_width_dimension_rule_when_only_width_is_declared(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar')->acceptsMimeTypes(['image/jpeg', 'image/png']);
@@ -79,8 +70,7 @@ public function registerMediaConversions(Media $media = null): void
/** @test */
public function it_returns_only_height_dimension_rule_when_only_height_is_declared(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar')->acceptsMimeTypes(['image/jpeg', 'image/png']);
@@ -98,8 +88,7 @@ public function registerMediaConversions(Media $media = null): void
/** @test */
public function it_returns_no_dimension_rule_when_no_size_is_declared(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar')->acceptsMimeTypes(['image/jpeg', 'image/png']);
@@ -117,8 +106,7 @@ public function registerMediaConversions(Media $media = null): void
/** @test */
public function it_returns_collection_dimension_rules_when_no_global_conversions_declared(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar')
@@ -143,8 +131,7 @@ public function registerMediaConversions(Media $media = null): void
/** @test */
public function it_returns_global_and_collection_dimension_rules_when_both_are_declared(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar')
@@ -168,8 +155,7 @@ public function registerMediaConversions(Media $media = null): void
/** @test */
public function it_does_not_returns_dimension_rules_when_no_image_declared(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar')
diff --git a/tests/Unit/ValidationRules/CollectionMimeTypesValidationRulesTest.php b/tests/Unit/ValidationRules/CollectionMimeTypesValidationRulesTest.php
index 27d85f57..caabf448 100644
--- a/tests/Unit/ValidationRules/CollectionMimeTypesValidationRulesTest.php
+++ b/tests/Unit/ValidationRules/CollectionMimeTypesValidationRulesTest.php
@@ -1,7 +1,8 @@
addMediaConversion('thumb')->crop(Manipulations::CROP_CENTER, 60, 20);
- }
- };
- $rules = $testModel->getMediaMimeTypesValidationRules('test');
- self::assertEquals('', $rules);
- ;
+ $this->expectException(CollectionNotFound::class);
+ (new InteractsWithMediaModel())->getMediaMimeTypesValidationRules('test');
}
/** @test */
public function it_returns_mime_types_rules_when_declared_in_collection(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar')
@@ -53,8 +45,7 @@ public function registerMediaConversions(Media $media = null): void
/** @test */
public function it_returns_no_collection_mime_types_rules_when_none_declared(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar');
diff --git a/tests/Unit/ValidationRules/CollectionMimesValidationRulesTest.php b/tests/Unit/ValidationRules/CollectionMimesValidationRulesTest.php
index 8f1d207f..40f857e9 100644
--- a/tests/Unit/ValidationRules/CollectionMimesValidationRulesTest.php
+++ b/tests/Unit/ValidationRules/CollectionMimesValidationRulesTest.php
@@ -1,7 +1,8 @@
addMediaConversion('thumb')->crop(Manipulations::CROP_CENTER, 60, 20);
- }
- };
- $rules = $testModel->getMediaMimesValidationRules('avatar');
- self::assertEquals('', $rules);
+ $this->expectException(CollectionNotFound::class);
+ (new InteractsWithMediaModel())->getMediaMimesValidationRules('test');
}
/** @test */
- public function it_returns_mimes_rules_when_declared_in_collection()
+ public function it_returns_mimes_rules_when_declared_in_collection(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar')
@@ -50,10 +43,9 @@ public function registerMediaConversions(Media $media = null): void
}
/** @test */
- public function it_returns_no_collection_mimes_rules_when_none_declared()
+ public function it_returns_no_collection_mimes_rules_when_none_declared(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar');
@@ -69,10 +61,9 @@ public function registerMediaConversions(Media $media = null): void
}
/** @test */
- public function it_removes_duplicated_mimes()
+ public function it_removes_duplicated_mimes(): void
{
- $testModel = new class extends InteractsWithMediaModel
- {
+ $testModel = new class extends InteractsWithMediaModel {
public function registerMediaCollections(): void
{
$this->addMediaCollection('avatar')
diff --git a/tests/Unit/ValidationRules/CollectionValidationRulesTest.php b/tests/Unit/ValidationRules/CollectionValidationRulesTest.php
index 9d739ff1..cfe60429 100644
--- a/tests/Unit/ValidationRules/CollectionValidationRulesTest.php
+++ b/tests/Unit/ValidationRules/CollectionValidationRulesTest.php
@@ -1,7 +1,8 @@
addMediaConversion('thumb')->crop(Manipulations::CROP_CENTER, 60, 20);
- }
- };
- $rules = $testModel->getMediaValidationRules('avatar');
- self::assertEquals([], $rules);
+ $this->expectException(CollectionNotFound::class);
+ (new InteractsWithMediaModel())->getMediaValidationRules('test');
}
/** @test */
diff --git a/tests/Unit/ValidationRules/SizeValidationRuleTest.php b/tests/Unit/ValidationRules/SizeValidationRuleTest.php
index d78f533a..7a427229 100644
--- a/tests/Unit/ValidationRules/SizeValidationRuleTest.php
+++ b/tests/Unit/ValidationRules/SizeValidationRuleTest.php
@@ -1,6 +1,6 @@