Skip to content

Commit

Permalink
8.0.1 (#24)
Browse files Browse the repository at this point in the history
* Fixed bytes conversions in kilobytes and megabytes.
  • Loading branch information
Okipa authored Sep 3, 2020
1 parent e42d435 commit af514c1
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parameters:
level: 5

ignoreErrors:
- '#Unsafe usage of new static#'
#- '#Exemple of error to ignore#'

excludes_analyse:
- ./*/*/FileToBeExcluded.php
Expand Down
4 changes: 2 additions & 2 deletions src/ExtendsMediaAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
])
: '';
}
Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions tests/Unit/Captions/SizeCaptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 6 additions & 6 deletions tests/Unit/ValidationRules/CollectionValidationRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
{
Expand All @@ -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);
}
}
4 changes: 2 additions & 2 deletions tests/Unit/ValidationRules/SizeValidationRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit af514c1

Please sign in to comment.