-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(typeMismatch): Add test on querystring parameters with array val…
…ues of number (#141) * test(typeMismatch): Add test on querystring parameters with array values of number Co-authored-by: Aurelien Dupuis <[email protected]>
- Loading branch information
1 parent
4a16cd2
commit e4ed24c
Showing
2 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\OpenAPIValidation\Tests\FromCommunity; | ||
|
||
use GuzzleHttp\Psr7\ServerRequest; | ||
use League\OpenAPIValidation\PSR7\ValidatorBuilder; | ||
use League\OpenAPIValidation\Tests\PSR7\BaseValidatorTest; | ||
|
||
use function parse_str; | ||
|
||
/** | ||
* @see https://github.com/thephpleague/openapi-psr7-validator/issues/140 | ||
*/ | ||
final class Issue140Test extends BaseValidatorTest | ||
{ | ||
public function testIssue140(): void | ||
{ | ||
$json = /** @lang json */ | ||
<<<JSON | ||
{ | ||
"openapi": "3.0.0", | ||
"servers": [ | ||
{ | ||
"url": "https://localhost" | ||
} | ||
], | ||
"paths": { | ||
"/api/list": { | ||
"get": { | ||
"summary": "Get a list filtred by ids", | ||
"parameters": [ | ||
{ | ||
"name": "id", | ||
"in": "query", | ||
"description": "Array of ids", | ||
"required": true, | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"type": "number" | ||
} | ||
} | ||
} | ||
], | ||
"responses": {} | ||
} | ||
} | ||
} | ||
} | ||
JSON; | ||
|
||
$validator = (new ValidatorBuilder())->fromJson($json)->getServerRequestValidator(); | ||
|
||
$queryString = 'id[]=1&id[]=2'; | ||
$query = null; | ||
parse_str($queryString, $query); | ||
|
||
$psrRequest = (new ServerRequest('get', 'http://localhost:8000/api/list')) | ||
->withHeader('Content-Type', 'application/json') | ||
->withQueryParams($query); | ||
|
||
$validator->validate($psrRequest); | ||
|
||
$this->addToAssertionCount(1); | ||
} | ||
} |