From 1b4123840212a120a3fb641ec20c97f2c8e62042 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 2 Sep 2020 20:39:17 -0500 Subject: [PATCH] Fix to the Media Test Failing. We need to ignore "." folder in the getDirSize calculation. It depends on the filesystem. This commit will solve: https://github.com/AsgardCms/Platform/issues/465 and the pull request to upgrade to Laravel 5.8 https://github.com/AsgardCms/Platform/pull/760 --- Tests/MaxFolderSizeRuleTest.php | 4 ++-- Validators/MaxFolderSizeRule.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Tests/MaxFolderSizeRuleTest.php b/Tests/MaxFolderSizeRuleTest.php index d8131743..feb48769 100644 --- a/Tests/MaxFolderSizeRuleTest.php +++ b/Tests/MaxFolderSizeRuleTest.php @@ -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()); @@ -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()); diff --git a/Validators/MaxFolderSizeRule.php b/Validators/MaxFolderSizeRule.php index d3fa71d7..4428c666 100644 --- a/Validators/MaxFolderSizeRule.php +++ b/Validators/MaxFolderSizeRule.php @@ -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 @@ -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(); }