From e9e1724397187e46c0302a85db0dae8b5d63e5d3 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 19 Dec 2024 17:59:41 +0300 Subject: [PATCH 01/17] chore: Code Cleanup --- .gitattributes | 3 ++- .gitignore | 2 ++ composer.json | 4 +++- tests/bootstrap.php | 27 +++------------------------ 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/.gitattributes b/.gitattributes index 95a8b17..2266402 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,4 +7,5 @@ /.gitignore export-ignore /.travis.yml export-ignore /phpunit.xml export-ignore -/sonar-project.properties export-ignore \ No newline at end of file +/sonar-project.properties export-ignore +/CHANGELOG.md \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9596e31..7d18188 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ php-cs-fixer-v2.phar .idea/* php-cs-fixer.phar clover.xml +*.bin +tests/files/not-exist/new.txt diff --git a/composer.json b/composer.json index 8ec7506..3d66931 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,8 @@ { "name": "webfiori/file", "description": "Basic class library to read, write and view files using PHP.", + "type":"library", + "version":"1.3.6", "authors": [ { "name": "Ibrahim BinAlshikh", @@ -24,7 +26,7 @@ ], "autoload" :{ "psr-4":{ - "webfiori\\file\\":"webfiori\\file" + "webfiori\\file\\":"webfiori/file/" } } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7d210b0..68366ed 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,16 +1,16 @@ Date: Thu, 19 Dec 2024 18:00:07 +0300 Subject: [PATCH 02/17] ci: Drop PHP 7 Support --- .github/workflows/php70.yml | 41 ---------------------------------- .github/workflows/php71.yml | 41 ---------------------------------- .github/workflows/php72.yml | 43 ------------------------------------ .github/workflows/php73.yml | 44 ------------------------------------- .github/workflows/php74.yml | 44 ------------------------------------- 5 files changed, 213 deletions(-) delete mode 100644 .github/workflows/php70.yml delete mode 100644 .github/workflows/php71.yml delete mode 100644 .github/workflows/php72.yml delete mode 100644 .github/workflows/php73.yml delete mode 100644 .github/workflows/php74.yml diff --git a/.github/workflows/php70.yml b/.github/workflows/php70.yml deleted file mode 100644 index ef223af..0000000 --- a/.github/workflows/php70.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build PHP 7.0 - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test: - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: true - matrix: - os: [ ubuntu-latest ] - php: [7.0] - - name: PHP${{matrix.php}} - ${{matrix.os}} - - steps: - - name: Clone Repo - uses: actions/checkout@v1 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: mysqli, mbstring, sqlsrv - tools: phpunit:5.7.27, composer - - - name: Install Dependencies - run: composer install --prefer-dist --no-interaction - - - name: Execute Tests - run: phpunit - - - name: CodeCov - uses: codecov/codecov-action@v4 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php71.yml b/.github/workflows/php71.yml deleted file mode 100644 index 9386707..0000000 --- a/.github/workflows/php71.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build PHP 7.1 - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test: - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: true - matrix: - os: [ ubuntu-latest ] - php: [7.1] - - name: PHP${{matrix.php}} - ${{matrix.os}} - - steps: - - name: Clone Repo - uses: actions/checkout@v1 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: mysqli, mbstring, sqlsrv - tools: phpunit:5.7.27, composer - - - name: Install Dependencies - run: composer install --prefer-dist --no-interaction - - - name: Execute Tests - run: phpunit - - - name: CodeCov - uses: codecov/codecov-action@v4 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/php72.yml b/.github/workflows/php72.yml deleted file mode 100644 index 7f404d9..0000000 --- a/.github/workflows/php72.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Build PHP 7.2 - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test: - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: true - matrix: - os: [ ubuntu-latest ] - php: [7.2] - - name: PHP${{matrix.php}} - ${{matrix.os}} - - steps: - - name: Clone Repo - uses: actions/checkout@v1 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: mysqli, mbstring, sqlsrv - tools: phpunit:8.5.13 - - - name: Install Dependencies - run: composer install --prefer-dist --no-interaction - - - name: Execute Tests - run: phpunit - - - name: CodeCov - uses: codecov/codecov-action@v4 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - - diff --git a/.github/workflows/php73.yml b/.github/workflows/php73.yml deleted file mode 100644 index 0cfa20c..0000000 --- a/.github/workflows/php73.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Build PHP 7.3 - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test: - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: true - matrix: - os: [ ubuntu-latest ] - php: [7.3] - - name: PHP${{matrix.php}} - ${{matrix.os}} - - steps: - - name: Clone Repo - uses: actions/checkout@v1 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: mysqli, mbstring, sqlsrv - tools: phpunit:8.5.13 - - - name: Install Dependencies - run: composer install --prefer-dist --no-interaction - - - name: Execute Tests - run: phpunit - - - name: CodeCov - uses: codecov/codecov-action@v4 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - - - diff --git a/.github/workflows/php74.yml b/.github/workflows/php74.yml deleted file mode 100644 index 4c94075..0000000 --- a/.github/workflows/php74.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Build PHP 7.4 - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - test: - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: true - matrix: - os: [ ubuntu-latest ] - php: [7.4] - - name: PHP${{matrix.php}} - ${{matrix.os}} - - steps: - - name: Clone Repo - uses: actions/checkout@v1 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: mysqli, mbstring, sqlsrv - tools: phpunit:8.5.13 - - - name: Install Dependencies - run: composer install --prefer-dist --no-interaction - - - name: Execute Tests - run: phpunit - - - name: CodeCov - uses: codecov/codecov-action@v4 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - - - From a4c02c25eb152cf362eb9f245dbad6675201565c Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 19 Dec 2024 18:00:24 +0300 Subject: [PATCH 03/17] ci: Added PHP 8 Support --- .github/workflows/php84.yml | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/php84.yml diff --git a/.github/workflows/php84.yml b/.github/workflows/php84.yml new file mode 100644 index 0000000..932e933 --- /dev/null +++ b/.github/workflows/php84.yml @@ -0,0 +1,44 @@ +name: Build PHP 8.4 + +on: + push: + branches: [ main, dev ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: true + matrix: + os: [ ubuntu-latest ] + php: [8.4] + + name: PHP${{matrix.php}} - ${{matrix.os}} + + steps: + - name: Clone Repo + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mysqli, mbstring, sqlsrv + tools: phpunit:9.5.20, composer + + - name: Shutdown Ubuntu MySQL + run: sudo service mysql stop + + - name: Install Dependencies + run: composer install --prefer-dist --no-interaction + + - name: Execute Tests + run: phpunit --configuration tests/phpunit.xml + + - name: CodeCov + uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file From 6fd0fe42f6c3e5a43d0be3c6413b4eb963f88e14 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 19 Dec 2024 18:00:50 +0300 Subject: [PATCH 04/17] test: Moved PHP Unit Configuration --- phpunit.xml | 22 ---------------------- tests/phpunit.xml | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 22 deletions(-) delete mode 100644 phpunit.xml create mode 100644 tests/phpunit.xml diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index adef165..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - ./webfiori/file/File.php - ./webfiori/file/MIME.php - ./webfiori/file/UploadFile.php - ./webfiori/file/Uploader.php - ./webfiori/file/exceptions/FileException.php - - - - - - - - ./tests/webfiori/framework/test - - - \ No newline at end of file diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 0000000..40fd6e9 --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,22 @@ + + + + + + + ../webfiori/file/File.php + ../webfiori/file/MIME.php + ../webfiori/file/UploadFile.php + ../webfiori/file/Uploader.php + ../webfiori/file/exceptions/FileException.php + + + + + + + + ./webfiori/framework/test + + + \ No newline at end of file From cc3215d23b852f8ed3678bcb25a0998863f928b6 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 19 Dec 2024 18:01:09 +0300 Subject: [PATCH 05/17] fix: Casting to Integer --- webfiori/file/FileUploader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webfiori/file/FileUploader.php b/webfiori/file/FileUploader.php index 99831de..744b304 100644 --- a/webfiori/file/FileUploader.php +++ b/webfiori/file/FileUploader.php @@ -625,7 +625,7 @@ private function isError(int $code): bool { return false; } case UPLOAD_ERR_INI_SIZE:{ - $this->uploadStatusMessage = 'File Size is Larger Than '.(ini_get('upload_max_filesize') / 1000).'KB. Found in php.ini.'; + $this->uploadStatusMessage = 'File Size is Larger Than '.(intval(ini_get('upload_max_filesize')) / 1000).'KB. Found in php.ini.'; break; } case UPLOAD_ERR_FORM_SIZE:{ From afb27e40454972d8dbb25f18721d9543d7b5c73e Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 19 Dec 2024 18:01:43 +0300 Subject: [PATCH 06/17] ci: Updated CI Configuration --- .github/workflows/php80.yml | 4 ++-- .github/workflows/php81.yml | 10 ++------- .github/workflows/php82.yml | 6 ++---- .github/workflows/php83.yml | 41 ++++++++++++++++++++++++++++--------- release-please-config.json | 22 ++++++++++++++++++++ 5 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 release-please-config.json diff --git a/.github/workflows/php80.yml b/.github/workflows/php80.yml index 9ffd78c..3f9ee67 100644 --- a/.github/workflows/php80.yml +++ b/.github/workflows/php80.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -35,7 +35,7 @@ jobs: run: composer install --prefer-dist --no-interaction - name: Execute Tests - run: phpunit + run: phpunit --configuration tests/phpunit.xml - name: CodeCov uses: codecov/codecov-action@v4 diff --git a/.github/workflows/php81.yml b/.github/workflows/php81.yml index 29b6a88..ec081d3 100644 --- a/.github/workflows/php81.yml +++ b/.github/workflows/php81.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -34,15 +34,9 @@ jobs: run: composer install --prefer-dist --no-interaction - name: Execute Tests - run: phpunit + run: phpunit --configuration tests/phpunit.xml - name: CodeCov uses: codecov/codecov-action@v4 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - - - name: SonarCloud - uses: SonarSource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/php82.yml b/.github/workflows/php82.yml index 1430f75..7b7f1d7 100644 --- a/.github/workflows/php82.yml +++ b/.github/workflows/php82.yml @@ -20,7 +20,7 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -29,14 +29,12 @@ jobs: extensions: mysqli, mbstring, sqlsrv tools: phpunit:9.5.20, composer - - name: Shutdown Ubuntu MySQL - run: sudo service mysql stop - name: Install Dependencies run: composer install --prefer-dist --no-interaction - name: Execute Tests - run: phpunit + run: phpunit --configuration tests/phpunit.xml - name: CodeCov uses: codecov/codecov-action@v4 diff --git a/.github/workflows/php83.yml b/.github/workflows/php83.yml index e2a640b..3aa801a 100644 --- a/.github/workflows/php83.yml +++ b/.github/workflows/php83.yml @@ -4,12 +4,13 @@ on: push: branches: [ main, dev ] pull_request: - branches: [ main ] + branches: [ main, dev ] jobs: + test: runs-on: ${{ matrix.os }} - + strategy: fail-fast: true matrix: @@ -20,25 +21,45 @@ jobs: steps: - name: Clone Repo - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: mysqli, mbstring, sqlsrv - tools: phpunit:9.5.20, composer + tools: phpunit:9.5.20, composer, symplify/easy-coding-standard:12.0.6, phpbench/phpbench:1.2.14 - - name: Shutdown Ubuntu MySQL - run: sudo service mysql stop - - name: Install Dependencies - run: composer install --prefer-dist --no-interaction + run: composer install --prefer-dist --no-interaction --no-dev - name: Execute Tests - run: phpunit + run: phpunit --configuration tests/phpunit.xml - name: CodeCov uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + - name: SonarCloud Code Scan + uses: sonarsource/sonarqube-scan-action@v4 env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + + release_prod: + name: Prepare Production Release Branch / Publish Release + needs: + - "test" + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v4 + - uses: google-github-actions/release-please-action@v3 + with: + release-type: php + config-file: release-please-config.json + token: ${{ secrets.GITHUB_TOKEN }} + + diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..2f70c95 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,22 @@ +{ + "include-v-in-tag":true, + "tag-separator": "-", + "changelog-path": "CHANGELOG.md", + "changelog-sections": [ + { "type": "feat", "section": "Features" }, + { "type": "feature", "section": "Features" }, + { "type": "fix", "section": "Bug Fixes" }, + { "type": "perf", "section": "Performance Improvements" }, + { "type": "revert", "section": "Reverts" }, + { "type": "docs", "section": "Documentation" }, + { "type": "style", "section": "Styles" }, + { "type": "chore", "section": "Miscellaneous Chores" }, + { "type": "refactor", "section": "Code Refactoring" }, + { "type": "test", "section": "Testing" }, + { "type": "build", "section": "Build System" }, + { "type": "ci", "section": "Continuous Integration" }, + { "type": "ui", "section": "User Interface" }, + { "type": "database", "section": "Database Changes" }, + { "type": "email", "section": "Email Notifications Changes" } + ] +} \ No newline at end of file From c3a3d13e10e8556d43af18c46012efb391774067 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 19 Dec 2024 18:03:02 +0300 Subject: [PATCH 07/17] doc: Removed PHP 7 from ReadMe --- README.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5999bf4..ea6a517 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ Basic class library to read, write and view files using PHP.

- - + + @@ -35,15 +35,11 @@ Basic class library to read, write and view files using PHP. ## Supported PHP Versions | Build Status | |:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| -| | -| | -| | -| | -| | | | | | | | | | +| | ## Main Aim of The Library The main aim of the library is to have an OOP abstraction that simplifies most common operations with files in PHP. From 3ce599576607b07853e0385103c8e7371f30dceb Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 19 Dec 2024 18:05:30 +0300 Subject: [PATCH 08/17] fix: Fix New Null Syntax --- webfiori/file/File.php | 2 +- webfiori/file/FileUploader.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/webfiori/file/File.php b/webfiori/file/File.php index 5f8b135..56f7ced 100644 --- a/webfiori/file/File.php +++ b/webfiori/file/File.php @@ -345,7 +345,7 @@ public function getID() { * * @since 1.1.7 */ - public function getLastModified(string $format = null) { + public function getLastModified(?string $format) { if ($this->isExist()) { clearstatcache(); diff --git a/webfiori/file/FileUploader.php b/webfiori/file/FileUploader.php index 744b304..7d05de1 100644 --- a/webfiori/file/FileUploader.php +++ b/webfiori/file/FileUploader.php @@ -537,7 +537,7 @@ private static function extractPathAndName($absPath): array { 'path' => '' ]; } - private function getFileArr($fileOrFiles,$replaceIfExist, $idx = null): array { + private function getFileArr($fileOrFiles,$replaceIfExist, ?string $idx): array { $errIdx = 'error'; $tempIdx = 'tmp_name'; $fileInfoArr = []; From 0c17aae4cd4caea54eeb8b76ed6bb6344874d6c7 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 19 Dec 2024 18:10:13 +0300 Subject: [PATCH 09/17] test: Fix Autoloader Path --- tests/bootstrap.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 68366ed..cb6fa4a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,8 +5,9 @@ ini_set('display_errors', 1); error_reporting(-1); -require_once '../vendor/autoload.php'; define('DS', DIRECTORY_SEPARATOR); +require_once __DIR__.DS.'..'.DS.'vendor'.DS.'autoload.php'; + $testsDirName = 'tests'; $rootDir = substr(__DIR__, 0, strlen(__DIR__) - strlen($testsDirName)); $DS = DIRECTORY_SEPARATOR; From 51ab42a4c30dd893577238139feffbd7a6a47425 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 19 Dec 2024 18:17:19 +0300 Subject: [PATCH 10/17] fix: Small Fix to Last Modified --- tests/webfiori/framework/test/FileTest.php | 2 +- webfiori/file/File.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/webfiori/framework/test/FileTest.php b/tests/webfiori/framework/test/FileTest.php index 85e5981..e3607e1 100644 --- a/tests/webfiori/framework/test/FileTest.php +++ b/tests/webfiori/framework/test/FileTest.php @@ -257,7 +257,7 @@ public function testLastModified00() { public function testLastModified01() { $file = new File('text-file.txt',ROOT_PATH.DS.'tests'.DS.'files'); $time = filemtime($file->getAbsolutePath()); - $this->assertEquals($time, $file->getLastModified()); + $this->assertEquals($time, $file->getLastModified(null)); $this->assertEquals(date('Y-m-d H:i:s', $time), $file->getLastModified('Y-m-d H:i:s')); } /** diff --git a/webfiori/file/File.php b/webfiori/file/File.php index 56f7ced..f5c46cb 100644 --- a/webfiori/file/File.php +++ b/webfiori/file/File.php @@ -345,7 +345,7 @@ public function getID() { * * @since 1.1.7 */ - public function getLastModified(?string $format) { + public function getLastModified(?string $format = 'Y-m-d H:i:s') { if ($this->isExist()) { clearstatcache(); From 951fae906e6083df0cd4ca87e9c3ef512edbdf32 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Sun, 22 Dec 2024 17:49:16 +0300 Subject: [PATCH 11/17] test: Fix for Test Case --- tests/bootstrap.php | 1 + webfiori/file/File.php | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index cb6fa4a..de34ac8 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,6 +6,7 @@ error_reporting(-1); define('DS', DIRECTORY_SEPARATOR); +define('TESTING', true); require_once __DIR__.DS.'..'.DS.'vendor'.DS.'autoload.php'; $testsDirName = 'tests'; diff --git a/webfiori/file/File.php b/webfiori/file/File.php index f5c46cb..8b39531 100644 --- a/webfiori/file/File.php +++ b/webfiori/file/File.php @@ -889,7 +889,10 @@ private function doNotUseClassResponse($contentType, $asAttachment) { } foreach ($headersArr as $h) { - header($h); + //Check if in PHP Unit or not. If in + if (!defined('TESTING') || TESTING === false) { + header($h); + } } echo $this->getRawData(); die(); From 37216ec5d78e01694ef4f3ac36b4a6569dce8711 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Sun, 22 Dec 2024 17:51:09 +0300 Subject: [PATCH 12/17] test: Added Missing Import --- tests/bootstrap.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index de34ac8..70018de 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,7 @@ Date: Sun, 22 Dec 2024 18:07:59 +0300 Subject: [PATCH 13/17] chore: Added Additional Test Case --- .gitignore | 1 + tests/webfiori/framework/test/FileTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 7d18188..e58dad2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ php-cs-fixer.phar clover.xml *.bin tests/files/not-exist/new.txt +tests/webfiori/framework/test/testUpload.txt diff --git a/tests/webfiori/framework/test/FileTest.php b/tests/webfiori/framework/test/FileTest.php index e3607e1..3a6d5c9 100644 --- a/tests/webfiori/framework/test/FileTest.php +++ b/tests/webfiori/framework/test/FileTest.php @@ -134,6 +134,7 @@ public function test08() { $this->assertEquals(['54'], $file->toHexArray()); $file->read(); $this->assertEquals("This is to test if read from same directory is working.\n", $file->getRawData()); + $this->assertEquals('{"id":-1,"mime":"text\/plain","name":"in-dir.txt","directory":"C:\\inetpub\\wwwroot\\dev\\IbrahimSpace\\file\\tests\\webfiori\\framework\\test","sizeInBytes":57,"sizeInKBytes":0.0556640625,"sizeInMBytes":5.4359436035156E-5}', $file.''); } /** * @test From 090d2c5d30c9a2be5bfcc909b22a677cc6eba3fc Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Sun, 22 Dec 2024 18:12:06 +0300 Subject: [PATCH 14/17] test: Added Test for Append --- tests/webfiori/framework/test/FileTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/webfiori/framework/test/FileTest.php b/tests/webfiori/framework/test/FileTest.php index 3a6d5c9..39b6dbe 100644 --- a/tests/webfiori/framework/test/FileTest.php +++ b/tests/webfiori/framework/test/FileTest.php @@ -136,6 +136,21 @@ public function test08() { $this->assertEquals("This is to test if read from same directory is working.\n", $file->getRawData()); $this->assertEquals('{"id":-1,"mime":"text\/plain","name":"in-dir.txt","directory":"C:\\inetpub\\wwwroot\\dev\\IbrahimSpace\\file\\tests\\webfiori\\framework\\test","sizeInBytes":57,"sizeInKBytes":0.0556640625,"sizeInMBytes":5.4359436035156E-5}', $file.''); } + /** + * @test + */ + public function testAppend00() { + $file = new File('text-file-x.txt',ROOT_PATH.DS.'tests'.DS.'files'); + $this->assertEquals('', $file->getRawData()); + $file->append('Hello'); + $this->assertEquals('Hello', $file->getRawData()); + $file->append(' World!'); + $file->append([ + ' More ', + 'Data' + ]); + $this->assertEquals('Hello World! More Data', $file->getRawData()); + } /** * @test */ From 9c31ee11e24e7275be217c029e22f6efa2ccf633 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Sun, 22 Dec 2024 18:26:36 +0300 Subject: [PATCH 15/17] test: Add Missing Files to Coverage --- tests/phpunit.xml | 4 ++-- webfiori/file/FileUploader.php | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 40fd6e9..f01bae4 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -6,8 +6,8 @@ ../webfiori/file/File.php ../webfiori/file/MIME.php - ../webfiori/file/UploadFile.php - ../webfiori/file/Uploader.php + ../webfiori/file/UploadedFile.php + ../webfiori/file/FileUploader.php ../webfiori/file/exceptions/FileException.php diff --git a/webfiori/file/FileUploader.php b/webfiori/file/FileUploader.php index 7d05de1..0b69066 100644 --- a/webfiori/file/FileUploader.php +++ b/webfiori/file/FileUploader.php @@ -628,10 +628,6 @@ private function isError(int $code): bool { $this->uploadStatusMessage = 'File Size is Larger Than '.(intval(ini_get('upload_max_filesize')) / 1000).'KB. Found in php.ini.'; break; } - case UPLOAD_ERR_FORM_SIZE:{ - $this->uploadStatusMessage = 'File Size is Larger Than '.($this->getLimit() / 1000).'KB'; - break; - } case UPLOAD_ERR_PARTIAL:{ $this->uploadStatusMessage = 'File Uploaded Partially'; break; @@ -649,7 +645,7 @@ private function isError(int $code): bool { break; } default :{ - $this->uploadStatusMessage = 'No File was Uploaded'; + $this->uploadStatusMessage = 'No File was Uploaded due to uknown error'; } } From d4164302e156bd21e33acfcb931bac7d31d9537d Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Sun, 22 Dec 2024 18:31:51 +0300 Subject: [PATCH 16/17] test: Fix Test Case --- tests/webfiori/framework/test/FileTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/webfiori/framework/test/FileTest.php b/tests/webfiori/framework/test/FileTest.php index 39b6dbe..a05eef3 100644 --- a/tests/webfiori/framework/test/FileTest.php +++ b/tests/webfiori/framework/test/FileTest.php @@ -134,7 +134,7 @@ public function test08() { $this->assertEquals(['54'], $file->toHexArray()); $file->read(); $this->assertEquals("This is to test if read from same directory is working.\n", $file->getRawData()); - $this->assertEquals('{"id":-1,"mime":"text\/plain","name":"in-dir.txt","directory":"C:\\inetpub\\wwwroot\\dev\\IbrahimSpace\\file\\tests\\webfiori\\framework\\test","sizeInBytes":57,"sizeInKBytes":0.0556640625,"sizeInMBytes":5.4359436035156E-5}', $file.''); + $this->assertEquals('{"id":-1,"mime":"text\/plain","name":"in-dir.txt","directory":"'.Json::escapeJSONSpecialChars($file->getDir()).'","sizeInBytes":'.$file->getSize().',"sizeInKBytes":'.($file->getSize() / 1024).',"sizeInMBytes":'.(($file->getSize() / 1024) / 1024).'}', $file.''); } /** * @test From 247c9673ef312d877ea503d73fba0a71395b5b62 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Sun, 22 Dec 2024 18:57:58 +0300 Subject: [PATCH 17/17] Update FileUploader.php --- webfiori/file/FileUploader.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/webfiori/file/FileUploader.php b/webfiori/file/FileUploader.php index 0b69066..cccf873 100644 --- a/webfiori/file/FileUploader.php +++ b/webfiori/file/FileUploader.php @@ -607,6 +607,27 @@ private function getFileArr($fileOrFiles,$replaceIfExist, ?string $idx): array { return $fileInfoArr; } + /** + * Returns the value of the directive 'upload_max_filesize' in KB. + * + * @return int + */ + public static function getMaxFileSize() : int { + $val = ini_get('upload_max_filesize'); + $lastChar = strtoupper($val[strlen($val) - 1]); + + switch ($lastChar) { + case 'M' : { + return intval($val) * 1000; + } case 'K' : { + return intval($val); + } case 'G' : { + return intval($val) * 1000000; + } default : { + return intval($val) / 1000; + } + } + } /** * Checks if PHP upload code is error or not. * @@ -625,7 +646,7 @@ private function isError(int $code): bool { return false; } case UPLOAD_ERR_INI_SIZE:{ - $this->uploadStatusMessage = 'File Size is Larger Than '.(intval(ini_get('upload_max_filesize')) / 1000).'KB. Found in php.ini.'; + $this->uploadStatusMessage = 'File Size is Larger Than '.(self::getMaxFileSize()).'KB. Found in php.ini.'; break; } case UPLOAD_ERR_PARTIAL:{