diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index cd5e7b7..e39ff08 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -15,7 +15,6 @@ jobs: operating-system: - ubuntu-latest php-version: - - '8.1' - '8.2' - '8.3' - '8.4' diff --git a/CHANGELOG.md b/CHANGELOG.md index cc15b70..c97e3e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed +- Require PHP 8.2 or later. PHP 8.1 is no longer supported. +- Dev dependency `koriym/file-upload` is now `^1.0.1`. + ## [1.1.0] - 2026-05-02 ### Added diff --git a/composer.json b/composer.json index 15f69f3..7c01bd2 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "php": "^8.1", + "php": "^8.2", "ray/di": "^2.18", "symfony/polyfill-php83": "^1.28" }, @@ -19,7 +19,7 @@ "require-dev": { "bamarni/composer-bin-plugin": "^1.8", "phpunit/phpunit": "^10.5", - "koriym/file-upload": "^0.2.0" + "koriym/file-upload": "^1.0.1" }, "autoload": { "psr-4": { diff --git a/tests/FileUploadFactoryTest.php b/tests/FileUploadFactoryTest.php index 64cffd0..a9fadb9 100644 --- a/tests/FileUploadFactoryTest.php +++ b/tests/FileUploadFactoryTest.php @@ -9,6 +9,11 @@ use PHPUnit\Framework\TestCase; use ReflectionMethod; +use function file_put_contents; +use function sys_get_temp_dir; +use function tempnam; +use function unlink; + use const UPLOAD_ERR_NO_FILE; use const UPLOAD_ERR_OK; @@ -26,12 +31,15 @@ public function testCreateFromFiles(): void $method = new ReflectionMethod($this, 'dummyMethodForFileUpload'); $param = $method->getParameters()[0]; + $tmpName = tempnam(sys_get_temp_dir(), 'iq'); + file_put_contents($tmpName, 'plain text'); + $filesData = [ 'upload' => [ 'name' => 'test.txt', 'type' => 'text/plain', 'size' => 100, - 'tmp_name' => '/tmp/test', + 'tmp_name' => $tmpName, 'error' => UPLOAD_ERR_OK, ], ]; @@ -42,6 +50,7 @@ public function testCreateFromFiles(): void ]; $result = $this->factory->createFromFiles($param, $filesData, $validationOptions); + unlink($tmpName); $this->assertInstanceOf(FileUpload::class, $result); } diff --git a/tests/InputFileTest.php b/tests/InputFileTest.php index b5ab1fd..c7f54d7 100644 --- a/tests/InputFileTest.php +++ b/tests/InputFileTest.php @@ -16,6 +16,11 @@ use Ray\InputQuery\Fake\InputFileWithOptionsInput; use Ray\InputQuery\Fake\MultipleInputFileAttributesInput; +use function file_put_contents; +use function sys_get_temp_dir; +use function tempnam; +use function unlink; + use const UPLOAD_ERR_OK; final class InputFileTest extends TestCase @@ -102,6 +107,21 @@ public function testFileValidationMaxSizeError(): void $this->assertStringContainsString('File size exceeds maximum allowed size', $input->avatar->message); } + private const JPEG = "\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xFF\xD9"; + private const PDF = "%PDF-1.4\n%%EOF\n"; + + /** @var list */ + private array $tempFiles = []; + + private function tempFile(string $content): string + { + $file = tempnam(sys_get_temp_dir(), 'iq'); + file_put_contents($file, $content); + $this->tempFiles[] = $file; + + return $file; + } + public function testFileValidationTypeError(): void { // Simulate $_FILES data with wrong type @@ -109,7 +129,7 @@ public function testFileValidationTypeError(): void 'name' => 'document.pdf', 'type' => 'application/pdf', 'size' => 500, - 'tmp_name' => '/tmp/document', + 'tmp_name' => $this->tempFile(self::PDF), 'error' => UPLOAD_ERR_OK, ]; @@ -129,7 +149,7 @@ public function testFileValidationSuccess(): void 'name' => 'small.jpg', 'type' => 'image/jpeg', 'size' => 500, - 'tmp_name' => '/tmp/small', + 'tmp_name' => $this->tempFile(self::JPEG), 'error' => UPLOAD_ERR_OK, ]; @@ -149,7 +169,7 @@ public function testFileValidationExtensionError(): void 'name' => 'document.pdf', 'type' => 'image/jpeg', // Valid type but invalid extension 'size' => 500, - 'tmp_name' => '/tmp/document', + 'tmp_name' => $this->tempFile(self::JPEG), 'error' => UPLOAD_ERR_OK, ]; @@ -169,7 +189,7 @@ public function testFileValidationExtensionSuccess(): void 'name' => 'image.jpg', 'type' => 'image/jpeg', 'size' => 500, - 'tmp_name' => '/tmp/image', + 'tmp_name' => $this->tempFile(self::JPEG), 'error' => UPLOAD_ERR_OK, ]; @@ -188,7 +208,7 @@ public function testFileValidationExtensionCaseInsensitive(): void 'name' => 'image.JPG', // Uppercase extension 'type' => 'image/jpeg', 'size' => 500, - 'tmp_name' => '/tmp/image', + 'tmp_name' => $this->tempFile(self::JPEG), 'error' => UPLOAD_ERR_OK, ]; @@ -221,7 +241,9 @@ public function testConflictingInputAndInputFileAttributesThrowsException(): voi protected function tearDown(): void { - // Clean up $_FILES $_FILES = []; + foreach ($this->tempFiles as $file) { + @unlink($file); + } } }