From ddd7fa81cee72bdceaa163ea7d93fe84afda4286 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 1 Dec 2025 13:43:01 +0100 Subject: [PATCH 1/3] Upgrade package `guzzlehttp/psr7` Streamline with https://github.com/Icinga/icinga-php-thirdparty/pull/82 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 260b7d9..30d04c9 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } }, "require-dev": { - "guzzlehttp/psr7": "^1", + "guzzlehttp/psr7": "^2.8", "ipl/stdlib": "dev-main", "ipl/i18n": "dev-main" } From f3466dae7d50be7ad2528ba697df3bbc74992968 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 4 Dec 2025 09:56:53 +0100 Subject: [PATCH 2/3] Replace deprecated methods of `SplObjectStorage` https://www.php.net/manual/en/migration85.deprecated.php#migration85.deprecated.spl --- src/ValidatorChain.php | 6 +++--- tests/ValidatorChainTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ValidatorChain.php b/src/ValidatorChain.php index 1044498..3917d2b 100644 --- a/src/ValidatorChain.php +++ b/src/ValidatorChain.php @@ -68,7 +68,7 @@ public function add(Validator $validator, $breakChainOnFailure = false, $priorit $this->validators->insert($validator, $priority); if ($breakChainOnFailure) { - $this->validatorsThatBreakTheChain->attach($validator); + $this->validatorsThatBreakTheChain->offsetSet($validator); } return $this; @@ -227,7 +227,7 @@ public function merge(ValidatorChain $validatorChain) * @var Validator $validator */ foreach ($validatorChain->validators->yieldAll() as $priority => $validator) { - $this->add($validator, $validatorsThatBreakTheChain->contains($validator), $priority); + $this->add($validator, $validatorsThatBreakTheChain->offsetExists($validator), $priority); } return $this; @@ -282,7 +282,7 @@ public function isValid($value): bool $this->addMessages($validator->getMessages()); - if ($this->validatorsThatBreakTheChain->contains($validator)) { + if ($this->validatorsThatBreakTheChain->offsetExists($validator)) { break; } } diff --git a/tests/ValidatorChainTest.php b/tests/ValidatorChainTest.php index 59224ac..f2544e2 100644 --- a/tests/ValidatorChainTest.php +++ b/tests/ValidatorChainTest.php @@ -273,7 +273,7 @@ public function testMerge() $this->assertSame($callbackValidator, $validatorsAsArray[0]); $this->assertInstanceOf(TestValidator::class, $validatorsAsArray[1]); $this->assertInstanceOf(CallbackValidator::class, $validatorsAsArray[2]); - $this->assertTrue($validators->getValidatorsThatBreakTheChain()->contains($callbackValidator)); + $this->assertTrue($validators->getValidatorsThatBreakTheChain()->offsetExists($callbackValidator)); } public function testArraySpecExceptionIfNameIsMissing() From 58f440c6c830aa11ead5a192b485e41cf3d7d83f Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 15 Dec 2025 09:33:43 +0100 Subject: [PATCH 3/3] Don't depend on `guzzlehttp/psr7` just for testing Otherwise, we would have to increase `guzzlehttp/psr7` (ddd7fa8) to support recent PHP versions. This is a bit excessive for a library from which we only need a single class exclusively for testing: The `UploadedFile` class was only used to test our `FileValidator` and is now replaced by a minimal implementation of `PSR-7#UploadedFileInterface`. --- composer.json | 1 - tests/FileValidatorTest.php | 69 +++++++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 30d04c9..97048ae 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,6 @@ } }, "require-dev": { - "guzzlehttp/psr7": "^2.8", "ipl/stdlib": "dev-main", "ipl/i18n": "dev-main" } diff --git a/tests/FileValidatorTest.php b/tests/FileValidatorTest.php index 92d0f9c..bb3e5ca 100644 --- a/tests/FileValidatorTest.php +++ b/tests/FileValidatorTest.php @@ -2,22 +2,69 @@ namespace ipl\Tests\Validator; -use GuzzleHttp\Psr7\UploadedFile; use ipl\I18n\NoopTranslator; use ipl\I18n\StaticTranslator; use ipl\Validator\FileValidator; +use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\UploadedFileInterface; +use RuntimeException; class FileValidatorTest extends TestCase { - public function createUploadedFileObject($mimeType = 'application/pdf'): UploadedFile - { - return new UploadedFile( - 'test/test.pdf', - 500, - 0, - 'test.pdf', - $mimeType - ); + public function createUploadedFileObject( + string $filename = 'test.pdf', + int $size = 500, + int $error = UPLOAD_ERR_OK, + string $mimeType = 'application/pdf' + ): UploadedFileInterface { + return new class ($filename, $size, $error, $mimeType) implements UploadedFileInterface { + private readonly int $size; + private readonly int $error; + private readonly string $clientFilename; + private readonly string $clientMediaType; + + public function __construct( + string $clientFilename, + int $size, + int $error, + string $clientMediaType + ) { + $this->size = $size; + $this->error = $error; + $this->clientFilename = $clientFilename; + $this->clientMediaType = $clientMediaType; + } + + public function getStream(): StreamInterface + { + throw new RuntimeException('not implemented'); + } + + public function moveTo(string $targetPath): void + { + throw new RuntimeException('not implemented'); + } + + public function getSize(): ?int + { + return $this->size; + } + + public function getError(): int + { + return $this->error; + } + + public function getClientFilename(): ?string + { + return $this->clientFilename; + } + + public function getClientMediaType(): ?string + { + return $this->clientMediaType; + } + }; } public function testValidValue(): void @@ -89,7 +136,7 @@ public function testMimeTypeOption(): void $this->assertTrue($validator->isValid($uploadedFile)); $validator->setAllowedMimeTypes(['image/gif', 'image/jpeg']); - $uploadedFile = $this->createUploadedFileObject('image/png'); + $uploadedFile = $this->createUploadedFileObject(mimeType: 'image/png'); $this->assertFalse($validator->isValid($uploadedFile)); }