-
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.
Respect uploaded file tree instead of flat array (#63)
- Loading branch information
Showing
2 changed files
with
95 additions
and
6 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,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\OpenAPIValidation\Tests\FromCommunity; | ||
|
||
use GuzzleHttp\Psr7\ServerRequest; | ||
use GuzzleHttp\Psr7\UploadedFile; | ||
use League\OpenAPIValidation\PSR7\ValidatorBuilder; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class Issue62Test extends TestCase | ||
{ | ||
/** | ||
* @see https://github.com/thephpleague/openapi-psr7-validator/issues/62 | ||
*/ | ||
public function testIssue62() : void | ||
{ | ||
$yaml = /** @lang yaml */ | ||
<<<YAML | ||
openapi: 3.0.0 | ||
info: | ||
title: Test API | ||
version: '1.0' | ||
servers: | ||
- url: 'http://localhost:8000/api/v1' | ||
paths: | ||
/clam/scan: | ||
put: | ||
responses: | ||
'202': | ||
description: Accepted | ||
requestBody: | ||
content: | ||
multipart/form-data: | ||
schema: | ||
type: object | ||
properties: | ||
upload: | ||
type: array | ||
items: | ||
type: string | ||
format: binary | ||
YAML; | ||
|
||
$validator = (new ValidatorBuilder())->fromYaml($yaml)->getServerRequestValidator(); | ||
|
||
$psrRequest = (new ServerRequest('post', 'http://localhost:8000/api/v1/clam/scan')) | ||
->withUploadedFiles( | ||
ServerRequest::normalizeFiles( | ||
[ | ||
'upload' => [ | ||
new UploadedFile('body1', 5, 0, 'upload_1.txt', 'text/plain'), | ||
new UploadedFile('body2', 5, 0, 'upload_2.txt', 'text/plain'), | ||
], | ||
] | ||
) | ||
) | ||
->withMethod('PUT') | ||
->withHeader('Content-Type', 'multipart/form-data'); | ||
|
||
$validator->validate($psrRequest); | ||
$this->addToAssertionCount(1); | ||
} | ||
} |