From 9a9fe4df32133b21a70364b28cf83df334d49893 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Magalhaes Date: Wed, 27 Nov 2024 14:30:03 -0600 Subject: [PATCH] Minor Changes --- src/ApiTestCase.php | 2 +- tests/AbstractRequesterTest.php | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/ApiTestCase.php b/src/ApiTestCase.php index 3076578..4d878f6 100644 --- a/src/ApiTestCase.php +++ b/src/ApiTestCase.php @@ -141,7 +141,6 @@ public function assertRequestException(AbstractRequester $request, string $excep { try { $this->assertRequest($request); - $this->fail("Expected exception " . $exceptionClass); } catch (Throwable $ex) { $this->assertInstanceOf($exceptionClass, $ex); @@ -151,6 +150,7 @@ public function assertRequestException(AbstractRequester $request, string $excep return $ex; } + $this->fail("Expected exception '{$exceptionClass}' but no exception was thrown"); } diff --git a/tests/AbstractRequesterTest.php b/tests/AbstractRequesterTest.php index d631838..bb69019 100644 --- a/tests/AbstractRequesterTest.php +++ b/tests/AbstractRequesterTest.php @@ -63,23 +63,11 @@ public function testExpectOK() } /** - * @throws DefinitionNotFoundException - * @throws GenericSwaggerException - * @throws HttpMethodNotFoundException - * @throws InvalidDefinitionException - * @throws InvalidRequestException * @throws MessageException - * @throws NotMatchedException - * @throws PathNotFoundException * @throws RequestException - * @throws RequiredArgumentNotFound - * @throws StatusCodeNotMatchedException */ public function testExpectError() { - $this->expectException(NotMatchedException::class); - $this->expectExceptionMessage("Required property 'name'"); - $expectedResponse = Response::getInstance(200) ->withBody(new MemoryStream(json_encode([ "id" => 1, @@ -91,7 +79,7 @@ public function testExpectError() ->withMethod('GET') ->withPath("/pet/1"); - $this->assertRequest($request); + $this->assertRequestException($request, NotMatchedException::class, "Required property 'name'"); } public function testExpectParamError() @@ -112,6 +100,24 @@ public function testExpectParamError() $this->assertRequestException($request, NotMatchedException::class, "Expected 'petId' to be numeric, but found 'ABC'."); } + public function testExpectParamErrorRequired() + { + $expectedResponse = Response::getInstance(200) + ->withBody(new MemoryStream(json_encode([ + "id" => 1, + "name" => "Spike", + "photoUrls" => [] + ]))); + + // Basic Request + $request = new MockRequester($expectedResponse); + $request + ->withMethod('GET') + ->withPath("/pet/"); + + $this->assertRequestException($request, NotMatchedException::class, "Expected 'petId' to be numeric, but found 'ABC'."); + } + /** * @throws DefinitionNotFoundException * @throws GenericSwaggerException