Skip to content

Commit

Permalink
Fix to the Media Test Failing. We need to ignore "." folder in the ge…
Browse files Browse the repository at this point in the history
…tDirSize calculation. It depends on the filesystem.

This commit will solve:
AsgardCms/Platform#465
and the pull request to upgrade to Laravel 5.8
AsgardCms/Platform#760
  • Loading branch information
imagina committed Sep 3, 2020
1 parent ec9518c commit 1b41238
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Tests/MaxFolderSizeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function test_it_creates_instance_of_folder_size_validator()
/** @test */
public function it_validates_max_folder_size_is_valid()
{
$this->app['config']->set('asgard.media.config.max-total-size', 10000); // Mocked folder size: 480; Mocked image: ~8192
$this->app['config']->set('asgard.media.config.max-total-size', 1000); // Mocked folder size: 510

$validator = $this->buildValidator(UploadedFile::fake()->image('avatar.jpg'));
$this->assertTrue($validator->passes());
Expand All @@ -36,7 +36,7 @@ public function it_validates_max_folder_size_is_valid()
/** @test */
public function it_validates_max_folder_size_is_invalid()
{
$this->app['config']->set('asgard.media.config.max-total-size', 100);
$this->app['config']->set('asgard.media.config.max-total-size', 50); // Mocked folder size: 510

$validator = $this->buildValidator(UploadedFile::fake()->image('avatar.jpg'));
$this->assertFalse($validator->passes());
Expand Down
3 changes: 2 additions & 1 deletion Validators/MaxFolderSizeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Contracts\Validation\Rule;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use FilesystemIterator;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class MaxFolderSizeRule implements Rule
Expand Down Expand Up @@ -45,7 +46,7 @@ public function message()
public function getDirSize($directory) : int
{
$size = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory,FilesystemIterator::SKIP_DOTS)) as $file) {
$size += $file->getSize();
}

Expand Down

0 comments on commit 1b41238

Please sign in to comment.