From fd9bede92d58a34c955036d6c3f2de45a221c0f3 Mon Sep 17 00:00:00 2001 From: Chris Wolff Date: Tue, 1 Mar 2022 09:20:05 +0100 Subject: [PATCH] Add ResponseStatusCodesWithWildcards Test for Specfinder Test Different Response Adresses and check if the correct Response Schema is Found #158 --- tests/PSR7/SpecFinderTest.php | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/PSR7/SpecFinderTest.php b/tests/PSR7/SpecFinderTest.php index 98e2e362..d9f6c785 100644 --- a/tests/PSR7/SpecFinderTest.php +++ b/tests/PSR7/SpecFinderTest.php @@ -6,6 +6,7 @@ use League\OpenAPIValidation\PSR7\CallbackAddress; use League\OpenAPIValidation\PSR7\OperationAddress; +use League\OpenAPIValidation\PSR7\ResponseAddress; use League\OpenAPIValidation\PSR7\SpecFinder; use League\OpenAPIValidation\PSR7\ValidatorBuilder; use PHPUnit\Framework\TestCase; @@ -122,4 +123,61 @@ public function testHandleParameters(): void $pathItem = $specFinder->findPathSpec(new OperationAddress('/api/1.0/order/123', 'get')); self::assertSame('The order object', $pathItem->get->responses[200]->description); } + + public function testResponseStatusCodesWithWildcards(): void + { + $yaml = <<fromYaml($yaml)->getServerRequestValidator()->getSchema(); + $specFinder = new SpecFinder($schema); + $responseSpec = $specFinder->findResponseSpec( + new ResponseAddress('/products.find', 'get', 404) + ); + self::assertSame('Not Found', $responseSpec->description); + + $responseSpec = $specFinder->findResponseSpec( + new ResponseAddress('/products.find', 'get', 400) + ); + self::assertSame('Client Error', $responseSpec->description); + + $responseSpec = $specFinder->findResponseSpec( + new ResponseAddress('/products.find', 'get', 500) + ); + self::assertSame('Unexpected Error', $responseSpec->description); + } }