diff --git a/composer.json b/composer.json index 48919f1c..a9fa4bf6 100644 --- a/composer.json +++ b/composer.json @@ -24,9 +24,9 @@ "php": ">=7.2", "ext-json": "*", "devizzent/cebe-php-openapi": "^1.0", - "league/uri": "^6.3", + "league/uri": "^6.3 || ^7.0", "psr/cache": "^1.0 || ^2.0 || ^3.0", - "psr/http-message": "^1.0", + "psr/http-message": "^1.0 || ^2.0", "psr/http-server-middleware": "^1.0", "respect/validation": "^1.1.3 || ^2.0", "riverline/multipart-parser": "^2.0.3", @@ -35,8 +35,8 @@ }, "require-dev": { "doctrine/coding-standard": "^8.0", - "guzzlehttp/psr7": "^1.5", - "hansott/psr7-cookies": "^3.0.2", + "guzzlehttp/psr7": "^2.0", + "hansott/psr7-cookies": "^3.0.2 || ^4.0", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^1", "phpstan/phpstan-phpunit": "^1", diff --git a/phpstan.neon b/phpstan.neon index 90669f82..da958806 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,5 +5,6 @@ parameters: - src - tests treatPhpDocTypesAsCertain: false + reportUnmatchedIgnoredErrors: false ignoreErrors: - '#Call to an undefined static method Respect\\Validation\\Validator::numeric\(\).#' diff --git a/src/Schema/TypeFormats/StringURI.php b/src/Schema/TypeFormats/StringURI.php index 8d4bdca9..104998e8 100644 --- a/src/Schema/TypeFormats/StringURI.php +++ b/src/Schema/TypeFormats/StringURI.php @@ -12,6 +12,8 @@ class StringURI public function __invoke(string $value): bool { try { + // namespace 'League\Uri' is provided by multiple packages, but PHPStan does not support merging them + // @phpstan-ignore-next-line UriString::parse($value); return true; diff --git a/tests/FromCommunity/EmptyObjectValidationTest.php b/tests/FromCommunity/EmptyObjectValidationTest.php index 4a840dac..2f23c9d4 100644 --- a/tests/FromCommunity/EmptyObjectValidationTest.php +++ b/tests/FromCommunity/EmptyObjectValidationTest.php @@ -5,11 +5,10 @@ namespace League\OpenAPIValidation\Tests\FromCommunity; use GuzzleHttp\Psr7\ServerRequest; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\ValidatorBuilder; use PHPUnit\Framework\TestCase; -use function GuzzleHttp\Psr7\stream_for; - final class EmptyObjectValidationTest extends TestCase { /** @@ -40,7 +39,7 @@ public function testIssue57000(): void $psrRequest = (new ServerRequest('post', 'http://localhost:8000/api/v1/products.create')) ->withHeader('Content-Type', 'application/json') - ->withBody(stream_for('{}')); + ->withBody(Utils::streamFor('{}')); $validator->validate($psrRequest); diff --git a/tests/FromCommunity/Issue12Test.php b/tests/FromCommunity/Issue12Test.php index 0781c462..6e7f68cb 100644 --- a/tests/FromCommunity/Issue12Test.php +++ b/tests/FromCommunity/Issue12Test.php @@ -5,10 +5,10 @@ namespace League\OpenAPIValidation\Tests\FromCommunity; use GuzzleHttp\Psr7\ServerRequest; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\ValidatorBuilder; use PHPUnit\Framework\TestCase; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; final class Issue12Test extends TestCase @@ -61,7 +61,7 @@ public function testIssue12(?array $example): void $psrRequest = (new ServerRequest('post', 'http://localhost:8000/api/v1/products.create')) ->withHeader('Content-Type', 'application/json') - ->withBody(stream_for(json_encode(['test' => $example]))); + ->withBody(Utils::streamFor(json_encode(['test' => $example]))); $validator->validate($psrRequest); diff --git a/tests/FromCommunity/Issue32Test.php b/tests/FromCommunity/Issue32Test.php index dc91c7cc..52178081 100644 --- a/tests/FromCommunity/Issue32Test.php +++ b/tests/FromCommunity/Issue32Test.php @@ -5,11 +5,11 @@ namespace League\OpenAPIValidation\Tests\FromCommunity; use GuzzleHttp\Psr7\ServerRequest; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\Exception\ValidationFailed; use League\OpenAPIValidation\PSR7\ValidatorBuilder; use PHPUnit\Framework\TestCase; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; final class Issue32Test extends TestCase @@ -51,7 +51,7 @@ enum: $psrRequest = (new ServerRequest('post', 'http://localhost:8000/api/test/create')) ->withHeader('Content-Type', 'application/json') - ->withBody(stream_for(json_encode($data))); + ->withBody(Utils::streamFor(json_encode($data))); $serverRequestValidator = (new ValidatorBuilder())->fromYaml($yaml)->getServerRequestValidator(); diff --git a/tests/FromCommunity/Issue3Test.php b/tests/FromCommunity/Issue3Test.php index ae781a7c..80dbc340 100644 --- a/tests/FromCommunity/Issue3Test.php +++ b/tests/FromCommunity/Issue3Test.php @@ -5,10 +5,10 @@ namespace League\OpenAPIValidation\Tests\FromCommunity; use GuzzleHttp\Psr7\ServerRequest; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\ValidatorBuilder; use PHPUnit\Framework\TestCase; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; final class Issue3Test extends TestCase @@ -52,7 +52,7 @@ public function testIssue3(): void $psrRequest = (new ServerRequest('post', 'http://localhost:8000/api/v1/products.create')) ->withHeader('Content-Type', 'application/json') - ->withBody(stream_for(json_encode(['test' => 20]))); + ->withBody(Utils::streamFor(json_encode(['test' => 20]))); $validator->validate($psrRequest); diff --git a/tests/FromCommunity/Issue50Test.php b/tests/FromCommunity/Issue50Test.php index 1c3846de..bcf7a23a 100644 --- a/tests/FromCommunity/Issue50Test.php +++ b/tests/FromCommunity/Issue50Test.php @@ -5,12 +5,12 @@ namespace League\OpenAPIValidation\Tests\FromCommunity; use GuzzleHttp\Psr7\ServerRequest; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidBody; use League\OpenAPIValidation\PSR7\ValidatorBuilder; use League\OpenAPIValidation\Schema\Exception\KeywordMismatch; use PHPUnit\Framework\TestCase; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; final class Issue50Test extends TestCase @@ -54,7 +54,7 @@ public function testIssue50(): void $psrRequest = (new ServerRequest('post', 'http://localhost:8000/api/v1/products.create')) ->withHeader('Content-Type', 'application/json') ->withBody( - stream_for( + Utils::streamFor( json_encode( [ 'body' => diff --git a/tests/FromCommunity/Issue57Test.php b/tests/FromCommunity/Issue57Test.php index f1126259..affba4df 100644 --- a/tests/FromCommunity/Issue57Test.php +++ b/tests/FromCommunity/Issue57Test.php @@ -5,10 +5,10 @@ namespace League\OpenAPIValidation\Tests\FromCommunity; use GuzzleHttp\Psr7\ServerRequest; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\ValidatorBuilder; use PHPUnit\Framework\TestCase; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; final class Issue57Test extends TestCase @@ -60,7 +60,7 @@ public function testIssue57(): void $psrRequest = (new ServerRequest('post', 'http://localhost:8000/api/v1/products.create')) ->withHeader('Content-Type', 'application/json') - ->withBody(stream_for(json_encode(['test' => (object) ['some_property_here' => (object) []]]))); + ->withBody(Utils::streamFor(json_encode(['test' => (object) ['some_property_here' => (object) []]]))); $validator->validate($psrRequest); diff --git a/tests/PSR7/BaseValidatorTest.php b/tests/PSR7/BaseValidatorTest.php index bb794e22..6f4e841b 100644 --- a/tests/PSR7/BaseValidatorTest.php +++ b/tests/PSR7/BaseValidatorTest.php @@ -8,6 +8,7 @@ use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\ServerRequest; use GuzzleHttp\Psr7\Uri; +use GuzzleHttp\Psr7\Utils; use HansOtt\PSR7Cookies\SetCookie; use InvalidArgumentException; use PHPUnit\Framework\TestCase; @@ -15,7 +16,6 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; use function sprintf; @@ -33,7 +33,7 @@ protected function makeGoodResponse(string $path, string $method): ResponseInter return (new Response()) ->withHeader('Content-Type', 'application/json') ->withHeader('Header-B', 'good value') - ->withBody(stream_for(json_encode($body))); + ->withBody(Utils::streamFor(json_encode($body))); case 'post /cookies': $response = (new Response()) @@ -72,7 +72,7 @@ protected function makeGoodServerRequest(string $path, string $method): ServerRe return $request ->withHeader('Content-Type', 'application/json') - ->withBody(stream_for(json_encode($body))); + ->withBody(Utils::streamFor(json_encode($body))); default: throw new InvalidArgumentException(sprintf("unexpected operation '%s %s''", $method, $path)); @@ -104,7 +104,7 @@ protected function makeGoodRequest(string $path, string $method): RequestInterfa return $request ->withHeader('Content-Type', 'application/json') - ->withBody(stream_for(json_encode($body))); + ->withBody(Utils::streamFor(json_encode($body))); default: throw new InvalidArgumentException(sprintf("unexpected operation '%s %s''", $method, $path)); diff --git a/tests/PSR7/CompleteTest.php b/tests/PSR7/CompleteTest.php index 0fe2c267..24f2b29e 100644 --- a/tests/PSR7/CompleteTest.php +++ b/tests/PSR7/CompleteTest.php @@ -6,13 +6,13 @@ use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\ServerRequest; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\OperationAddress; use League\OpenAPIValidation\PSR7\ValidatorBuilder; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; use const PHP_INT_MAX; @@ -56,13 +56,13 @@ protected function buildGoodRequest(): ServerRequestInterface ->withCookieParams(['session_id' => 100]) ->withHeader('X-RequestId', 'abcd') ->withHeader('Content-Type', 'application/json') - ->withBody(stream_for(json_encode(['propB' => 'good value']))); + ->withBody(Utils::streamFor(json_encode(['propB' => 'good value']))); } protected function buildGoodResponse(): ResponseInterface { return (new Response()) ->withHeader('Content-Type', 'application/json') - ->withBody(stream_for(json_encode(['propA' => PHP_INT_MAX]))); + ->withBody(Utils::streamFor(json_encode(['propA' => PHP_INT_MAX]))); } } diff --git a/tests/PSR7/RequestTest.php b/tests/PSR7/RequestTest.php index 5f652aab..4915e8e5 100644 --- a/tests/PSR7/RequestTest.php +++ b/tests/PSR7/RequestTest.php @@ -4,12 +4,12 @@ namespace League\OpenAPIValidation\Tests\PSR7; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidBody; use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidHeaders; use League\OpenAPIValidation\PSR7\OperationAddress; use League\OpenAPIValidation\PSR7\ValidatorBuilder; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; final class RequestTest extends BaseValidatorTest @@ -27,7 +27,7 @@ public function testItValidatesBodyGreen(): void { $body = ['name' => 'Alex']; $request = $this->makeGoodRequest('/request-body', 'post') - ->withBody(stream_for(json_encode($body))); + ->withBody(Utils::streamFor(json_encode($body))); $validator = (new ValidatorBuilder())->fromYamlFile($this->apiSpecFile)->getRequestValidator(); $validator->validate($request); @@ -39,7 +39,7 @@ public function testItValidatesBodyHasInvalidPayloadRed(): void $addr = new OperationAddress('/request-body', 'post'); $body = ['name' => 1000]; $request = $this->makeGoodRequest($addr->path(), $addr->method()) - ->withBody(stream_for(json_encode($body))); + ->withBody(Utils::streamFor(json_encode($body))); $this->expectException(InvalidBody::class); $this->expectExceptionMessage( diff --git a/tests/PSR7/RoutedServerRequestTest.php b/tests/PSR7/RoutedServerRequestTest.php index cc862c25..8d650062 100644 --- a/tests/PSR7/RoutedServerRequestTest.php +++ b/tests/PSR7/RoutedServerRequestTest.php @@ -4,12 +4,12 @@ namespace League\OpenAPIValidation\Tests\PSR7; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidBody; use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidHeaders; use League\OpenAPIValidation\PSR7\OperationAddress; use League\OpenAPIValidation\PSR7\ValidatorBuilder; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; final class RoutedServerRequestTest extends BaseValidatorTest @@ -27,7 +27,7 @@ public function testItValidatesBodyGreen(): void { $body = ['name' => 'Alex']; $request = $this->makeGoodServerRequest('/request-body', 'post') - ->withBody(stream_for(json_encode($body))); + ->withBody(Utils::streamFor(json_encode($body))); $validator = (new ValidatorBuilder())->fromYamlFile($this->apiSpecFile)->getRoutedRequestValidator(); $validator->validate(new OperationAddress('/request-body', 'post'), $request); @@ -39,7 +39,7 @@ public function testItValidatesBodyHasInvalidPayloadRed(): void $addr = new OperationAddress('/request-body', 'post'); $body = ['name' => 1000]; $request = $this->makeGoodServerRequest($addr->path(), $addr->method()) - ->withBody(stream_for(json_encode($body))); + ->withBody(Utils::streamFor(json_encode($body))); $this->expectException(InvalidBody::class); $this->expectExceptionMessage( diff --git a/tests/PSR7/ServerRequestTest.php b/tests/PSR7/ServerRequestTest.php index 679d57e6..191a4c7b 100644 --- a/tests/PSR7/ServerRequestTest.php +++ b/tests/PSR7/ServerRequestTest.php @@ -4,12 +4,12 @@ namespace League\OpenAPIValidation\Tests\PSR7; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidBody; use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidHeaders; use League\OpenAPIValidation\PSR7\OperationAddress; use League\OpenAPIValidation\PSR7\ValidatorBuilder; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; final class ServerRequestTest extends BaseValidatorTest @@ -27,7 +27,7 @@ public function testItValidatesBodyGreen(): void { $body = ['name' => 'Alex']; $request = $this->makeGoodServerRequest('/request-body', 'post') - ->withBody(stream_for(json_encode($body))); + ->withBody(Utils::streamFor(json_encode($body))); $validator = (new ValidatorBuilder())->fromYamlFile($this->apiSpecFile)->getServerRequestValidator(); $validator->validate($request); @@ -39,7 +39,7 @@ public function testItValidatesBodyHasInvalidPayloadRed(): void $addr = new OperationAddress('/request-body', 'post'); $body = ['name' => 1000]; $request = $this->makeGoodServerRequest($addr->path(), $addr->method()) - ->withBody(stream_for(json_encode($body))); + ->withBody(Utils::streamFor(json_encode($body))); $this->expectException(InvalidBody::class); $this->expectExceptionMessage( diff --git a/tests/PSR7/ValidateResponseTest.php b/tests/PSR7/ValidateResponseTest.php index 28b75d26..c1eacf9c 100644 --- a/tests/PSR7/ValidateResponseTest.php +++ b/tests/PSR7/ValidateResponseTest.php @@ -5,12 +5,12 @@ namespace League\OpenAPIValidation\Tests\PSR7; use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Utils; use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidBody; use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidHeaders; use League\OpenAPIValidation\PSR7\OperationAddress; use League\OpenAPIValidation\PSR7\ValidatorBuilder; -use function GuzzleHttp\Psr7\stream_for; use function json_encode; final class ValidateResponseTest extends BaseValidatorTest @@ -32,7 +32,7 @@ public function testItValidatesMessageWithReferencesGreen(): void ]; $response = (new Response()) ->withHeader('Content-Type', 'application/json') - ->withBody(stream_for(json_encode($body))); + ->withBody(Utils::streamFor(json_encode($body))); $validator = (new ValidatorBuilder())->fromYamlFile($this->apiSpecFile)->getResponseValidator(); $validator->validate(new OperationAddress('/ref', 'post'), $response); @@ -43,7 +43,7 @@ public function testItValidatesBinaryResponseGreen(): void { $response = $this->makeGoodResponse('/path1', 'get') ->withHeader('Content-Type', 'image/jpeg') - ->withBody(stream_for(__DIR__ . '/../stubs/image.jpg')); + ->withBody(Utils::streamFor(__DIR__ . '/../stubs/image.jpg')); $validator = (new ValidatorBuilder())->fromYamlFile($this->apiSpecFile)->getResponseValidator(); $validator->validate(new OperationAddress('/path1', 'get'), $response); @@ -54,7 +54,7 @@ public function testItValidatesMessageWrongBodyValueRed(): void { $addr = new OperationAddress('/path1', 'get'); $body = []; - $response = $this->makeGoodResponse('/path1', 'get')->withBody(stream_for(json_encode($body))); + $response = $this->makeGoodResponse('/path1', 'get')->withBody(Utils::streamFor(json_encode($body))); $this->expectException(InvalidBody::class); $this->expectExceptionMessage( diff --git a/tests/PSR7/Validators/BodyValidator/MultipartValidatorTest.php b/tests/PSR7/Validators/BodyValidator/MultipartValidatorTest.php index e93300c0..2e2580e6 100644 --- a/tests/PSR7/Validators/BodyValidator/MultipartValidatorTest.php +++ b/tests/PSR7/Validators/BodyValidator/MultipartValidatorTest.php @@ -4,6 +4,7 @@ namespace League\OpenAPIValidation\Tests\PSR7\Validators\BodyValidator; +use GuzzleHttp\Psr7\Message; use GuzzleHttp\Psr7\ServerRequest; use GuzzleHttp\Psr7\UploadedFile; use GuzzleHttp\Psr7\Uri; @@ -14,7 +15,6 @@ use Psr\Http\Message\UploadedFileInterface; use function filesize; -use function GuzzleHttp\Psr7\parse_request; class MultipartValidatorTest extends TestCase { @@ -388,7 +388,7 @@ public function testValidateMultipartGreen(string $message): void { $specFile = __DIR__ . '/../../../stubs/multipart.yaml'; - $request = parse_request($message); // convert a text HTTP message to a PSR7 message + $request = Message::parseRequest($message); // convert a text HTTP message to a PSR7 message $serverRequest = new ServerRequest( $request->getMethod(), $request->getUri(), @@ -410,7 +410,7 @@ public function testValidateMultipartRed(string $message, string $expectedExcept $specFile = __DIR__ . '/../../../stubs/multipart.yaml'; - $request = parse_request($message); // convert a text HTTP message to a PSR7 message + $request = Message::parseRequest($message); // convert a text HTTP message to a PSR7 message $serverRequest = new ServerRequest( $request->getMethod(), $request->getUri(), diff --git a/tests/PSR7/Validators/BodyValidatorTest.php b/tests/PSR7/Validators/BodyValidatorTest.php index e70c8f8d..19c7a0eb 100644 --- a/tests/PSR7/Validators/BodyValidatorTest.php +++ b/tests/PSR7/Validators/BodyValidatorTest.php @@ -4,13 +4,12 @@ namespace League\OpenAPIValidation\Tests\PSR7\Validators; +use GuzzleHttp\Psr7\Message; use GuzzleHttp\Psr7\ServerRequest; use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidBody; use League\OpenAPIValidation\PSR7\ValidatorBuilder; use PHPUnit\Framework\TestCase; -use function GuzzleHttp\Psr7\parse_request; - class BodyValidatorTest extends TestCase { /** @@ -140,7 +139,7 @@ public function dataProviderRed(): array */ public function testValidateGreen(string $specFile, string $message): void { - $request = parse_request($message); // convert a text HTTP message to a PSR7 message + $request = Message::parseRequest($message); // convert a text HTTP message to a PSR7 message $serverRequest = new ServerRequest( $request->getMethod(), $request->getUri(), @@ -158,7 +157,7 @@ public function testValidateGreen(string $specFile, string $message): void */ public function testValidateRed(string $specFile, string $message): void { - $request = parse_request($message); // convert a text HTTP message to a PSR7 message + $request = Message::parseRequest($message); // convert a text HTTP message to a PSR7 message $serverRequest = new ServerRequest( $request->getMethod(), $request->getUri(),