From d24b5d4f554213398f298e6ff69c87bf390f840c Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Thu, 23 Jul 2026 08:37:43 -0400 Subject: [PATCH] Add support for guzzlehttp/psr7 3.0 --- composer.json | 2 +- tests/Helpers/Constraints/FormFileConstraint.php | 12 ++++++++---- .../Helpers/Constraints/FormValueConstraint.php | 16 +++++++++------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index de589e2..a2c76fc 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "php": "^8.1|^8.2|^8.3|^8.4|^8.5", "ext-json": "*", "ext-mbstring": "*", - "guzzlehttp/psr7": "^1 || ^2.1", + "guzzlehttp/psr7": "^1 || ^2.1 || ^3", "php-http/discovery": "^1.14", "psr/http-client": "^1.0", "psr/http-message": "^1.0|^2.0" diff --git a/tests/Helpers/Constraints/FormFileConstraint.php b/tests/Helpers/Constraints/FormFileConstraint.php index 2cf9767..84cbaed 100644 --- a/tests/Helpers/Constraints/FormFileConstraint.php +++ b/tests/Helpers/Constraints/FormFileConstraint.php @@ -4,8 +4,10 @@ namespace Gotenberg\Test\Helpers\Constraints; +use GuzzleHttp\Psr7\DiagnosticValue; use PHPUnit\Framework\Constraint\Constraint; +use function class_exists; use function is_string; use function mb_strlen; use function sprintf; @@ -27,14 +29,16 @@ protected function matches(mixed $other): bool return false; } - $length = mb_strlen($this->content); - $needle = 'Content-Disposition: form-data; name="' . $this->fieldName . '"; filename="' . $this->filename - . '" Content-Length: ' - . $length; + . '"'; + + // guzzlehttp/psr7:^3.0 removed the non-standard Content-Length header from multipart/form-data parts + if (! class_exists(DiagnosticValue::class)) { + $needle .= ' Content-Length: ' . mb_strlen($this->content); + } if ($this->contentType !== null) { $needle .= ' Content-Type: ' . $this->contentType; diff --git a/tests/Helpers/Constraints/FormValueConstraint.php b/tests/Helpers/Constraints/FormValueConstraint.php index 75d27ef..67d9d97 100644 --- a/tests/Helpers/Constraints/FormValueConstraint.php +++ b/tests/Helpers/Constraints/FormValueConstraint.php @@ -4,8 +4,10 @@ namespace Gotenberg\Test\Helpers\Constraints; +use GuzzleHttp\Psr7\DiagnosticValue; use PHPUnit\Framework\Constraint\Constraint; +use function class_exists; use function is_string; use function mb_strlen; use function sprintf; @@ -25,14 +27,14 @@ protected function matches(mixed $other): bool return false; } - $length = mb_strlen($this->value); + $needle = 'Content-Disposition: form-data; name="' . $this->name . '"'; - $needle = 'Content-Disposition: form-data; name="' - . $this->name - . '" Content-Length: ' - . $length - . ' ' - . $this->value; + // guzzlehttp/psr7:^3.0 removed the non-standard Content-Length header from multipart/form-data parts + if (! class_exists(DiagnosticValue::class)) { + $needle .= ' Content-Length: ' . mb_strlen($this->value); + } + + $needle .= ' ' . $this->value; return str_contains($other, $needle); }