Skip to content

Commit

Permalink
Minor Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Nov 27, 2024
1 parent 862b47a commit 9a9fe4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -151,6 +150,7 @@ public function assertRequestException(AbstractRequester $request, string $excep

return $ex;
}
$this->fail("Expected exception '{$exceptionClass}' but no exception was thrown");
}


Expand Down
32 changes: 19 additions & 13 deletions tests/AbstractRequesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 9a9fe4d

Please sign in to comment.