diff --git a/CHANGELOG.md b/CHANGELOG.md index 79898462..b70fec39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [8.0.1](https://github.com/Okipa/laravel-medialibrary-ext/compare/8.0.0...Okipa:8.0.1) + +2020-09-03 + +* Fixed bytes conversions in kilobytes and megabytes. + ## [8.0.0](https://github.com/Okipa/laravel-medialibrary-ext/compare/7.19.2...Okipa:8.0.0) 2020-03-30 diff --git a/composer.json b/composer.json index 5e90d50d..f03ca275 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "symfony/mime": "^4.0||^5.0" }, "require-dev": { - "nunomaduro/larastan": "^0.4.3||^0.5", + "nunomaduro/larastan": "^0.4.3||^0.6", "orchestra/testbench": "~3.8.0||^4.0||^5.0", "phpmd/phpmd": "^2.8", "squizlabs/php_codesniffer": "^3.5" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 76d963b9..eac8c0b7 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -10,7 +10,7 @@ parameters: level: 5 ignoreErrors: - - '#Unsafe usage of new static#' + #- '#Exemple of error to ignore#' excludes_analyse: - ./*/*/FileToBeExcluded.php diff --git a/src/ExtendsMediaAbilities.php b/src/ExtendsMediaAbilities.php index 9f4b61b8..5a3dd180 100644 --- a/src/ExtendsMediaAbilities.php +++ b/src/ExtendsMediaAbilities.php @@ -134,7 +134,7 @@ public function getMediaSizeCaption(): string return $configMaxFileSize ? (string) __('Max. file size: :size Mb.', [ - 'size' => round($configMaxFileSize / 1000000, 1), + 'size' => round($configMaxFileSize / 1048576, 1), // 1 Mb = 1 048 576 bytes ]) : ''; } @@ -203,6 +203,6 @@ public function getMediaSizeValidationRule(): string { $configMaxFileSize = config('media-library.max_file_size'); - return $configMaxFileSize ? 'max:' . round($configMaxFileSize / 1000) : ''; + return $configMaxFileSize ? 'max:' . round($configMaxFileSize / 1024) : ''; // 1 kilobyte = 1 024 bytes } } diff --git a/tests/Unit/Captions/SizeCaptionTest.php b/tests/Unit/Captions/SizeCaptionTest.php index db165863..64cbbb08 100644 --- a/tests/Unit/Captions/SizeCaptionTest.php +++ b/tests/Unit/Captions/SizeCaptionTest.php @@ -18,10 +18,10 @@ public function it_returns_none_when_max_file_size_is_not_defined() /** @test */ public function it_returns_max_weight_caption() { - config()->set('media-library.max_file_size', 1000000); + config()->set('media-library.max_file_size', (1024 * 1024 * 10)); $sizeCaptionString = (new InteractsWithMediaModel)->getMediaSizeCaption(); $this->assertEquals(__('Max. file size: :size Mb.', [ - 'size' => 1, + 'size' => 10, ]), $sizeCaptionString); } } diff --git a/tests/Unit/ValidationRules/CollectionValidationRulesTest.php b/tests/Unit/ValidationRules/CollectionValidationRulesTest.php index 92c24f7a..02fa139c 100644 --- a/tests/Unit/ValidationRules/CollectionValidationRulesTest.php +++ b/tests/Unit/ValidationRules/CollectionValidationRulesTest.php @@ -25,9 +25,9 @@ public function registerMediaCollections(): void /** @test */ public function it_returns_only_size_rule_with_non_existent_conversions() { - config()->set('media-library.max_file_size', 1000000); + config()->set('media-library.max_file_size', (1024 * 1024 * 10)); $rules = (new InteractsWithMediaModel)->getMediaValidationRules('avatar'); - $this->assertEquals(['max:1000'], $rules); + $this->assertEquals(['max:10240'], $rules); } /** @test */ @@ -79,15 +79,15 @@ public function registerMediaConversions(Media $media = null): void /** @test */ public function it_can_return_only_size_rule() { - config()->set('media-library.max_file_size', 1000000); + config()->set('media-library.max_file_size', (1024 * 1024 * 10)); $rules = (new InteractsWithMediaModel)->getMediaValidationRules('avatar'); - $this->assertEquals(['max:1000'], $rules); + $this->assertEquals(['max:10240'], $rules); } /** @test */ public function it_can_return_all_rules() { - config()->set('media-library.max_file_size', 1000000); + config()->set('media-library.max_file_size', (1024 * 1024 * 10)); $testModel = new class extends InteractsWithMediaModel { public function registerMediaCollections(): void { @@ -104,7 +104,7 @@ public function registerMediaConversions(Media $media = null): void 'mimes:jpeg,jpg,jpe,png', 'mimetypes:image/jpeg,image/png', 'dimensions:min_width=60,min_height=20', - 'max:1000', + 'max:10240', ], $rules); } } diff --git a/tests/Unit/ValidationRules/SizeValidationRuleTest.php b/tests/Unit/ValidationRules/SizeValidationRuleTest.php index f9eb348a..6ce5e5df 100644 --- a/tests/Unit/ValidationRules/SizeValidationRuleTest.php +++ b/tests/Unit/ValidationRules/SizeValidationRuleTest.php @@ -18,8 +18,8 @@ public function it_return_none_when_it_is_not_defined() /** @test */ public function it_can_return_size_constraint() { - config()->set('media-library.max_file_size', 1000000); + config()->set('media-library.max_file_size', (1024 * 1024 * 10)); $captionString = (new InteractsWithMediaModel)->getMediaSizeValidationRule(); - $this->assertEquals('max:1000', $captionString); + $this->assertEquals('max:10240', $captionString); } }