Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
operating-system:
- ubuntu-latest
php-version:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.2",
"ray/di": "^2.18",
"symfony/polyfill-php83": "^1.28"
},
Expand All @@ -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": {
Expand Down
11 changes: 10 additions & 1 deletion tests/FileUploadFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
],
];
Expand All @@ -42,6 +50,7 @@ public function testCreateFromFiles(): void
];

$result = $this->factory->createFromFiles($param, $filesData, $validationOptions);
unlink($tmpName);

$this->assertInstanceOf(FileUpload::class, $result);
}
Expand Down
34 changes: 28 additions & 6 deletions tests/InputFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,14 +107,29 @@ 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<string> */
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
$_FILES['avatar'] = [
'name' => 'document.pdf',
'type' => 'application/pdf',
'size' => 500,
'tmp_name' => '/tmp/document',
'tmp_name' => $this->tempFile(self::PDF),
'error' => UPLOAD_ERR_OK,
];

Expand All @@ -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,
];

Expand All @@ -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,
];

Expand All @@ -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,
];

Expand All @@ -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,
];

Expand Down Expand Up @@ -221,7 +241,9 @@ public function testConflictingInputAndInputFileAttributesThrowsException(): voi

protected function tearDown(): void
{
// Clean up $_FILES
$_FILES = [];
foreach ($this->tempFiles as $file) {
@unlink($file);
}
}
}
Loading