Skip to content

Commit a21e9a0

Browse files
committed
Better Validation for Query parameters
Add parameter matchQueryParam to allow match or not.
1 parent 36210fa commit a21e9a0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/AbstractRequester.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function assertBodyContains(string $contains): self
209209
* @throws RequiredArgumentNotFound
210210
* @throws StatusCodeNotMatchedException
211211
*/
212-
public function send(): ResponseInterface
212+
public function send(bool $matchQueryParams = true): ResponseInterface
213213
{
214214
// Process URI based on the OpenAPI schema
215215
$uriSchema = new Uri($this->schema->getServerUrl());
@@ -248,7 +248,7 @@ public function send(): ResponseInterface
248248
}
249249

250250
// Check if the body is the expected before request
251-
$bodyRequestDef = $this->schema->getRequestParameters($this->psr7Request->getUri()->getPath(), $this->psr7Request->getMethod(), $this->psr7Request->getUri()->getQuery());
251+
$bodyRequestDef = $this->schema->getRequestParameters($this->psr7Request->getUri()->getPath(), $this->psr7Request->getMethod(), $matchQueryParams ? $this->psr7Request->getUri()->getQuery() : null);
252252
$bodyRequestDef->match($requestBody);
253253

254254
// Handle Request

src/ApiTestCase.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected function makeRequest(
117117
* @throws RequiredArgumentNotFound
118118
* @throws StatusCodeNotMatchedException
119119
*/
120-
public function assertRequest(AbstractRequester $request): ResponseInterface
120+
public function assertRequest(AbstractRequester $request, bool $matchQueryParams = true): ResponseInterface
121121
{
122122
// Add own schema if nothing is passed.
123123
if (!$request->hasSchema()) {
@@ -126,7 +126,7 @@ public function assertRequest(AbstractRequester $request): ResponseInterface
126126
}
127127

128128
// Request based on the Swagger Request definitios
129-
$body = $request->send();
129+
$body = $request->send($matchQueryParams);
130130

131131
// Note:
132132
// This code is only reached if to send is successful and
@@ -137,10 +137,10 @@ public function assertRequest(AbstractRequester $request): ResponseInterface
137137
return $body;
138138
}
139139

140-
public function assertRequestException(AbstractRequester $request, string $exceptionClass, string $exceptionMessage = null): Throwable
140+
public function assertRequestException(AbstractRequester $request, string $exceptionClass, string $exceptionMessage = null, bool $matchQueryParams = true): Throwable
141141
{
142142
try {
143-
$this->assertRequest($request);
143+
$this->assertRequest($request, $matchQueryParams);
144144
} catch (Throwable $ex) {
145145
$this->assertInstanceOf($exceptionClass, $ex);
146146

0 commit comments

Comments
 (0)