-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathIssue166Test.php
More file actions
72 lines (63 loc) · 2.02 KB
/
Copy pathIssue166Test.php
File metadata and controls
72 lines (63 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
namespace League\OpenAPIValidation\Tests\FromCommunity;
use GuzzleHttp\Psr7\ServerRequest;
use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidQueryArgs;
use League\OpenAPIValidation\PSR7\ValidatorBuilder;
use League\OpenAPIValidation\Tests\PSR7\BaseValidatorTest;
use function parse_str;
/**
* @see https://github.com/thephpleague/openapi-psr7-validator/issues/166
*/
final class Issue166Test extends BaseValidatorTest
{
public function testIssue166(): void
{
$yaml = /** @lang yaml */
<<<YAML
openapi: 3.0.0
servers:
- url: 'http://localhost:8000/api'
paths:
/list:
get:
parameters:
- in: query
name: filter
style: deepObject
allowReserved: true
schema:
type: object
properties:
filters:
oneOf:
-
type: object
required:
- max
properties:
max:
type: number
-
type: object
required:
- min
properties:
min:
type: number
YAML;
$validator = (new ValidatorBuilder())->fromYaml($yaml)->getServerRequestValidator();
$queryString = 'filter[filters][min]=1';
$query = null;
parse_str($queryString, $query);
$psrRequest = (new ServerRequest('get', 'http://localhost:8000/api/list'))
->withHeader('Content-Type', 'application/json')
->withQueryParams($query);
try {
$validator->validate($psrRequest);
$this->assertTrue(true);
} catch (InvalidQueryArgs $e) {
self::fail('Should not throw an exception');
}
}
}